Merge branches using the Microsoft.TeamFoundationServer.ExtendedClient API does not work as expected
-
I'm having real trouble in getting a merge to work. The goal is to update a branch from its original source to be identical to it again. So I built a method that does create a branch if the target does not exist or merge the source into the target and overwrite all conflicts by the contents of the source. The branching works without any issues. The problem is that the merge is performed, but none of the modifications are actually merged. The target files do not change. If I stop my code before the check in and look at the Source Control Explorer the Pending Change on my files is only "merge". If I do the same merge manually in the Source Control Explorer the pending Change on my files is "merge, edit". So the question would be: Do I have the edit operation on these files myself? The code should actually be straight forward: 1. Check if target already exists, if target does not exist do a branch 2. If target exists do a merge 3. Get merge candidates 4. Merge all merge candidates 5. get conflicts 6. resolve all conflicts by overwriting the target version (take source version) 7. check in all pending changes Here is my code:
/// <summary>
/// Create a branch ore merge it if target already exists
/// </summary>
/// <param name="workspace">Workspace to use for merging</param>
/// <param name="sourcePath">Server item of the source</param>
/// <param name="targetPath">Server item of the target</param>
/// <param name="version">Version of the source that needs to be branched or merged</param>
/// <returns>Returns the change set id of the branch/merge or -1 if source already exists and nothing was merged.</returns>
public static int CreateOrMergeBranch(Workspace workspace, string sourcePath, string targetPath, VersionSpec version)
{
// check if target already exists
if (workspace.VersionControlServer.ServerItemExists(targetPath, ItemType.Folder))
{
// do a merge
var mergeCandidates = workspace.VersionControlServer.GetMergeCandidates(sourcePath, targetPath, RecursionType.Full);
if (mergeCandidates.Any())
{
// get the target
//TODO: only get the files that actually needs to get merged
workspace.Get(new GetRequest(targetPath, RecursionType.Full, VersionSpec.Latest), GetOptions.None);
// perform the merge operation
//TODO: actually use the version provided by the caller as versionTo
var mergeStatus = workspace.Merge(sourcePa