5

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.

riQQ
  • 9,878
  • 7
  • 49
  • 66
Paul Michaels
  • 16,185
  • 43
  • 146
  • 269

4 Answers4

8

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)
    {
        // ...
    }
}
Andy Lamb
  • 2,151
  • 20
  • 22
2

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)
Gyum Fox
  • 3,287
  • 2
  • 41
  • 71
Chrono
  • 1,433
  • 1
  • 16
  • 33
  • I did come across looking at the type of the change. However, when I then try and drill into MergeSource it's always empty. I've updated my question. – Paul Michaels Mar 26 '15 at 08:20
0

You would need to interrogate the files am see if the operation was "merge".

  • 1
    I've updated my question - I believe I have the right flag from the other answer, but the MergeSources aren't populated. – Paul Michaels Mar 26 '15 at 08:22
0

Use the overload of VersionControlServer.GetChangeset that accepts the includeDownloadInfo bool parameter. Setting this parameter to true will include the MergeSources in the returned changesets.

IEnumerable<Changeset> changesetDetails = changeSets.Select(x => versionControlServer.GetChangeset(x.ChangesetId, true, true));

[ https://msdn.microsoft.com/en-us/library/bb138628.aspx ]

Andy Lamb
  • 2,151
  • 20
  • 22
  • This doesn't appear to make any difference. The link that you included that the `includeDownloadInfo` is for getting information about the physical files; but regardless, MergeSources are still null – Paul Michaels Apr 14 '15 at 16:58
  • My mistake, see me later answer instead. – Andy Lamb Apr 20 '15 at 11:54