I am trying to create a new branch using the API and have used both PendBranch(), and CreateBranch(). The problem with CreateBranch()is immediate commit, and I want to be able to add comments as the branch is checked. So, I did what I did, shown below.
Basically, I get all the information, such as the server element and the local element that will be displayed, as well as the source and target of the branch from my Windows application.
Somehow, when I see the Source Control Explorer, it still says “Not mapped”, although I created a: workspace.Get()after creating the workspace andworkspace.Map(serverItem,localItem)
Can anyone shed some light on this?
public void CreateNewBranch(string server,string serverItem,string localItem,string sourceBranch, string targetBranch)
{
int changeSetNumber = 0;
tfs = GetTFS(server);
workspace = tfvc.CreateWorkspace("Example Workspace", tfvc.AuthenticatedUser);
}
try
{
workspace.Map(serverItem, localItem);
workspace.PendBranch(sourceBranch, targetBranch, VersionSpec.Latest);
PendingChange[] pendingChanges = workspace.GetPendingChanges();
if (pendingChanges.Length > 0)
{
changeSetNumber = workspace.CheckIn(pendingChanges, "Comment:Branch Created");
MessageBox.Show("Checked in changeset # " + changeSetNumber);
}
}
catch (Exception e)
{
MessageBox.Show(e.Message);
}
finally
{
workspace.Delete();
}
}