如何创建使用TFS API的新来源$ C $ C分支? [英] How to create a new source code branch using TFS API?
问题描述
我想创建一个使用API一个新的分支,并同时使用 PendBranch()
和 CreateBranch()
。与 CreateBranch问题()
是立即提交,我希望能够为分支的检查,添加注释,所以我什么,我做了如下所示。
基本上我得到像服务器项目和地方项目的信息被映射,以及从我的Windows应用程序分支的源和目标。
不知怎的,当我看到源代码控制浏览器还在说的未映射的,即使我已经给了一个 workspace.Get()
在创建工作区后 workspace.Map(serverItem,localItem)
任何人都可以揭示出这个光?
公共无效CreateNewBranch(字符串服务器,字符串serverItem,串localItem,串sourceBranch,串targetBranch)
{
INT changeSetNumber = 0;
//获取到Team Foundation服务器和源代码控制的参考。
TFS = GetTFS(服务器);
//创建为当前认证的用户一个新的工作区。
工作区= tfvc.CreateWorkspace(示例工作区,tfvc.AuthenticatedUser);
}
//创建一个映射到项目中。
尝试
{
workspace.Map(serverItem,localItem); //从库中的最新源文件。
//workspace.Get(); //执行挂起分支操作。
workspace.PendBranch(sourceBranch,targetBranch,VersionSpec.Latest);
//获取所有挂起的更改列表。
PendingChange [] = pendingChanges workspace.GetPendingChanges();
如果(pendingChanges.Length大于0)
{
changeSetNumber = workspace.CheckIn(pendingChanges,点评:科创);
的MessageBox.show(已开始变更#+ changeSetNumber);
}
}
赶上(例外五)
{
MessageBox.Show(e.Message);
}
最后
{
//清理工作区。
workspace.Delete();
}
}
在TFS变更集评论实际上是编辑。因此,你可以尝试类似的东西利用在VS2008 / TFS2008 SP1中引入的CreateBranch方法如下:
公共无效CreateBranchWithComment(
字符串的serverUrl,
串SOURCEPATH,
串TARGETPATH,
字符串评论)
{
TeamFoundationServer TFS =新TeamFoundationServer(的serverUrl);
VersionControlServer vcServer =
(VersionControlServer)tfs.GetService(typeof运算(VersionControlServer)); INT changesetId = vcServer.CreateBranch(
SOURCEPATH,
TARGETPATH,
VersionSpec.Latest); 变更变更= vcServer.GetChangeset(changesetId);
changeset.Comment =评论;
changeset.Update();}
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?
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();
}
}
In TFS changeset comments are actually editable. Therefore you could try something like the following that makes use of the CreateBranch method introduced in VS2008/TFS2008 SP1:
public void CreateBranchWithComment(
string serverUrl,
string sourcePath,
string targetPath,
string comment)
{
TeamFoundationServer tfs = new TeamFoundationServer(serverUrl);
VersionControlServer vcServer =
(VersionControlServer)tfs.GetService(typeof(VersionControlServer));
int changesetId = vcServer.CreateBranch(
sourcePath,
targetPath,
VersionSpec.Latest);
Changeset changeset = vcServer.GetChangeset(changesetId);
changeset.Comment = comment;
changeset.Update();
}
这篇关于如何创建使用TFS API的新来源$ C $ C分支?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!