2014-02-27 141 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);