As part of a bigger implementation, I'm trying to implement a merge operation of my source control branches/folders using TFS-SDK. I'm working against a TFS2010 installation.
What I have is this:
using System;
using Microsoft.TeamFoundation.Client;
using Microsoft.TeamFoundation.VersionControl.Client;
using Microsoft.TeamFoundation.VersionControl.Common;
namespace MergeBranchesFolders
{
class Program
{
static void Main()
{
TfsTeamProjectCollection teamProjectCollection = TfsTeamProjectCollectionFactory.GetTeamProjectCollection(new Uri("http://TFSSERVER/Collection"));
var versionControl = teamProjectCollection.GetService<VersionControlServer>();
const string fromPath = "$/TeamProject/SourceDir";
const string toPath = "$/TeamProject/TargetDir";
Workspace myWorkspace = versionControl.GetWorkspace("WorkspaceName", "WorkspaceOwner");
GetStatus getStatus = myWorkspace.Merge(fromPath, toPath, VersionSpec.Latest, VersionSpec.Latest,
LockLevel.None, RecursionType.Full, MergeOptionsEx.None);
}
}
}
I'm convinced that I get proper access to myWorkspace
, yet the getStatus
looks like this:
That pretty much says that nothing has happened.
Yet if I try to merge in the IDE, I get several merge candidates.
The same merge candidates are also visible if I do a:
var mergeCandidates = versionControl.GetMergeCandidates(fromPath, toPath,RecursionType.Full).ToList();
I failed with both fromPath
/toPath
being branches and folders - even with single file.
The only resource out there I could find was this one, which didn't help...
Shai Raiten's blog-post to the rescue!
This failed:
GetStatus getStatus = myWorkspace.Merge(fromPath, toPath, VersionSpec.Latest, VersionSpec.Latest,
LockLevel.None, RecursionType.Full, MergeOptionsEx.None);
This succeeded:
GetStatus getStatus = myWorkspace.Merge(fromPath, toPath, null, null, LockLevel.None, RecursionType.Full, MergeOptionsEx.None);
While the link to Shai Raiten's blog proved to be helpful, the reason for the change was not made very clear in the answer above, nor was it made very clear in Shai's blog (or in Microsoft's documentation for that matter). The key here is in the meaning of fromVersion and toVersion. It seems like this question's author made the same mistake I did, in misunderstanding the meaning of these parameters. In my case, I understood the "from" and "to" to be references to the source (start point) and target (end point) of the merge, respectively. Though I did not understand why one would have to specify the "to" version in this case, since in order to actually do a meaningful merge, the version of the target always has to be the Tip. So, reading the parameter description as the "starting" and "ending" versions did not strike me as being at odds with this interpretation.
What I finally came to understand is that in this case the "from" and "to" are both referring to the source of the merge, where "from" refers to the starting point for a range of changesets, and "to" refers to the ending point for a range of changesets. If you omit "fromVersion" parameter then you are saying that you want to include all changesets all the way back to the beginning (or the last recorded merge), otherwise you are saying that you want to only include changesets going as far back as the specified version. If you omit the "toVersion" then you are saying that you want to include all changesets up to the Tip version, otherwise you are saying that you want to include changesets only up to the specified version.
So in the original code with both the fromVersion and toVersion parameters specified as VersionSpec.Latest, you are saying that you want to merge all changesets occurring between the Latest version and the Latest version, which by definition contains no changes. In the modified code, however, with null specified for both parameters you are including all available changesets with no constraints.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With