TFS API - Get merged changesets
Asked Answered
T

4

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.

Thereby answered 25/3, 2015 at 8:30 Comment(0)
C
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)
    {
        // ...
    }
}
Christalchristalle answered 20/4, 2015 at 11:53 Comment(1)
For me some of the merged CS are not included with this method, do you know what can be the reason.Officiary
B
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)
Berni answered 26/3, 2015 at 7:35 Comment(1)
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.Thereby
L
0

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

Llano answered 26/3, 2015 at 7:28 Comment(1)
I've updated my question - I believe I have the right flag from the other answer, but the MergeSources aren't populated.Thereby
C
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 ]

Christalchristalle answered 14/4, 2015 at 11:27 Comment(2)
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 nullThereby
My mistake, see me later answer instead.Christalchristalle

© 2022 - 2024 — McMap. All rights reserved.