Hi I am trying to create a new branch using the API, and have used both PendBranch() and CreateBranch(). The problem with CreateBranch() is it commits immediately and I want to be able to add comments as the branch is checked in. So, I what I did is shown below.
Basically I get all the information like server item and local item to be mapped as well as source and target of the branch from my windows application. Somehow, when I see Source Control Explorer it still says "Not mapped" even though I have given a : workspace.Get() after creating the workspace and workspace.Map(serverItem,localItem)
Can anyone shed light on this?
Thanks Tara.
public void CreateNewBranch(string server,string serverItem,string localItem,string sourceBranch, string targetBranch)
{
int changeSetNumber = 0;
// Get a reference to Team Foundation Server and Source Control.
tfs = GetTFS(server);
// Create a new workspace for the currently authenticated user.
workspace = tfvc.CreateWorkspace("Example Workspace", tfvc.AuthenticatedUser);
}
// Create a mapping to the project.
try
{
workspace.Map(serverItem, localItem);
// Get the latest source files from the repository.
//workspace.Get();
// Perform a pending Branch operation.
workspace.PendBranch(sourceBranch, targetBranch, VersionSpec.Latest);
// Get a list of all the Pending Changes.
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
{
// Cleanup the workspace.
workspace.Delete();
}
}