Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TFS API - Get merged changesets

Tags:

c#

tfs

tfs-sdk

I have a program that reads the lastest build and gets all the changesets from it. It is then possible to determine if the changset that I have it actually a merge, and where it was from.

Here's what I have:

List<IChangesetSummary> changeSets = InformationNodeConverters.GetAssociatedChangesets(build);
IEnumerable<Changeset> changesetDetails = changeSets.Select(x => versionControlServer.GetChangeset(x.ChangesetId));

// Determine is the first changeset was a merge
changesetDetails.First().IsMerge // How to check is the changeset is part of a merge?

UPDATE:

Following the answers so far I have updated

foreach (var cs in changesetDetails)
{
    foreach (Change change in cs.Changes)
    {
        if ((change.ChangeType & ChangeType.Merge) == 0)
            continue;

        foreach(var m in change.MergeSources)

But MergeSources is always empty.

like image 581
Paul Michaels Avatar asked Mar 25 '15 08:03

Paul Michaels


People also ask

How to Track changeset in TFS?

Click the File menu, point to Source Control, and then click View History. In the History window, right-click the changeset that you want to view, and click Track Changeset.

What are changesets in TFS?

Changesets contain the history of each item in version control. You can view a changeset to see what the exact file changes were, discover the owner's comments, find linked work items, and see if any policy warnings were triggered.


2 Answers

Use the VersionControlServer.GetChangesForChangeset method instead. The last parameter indicates that merge source information should be included.

List<IChangesetSummary> changeSets = InformationNodeConverters.GetAssociatedChangesets(build);
IEnumerable<Change> changes = changeSets.SelectMany(x => versionControlServer.GetChangesForChangeset(x.ChangesetId, false, Int32.MaxValue, null, null, true));

foreach (Change change in changes)
{
    if ((change.ChangeType & ChangeType.Merge) == 0) continue;                  
    foreach (var m in change.MergeSources)
    {
        // ...
    }
}
like image 60
Andy Lamb Avatar answered Oct 08 '22 09:10

Andy Lamb


You need to check whether any of the Changes made inside a Changeset is of the ChangeType Merge.

I don't know if the following works, but you get the idea:

changesetDetails.First().Changes.Any(c => (c.ChangeType & ChangeType.Merge) > 0)
like image 20
Chrono Avatar answered Oct 08 '22 07:10

Chrono