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

发布于 2024-08-07 02:07:35 字数 1740 浏览 6 评论 0原文

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

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

不知何故,当我看到源代码管理资源管理器时,它仍然显示“未映射”,即使我在创建工作区和工作区后给出了:workspace.Get() .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();
        }
    }

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

浸婚纱 2024-08-14 02:07:35

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

}

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

}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文