2012-07-02 28 views
2

我有一些功能在git中工作,我試圖移植到NGit。我的git的腳本是這樣的:NGit rebase創建新的提交

git add . 
git commit -a -m "Auto Commit" 
git fetch 
git rebase 
git push 

(我離開了衝突處理的細節,他們不是與此有關)。

移植這NGit,我結束了以下內容:

// Open a connection to the repository 
Git _git = Git.Open(MyRepoPath); 

// Add all new files to the commit. 
_git.Add().AddFilepattern(".").Call(); 

// execute the commit, but don't push yet. 
_git.Commit().SetMessage(CommitMsg).SetAll(true).Call(); 

// fetch all remote files 
_git.Fetch().Call(); 

// rebase 
_git.Rebase().SetUpstream("FETCH_HEAD").Call(); 

// push all changes 
_git.Push().Call(); 

看起來差不多相同......我看到的唯一區別是在我的git服務器上,每當NGit程序運行時,都會有一個新的提交到存儲庫。當我只是在同一臺機器上通過msysgit運行腳本時,這似乎不是這種情況。 (即,如果沒有文件被改變,則服務器上沒有生成任何文件。)

有沒有我在這裏做錯了?任何聰明的想法如何推動只有當有任何不同的地方到偏遠地區之後的遙控器?

謝謝!

回答

0

回答我自己的問題......希望這可以幫助別人。我實現了一個「isDirty」功能(因爲NGit似乎並沒有從JGit庫實現IsClean)如下:

private bool IsDirty(Status status) 
{ 
    return status.GetAdded().Count + status.GetChanged().Count + status.GetConflicting().Count + 
      status.GetMissing().Count + status.GetModified().Count + status.GetRemoved().Count + 
      status.GetUntracked().Count > 0; 
} 

然後我做加法前檢查該/承諾:

// Check if anything needs a'doin' 
if(IsDirty(_git.Status().Call())) 
{ 
    // Add all new files to the commit. 
    _git.Add().AddFilepattern(".").Call(); 

    // execute the commit, but don't push yet. 
    _git.Commit().SetMessage(CommitMsg).SetAll(true).Call(); 
    } 

現在它和上面的腳本一樣。涼!