I use tf.exe in my C# code to create new branches in TFS. This is what I do:
public static bool TFBranch(string projectPath, string originName, string branchName)
{
string branchedProject = projectPath + "\\" + branchName;
string projectToBranch = projectPath + "\\" + originName;
string path = Environment.ExpandEnvironmentVariables(@"branch " + projectToBranch + " " + branchedProject);
path = path.Replace("\\", "/");
return ExecuteProcess(path);
}
private static bool ExecuteProcess(string path)
{
MyProcess proc = new MyProcess();
var currentDirectory = WorkspaceHandler.GetLocalWorkspace();
var command = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\tf.exe";
Directory.SetCurrentDirectory(currentDirectory);
proc.FileName = command;
proc.Arguments = path;
try
{
proc.Execute();
}
catch (Exception e)
{
_Logger.Error("Could not execute TF.exe. Exception: " + e.ToString());
return false;
}
return true;
}
Mostly everything works as I except it. I branch from an directory that already contains a branch, so the new branch contains also a branch. But sometimes tf.exe creates a folder, not a branch. Is this a bug from tf.exe, or am I doing anything wrong?
Example:
This is how an branch command can look like:
-- EDIT --
Here is how I do it manually:
- I use the menu to branch Templates/BranchSource/Folder/Main:
- In the dialog I define the "Target Branch Name":
- The result is what I expected to get:
This is the same result that I get when I do it with my code. The only difference is that the code creates a folder sometimes.