Answered TFS api: get merge sources before checking in

  • Friday, August 19, 2011 12:31 PM
     
     

    Hello,

    after a lot of googling, I decided to register to this forum and ask my question. I can't imagine nobody done this before, but I just can't find any solution.

    For a better understanding, two words about the structure in the TFS. We have for every Team a development branch, which is branched out of main. So the folder structure is

    |- Development

                |- Team1 (branch object)

                |- Team2 (branch object)

    |- MAIN (branch object)

    So the problem is the following: I am writing a custom checkin policy (TFS 2010, VisualStudio 2010) which shall be evaluated as soon as someone wants to merge anything back into main. The policy shall then check if every changeset of the development branch from which the merge is done, has a special work item attached. The problem I'm having now is to get the development branch.

    When the policy is evaluated, I have the information from the pending checkins window, but all I get is the path on main. The MergeSources Property of my changes is unfortunately always an empty list. For files that were not newly created on the development branches, the SourceServerItem is null, too.

    So does anybody know how to get the merge source of a pending merge? Help would be very appreciated!

    Thanking you in advance

All Replies

  • Monday, August 22, 2011 9:24 AM
    Moderator
     
     

    Hi SaTu,

     

    Thanks for your post.

     

    I tried to get the MergeSources property from PendingChange, and as you said, the MergeSources return empty. I did some research and fund that we can’t get the MergeSources property from Pending Change using TFS API, it’s by design in TFS, sorry for any inconvenience. 

     

    For this scenario, I suggest you submit it as a suggestion to Microsoft Connect Feedback portal at: https://connect.microsoft.com/VisualStudio. Microsoft engineers will evaluate them seriously.

     


    John Qiao [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


  • Monday, August 22, 2011 10:32 AM
     
     

    Hi John,

    thanks for your answer. I understand that it is not possible to get the MergeSources property, but isn't there a different approach to getting the information I'm looking for? I assume that the information must be somewhere on the server as it is available after checkin.. Do you know any kind of workaround or anything I could do to get the source path?

    Thanking you in advance

  • Monday, August 22, 2011 10:44 AM
     
     

    Is it something like this you are looking for:

    http://geekswithblogs.net/jakob/archive/2010/10/27/merging-work-items-in-tfs-2010.aspx

    /Jakob


    Microsoft Community Contributor Award 2011
    Blog: http://geekswithblogs.net/jakob
    Twitter: http://twitter.com/jakobehn
  • Monday, August 22, 2011 11:08 AM
     
     

    Hi Jakob,

    I came across your implementations several times during my google search. I actually need something similar to this. I have seen your implementation at http://mergeworkitems.codeplex.com/ but I have seen that you get the MergeSources of a changeset which is already checked in.

    I would need what you write in your blog (the link you provided above):  "The checkin policy uses the TFS Version Control API to locate the merge sources of each pending merge item..."

    So how do I get the merge sources of a pending merge item? Any idea?

    Thanks

  • Monday, August 22, 2011 11:25 AM
     
     Answered Has Code

    If I recall correctly, you need to pass in the value true to the GetPendingChanges method, e.g. the includeDownloadInfo parameter. This caused, among other things, the MergeSources property to be properly initialized:

                   // Get pending changes with mergeSource information
                    Workspace currentWorkspace = this.PendingCheckin.PendingChanges.Workspace;
                    ItemSpec[] items = pendingMerges.Select(m => new ItemSpec(m, RecursionType.None)).ToArray();
     
                    var pendingChanges = currentWorkspace.GetPendingChanges(items, falseInt32.MaxValue, nulltrue);

    This was a bit of a trial and error for me, and the documentation is not clear about this. But this part worked for me, but other problems made me switch solution and do this operation server side instead, which turned out to be a better solution for us.

    Hope that helps
    /Jakob


    Microsoft Community Contributor Award 2011
    Blog: http://geekswithblogs.net/jakob
    Twitter: http://twitter.com/jakobehn
    • Marked As Answer by s.tu Monday, August 22, 2011 12:05 PM
    •  
  • Monday, August 22, 2011 12:05 PM
     
     

    Hi Jakob!

    You're my hero :)

    This is exactly what I needed. I would have never thought about "re-getting" the pending changes, as they were already available at the start of the policy evaluation. Thank you very much!

    Sandra

  • Tuesday, August 21, 2012 6:59 PM
     
     

    Hi, 

    I think it's the solution of all my problems too. But I can't identify   "pendingMerges" variable. Who is it ? Where is it declared ? thank you

  • Wednesday, August 22, 2012 5:42 AM
     
     

    Hi Denny,

    the pendingMerges variable was a variable I created myself. I don't know what you want to do, but I created a custom check-in policy, and the pending changes are coming with the PolicyBase class the custom Policy is derived by:

    public class CustomPolicy: PolicyBase {

    ..

    }

    Maybe it is easier to help if you write what you want to do.

    Best regards