Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get changeset comments with the merge candidates from a TFS command line command?

Tags:

tfs

I would like produce a list of merge candidates between two branches that includes the changeset comments in a format that I can copy paste in an email.

I know I can do this tf command:

tf merge /candidate $/Branch1 $/Branch2

Which returns something this:

Changeset Author                           Date
--------- -------------------------------- ----------
   22282  developer1                       08/09/2012
   22354  developer2                       08/14/2012
   22361  developer2                       08/14/2012
   22365  developer2                       08/14/2012
   22381  developer3                       08/15/2012

However, I'd like to get the comments as well. The Merge Wizard does something similar when doing a "Selected changesets" merge. Here is an example:

enter image description here

I was thinking that I might be able to combine tf merge /candidate in some way with this command:

tf changeset /noprompt 12345

Which outputs something like this:

Changeset: 12345
User: developer1
Date: Thursday, August 09, 2012 5:20:01 PM

Comment:
  Completed various things

Items:
  merge, edit $/Branch1/BreakFreely.asmx.vb
  merge, edit $/Branch1/FreelyBroken.vb

Work Items:
  ID    Type                State Assigned To  Title
  ----- ------------------- ----- ------------ -----------------------------------------------------------------------------
  21406 Sprint Backlog Task Done  JoDeveloper1 Fix various things

Check-in Notes:
  Code Reviewer:
    Complete Lyblind

In short, my desired outcome is something like this:

Changeset Author                           Date       Comment
--------- -------------------------------- ---------- --------------------------
   22282  developer1                       08/09/2012 Fixed random stuff
   22354  developer2                       08/14/2012 Fixed specific stuff

What do you think?

like image 547
Jon Avatar asked Aug 15 '12 18:08

Jon


1 Answers

In case you 're willing to utilize the TFS-SDK and write your own console app, this should be quite straightforward.
The following could serve as a jump-start:

using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;

namespace MergeCandidates
{
    class Program
    {
        static void Main()
        {
            TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSURI"));

            var versionControl = teamProjectCollection.GetService<VersionControlServer>();
            var mergeCandidates =
                versionControl.GetMergeCandidates(@"$/FromPath",
                                                  @"$/ToPath", RecursionType.Full);
            foreach (var mergeCandidate in mergeCandidates)
            {  
                Console.WriteLine(string.Format("{0} {1} {2} {3}",
                                                mergeCandidate.Changeset.ChangesetId,
                                                mergeCandidate.Changeset.Owner, 
                                                mergeCandidate.Changeset.CreationDate,
                                                mergeCandidate.Changeset.Comment));
            }
        }
    }
}
like image 193
pantelif Avatar answered Oct 09 '22 09:10

pantelif