api - 如何使用TFS API创建新的源代码分支?

标签 api version-control tfs branch new-operator

我正在尝试使用 API 创建一个新分支,并且使用了 PendBranch()CreateBranch()。 CreateBranch() 的问题是它立即提交,我希望能够在 checkin 分支时添加注释。所以,我所做的如下所示。

基本上,我从 Windows 应用程序中获取所有信息,例如要映射的服务器项目和本地项目以及分支的源和目标。

不知何故,当我看到源代码管理资源管理器时,它仍然显示“未映射”,即使我在创建工作区后给出了:workspace.Get()并且workspace.Map(serverItem,localItem)

有人能解释一下吗?

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();
        }
    }

最佳答案

在 TFS 中,变更集注释实际上是可编辑的。因此,您可以尝试使用 VS2008/TFS2008 SP1 中引入的 CreateBranch 方法,如下所示:

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();

}

关于api - 如何使用TFS API创建新的源代码分支?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1559180/

相关文章:

javascript - 如何在 LinkedIn 应用程序中打开 LinkedIn 共享文章链接

ruby-on-rails - 参数丢失或值为空 : user

c++ - 如何使用 C API 为 MySQL 查询设置超时

windows - Git svn 不使用 svn 凭据

version-control - 如何自动将多个 Monticello 提交从本地存储库复制到 Smalltalkhub.com?

powershell - 获取TFS错误中 check out 文件的列表

c# - TFS 复制工作项链接

Facebook API - 什么是 "curl -F "?

version-control - 将文件复制到新分支并在 P4V 中保留更改列表历史记录

iis - TFS 2013 : HTTP code 503: Service Unavailable