2014-02-27 137 views
1

我正在努力解決合併衝突與TFS API,我很掙扎。我的問題是:解決TFS API中的合併衝突

  1. 從主幹合併 - 合併過程>分支
  2. 發生衝突(一個文件的同一行中的兩個編輯)
  3. 在這一點上,我只是想提供自己的文本合併的文件應該是什麼樣子,然後將其標記爲已解決。

我無法解決如何做到這一點。見下面的代碼:

// merge was performed and there are conflicts to resolve 
Conflict[] conflicts = ws.QueryConflicts(new string[] {"$/ProjectName/solution/"}, true); 
Console.WriteLine(" - Conflicts: {0}", conflicts.Count()); 

if (conflicts.Any()) 
{ 
    Console.WriteLine(" - Resolving conflicts"); 

    // There are conflicts to deal with 
    foreach (Conflict conflict in conflicts) 
    { 
     // Attempt to perform merge internally 
     ws.MergeContent(conflict, false); 

     if (conflict.ContentMergeSummary.TotalConflicting > 0) 
     { 
      // Conflict was not resolved 
      // Manually resolve 
      // PROBLEM IS HERE <-------------- 
      var allLines = File.ReadAllLines(conflict.TargetLocalItem).ToList(); 
      allLines.Add("This is the MANUAL merge result"); 
      File.WriteAllLines(conflict.TargetLocalItem, allLines.ToArray()); 
     } 

     //conflict was resolved 
     conflict.Resolution = Resolution.AcceptMerge; 
     ws.ResolveConflict(conflict); 
    } 
} 

Checkin(ws, "Merge comment"); 
Console.WriteLine("Done"); 

正如你可以看到我試圖手動編輯目標文件,但這是行不通的。我似乎無法確定我應該在對象上編輯哪個文件來手動執行合併。

一提意見要我詳細說明與上面的代碼的問題:

  1. 在評論點「問題是在這裏」,目標文件仍然上有一個只讀標誌,所以我無法編輯文件。
  2. 如果我用一些代碼刪除readonly標誌並繼續執行代碼,則生成的文件不包含我的新行,但包含所有註釋中的diff樣式文本。如果它不包含,我可以詳細說明合理。
  3. 如果我在TargetLocalItem上進行了編輯,則此操作無效。沒有編輯被掛起。
  4. 這告訴我編輯本地工作區中的目標文件不是正確的操作。

本質上我試圖模仿什麼是外部工具,但我的程序將是外部工具並提供合併的文本。

回答

0

試試這個

string tmpOutFile = Path.GetTempFileName();  
conflict.MergedFileName = tmpOutFile;         
// do stuff with tmpOutFile 
conflict.Resolution = Resolution.AcceptMerge; 
ws.ResolveConflict(conflict);