locked
TFS API merge and conflict resolve does not have the same output as "tf resolve /automerge" or "GUI api" RRS feed

  • Question

  • Hi,

    We have recently developed a TFS API in our company to perform merge activities and auto-resolve conflict right after the merge. 

    Somehow, our TFS API does not return the same output as "tf.exe resolve /auto:automerge" command or  "AutoResolve All" from the "Pending Changes - Conflict" window. Our API was developped following the guideline/sample of this link  

    http://teamfoundation.blogspot.ca/2006/11/merging-and-resolving-conflicts-using.html.

    Below are the 2 scenarios that we have discovered:

    1. Merge changes to deleted files in the target branch - Our API does not return any conflict as the option "autoresolve" from "Pending Changes - Conflict" window or "tf.exe resolve /auto:automerge" command.   These 2 interfaces require user interaction to resolve conflict via merge tool whereas our API automatically recreate the files in target branch w/o asking question. A behavior that our users do not desire to see.
    2. Merge changes from files have been modified and then deleted in the source branch returns additional error message that they do not show in TFS GUI API (output window).

                        Ex. Error message have error code TF14121.

    Here is an extraction of our codes:

    TeamFoundation tfs = new TeamFoundation();

                Microsoft.TeamFoundation.VersionControl.Client.Workspace ws = tfs.GetWorkspace(hasloc, destVersion);

                GetStatus mergeStatus = ws.Merge(srcVersionPath, destVersionPath, null, toVersionSpec,

                                          LockLevel.Unchanged, RecursionType.Full, MergeOptions.None);

                   if (mergeStatus.NumConflicts + mergeStatus.NumFailures + mergeStatus.NumUpdated == 0)

                      {

                      Console.WriteLine("Nothing to merge");

                      return;

                      }

                   // Status du merge:

                   Console.WriteLine("Statut: Conflicts:{0} Failed:{1} MAJ:{2} {3}",

                                   mergeStatus.NumConflicts, mergeStatus.NumFailures,

                                   mergeStatus.NumUpdated, System.Environment.NewLine);

                   if (mergeStatus.NumFailures > 0)

                      {

                      Failure[] failures = mergeStatus.GetFailures();

                      foreach (Failure failure in failures)

                         {

                         newInstance.DisplayError(failure.GetFormattedMessage());

                         }

                      }

                   int numConflictNotResolve = 0;

                   bool showConflictWindow = false;

                   Conflict[] objConflicts = ws.QueryConflicts((new string[] { destVersionPath }), true);

                   foreach (Conflict objConflict in objConflicts)

                      {

                      bool isMerge = ws.MergeContent(objConflict, false);

                      // Auto relsove conflit...

                      if (objConflict.ContentMergeSummary.TotalConflicting == 0)

                         {

                         objConflict.Resolution = Resolution.AcceptMerge;

                         ws.ResolveConflict(objConflict);

                         }

                      else

                         {

                         showConflictWindow = true;

                         numConflictNotResolve++;

                         }

                      }

                   Console.WriteLine("Conflicts remained: {0}", numConflictNotResolve);

                   if (showConflictWindow)

                      {

                      //TODO : call tf resolve dans cshell wrapper.

                      Console.WriteLine("Lancer la commande 'tf resolve' pour complété.");

                      }

    We'd appreciate any help to resolve the problem. 

    In addition, we are concerned that our API does not treat all merge & autoresolve conflict scenarios the same way as TFS GUI API or "tf.exe merge & resolve" commands. Is there any way to identify differences between our API and TFS GUI API?

    Many thanks in advance,

    Luong


    • Edited by Hangluong Friday, August 10, 2012 7:40 PM
    Friday, August 10, 2012 6:36 PM

Answers

  • Hi Luong,

    Thanks for your reply.

    In this scenario, I think you can use the Resolution.AcceptYours or Resolution.AcceptTheirs in your code to select keep Target branch version or keep Source branch version, like do that in Pending Change-Conflicts window.   


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 20, 2012 6:50 AM
    Moderator

All replies

  • Hi Luong, 

    Thanks for your post.

    I tried to merge the changes to a deleted branch(be modified) using TFS API, it returned the right conflict number. Could you please provide the detailed reproduce steps about these 2 scenario here, I will follow your steps to reproduce these 2 scenario in my Source Control, and try to perform merge using TFS API again.

    And perform Merge using TFS API, you also can refer to the demo project in this blog: http://blogs.microsoft.co.il/blogs/shair/archive/2009/04/20/tfs-api-part-19-merge.aspx.     

    If you have any further research of this issue, please share your experience here.  


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 13, 2012 9:16 AM
    Moderator
  • Hi John,

    We performed the merge and auto resolve conflict actions on our API. The API was developped following the code sample from the link above. In some merge scenarios (see 2 examples shown above), our API does not produce the same outcome as TFS API.

    We are wondering if our codes are calling the right method (with appropriate options) of "merge" & "resolution"? Furthermore, does the code sample that we followed cover all merge scenarios? Do we need to additionally take care of special merge scenarios in our codes (pls see the code extracted shown above)?

    Thanks,

    Luong

    Monday, August 13, 2012 12:49 PM
  • Hi Luong, 

    Thanks for your reply.

    I think your codes are the right methods, we use the ws.Merge() method to perform the merge scenarios in TFS API.

    Can you provide the detailed steps about that two scenarios(examples shown in your initial post) here? I will use your code sample and follow your steps to reproduce these two scenarios on my machine.  


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us

    Tuesday, August 14, 2012 2:59 AM
    Moderator
  • Hi John,

    Sorry for the late reply.

    Here's the procedure:

    1. Create Branch_B from Branch_A

    2. In the child branch (Branch_B), delete the file Branch_B/src/file1.cpp and check in

    3. In the parent branch (Branch_A), modify the file Branch_A/src/file1.cpp and check in

    4. Merge the change from parent branch (Branch_A) to child branch (Branch_B)

        I,    with our API, the file file1.cpp is automatically re-created in the Branch_B - not expected behaviour

        II,   TFS GUI API returns a conflit and require user to resolve the conflict - desirable behaviour from our users

    Thanks,

    Luong

    Friday, August 17, 2012 12:37 PM
  • Hi Luong,

    Thanks for your reply.

    In this scenario, I think you can use the Resolution.AcceptYours or Resolution.AcceptTheirs in your code to select keep Target branch version or keep Source branch version, like do that in Pending Change-Conflicts window.   


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us

    Monday, August 20, 2012 6:50 AM
    Moderator
  • To use AutoMerge or AutoResolve with TFS API you need MergeOptionsEX.None

    ws.Merge(srcVersionPath, destVersionPath, null, toVersionSpec,LockLevel.Unchanged, RecursionType.Full, MergeOptionsEX.None);

    The assembly is:

    [Microsoft.TeamFoundation.VersionControl.Common.MergeOptionsEx]::None

    It took me all day to figure out :(


    Thursday, November 2, 2017 6:54 PM