是否可以从 CakeBuild 创建并签出新的 git 分支?

Is it possible to create and checkout a new git branch from CakeBuild?

我的问题是两部分问题

1) 我需要通过 cake build 创建并签出一个新的 git 分支。在 git 中,这与我们所做的完全一样

git branch Foo
git checkout Foo

Cake.Git插件提供了当前分支名称的信息,但我怀疑它是否具有分支和结帐功能。

2) 现有的 GitCheckout 方法抛出异常。这个 repo 有一个现有的 ReleaseRC 分支,它仍然抛出异常。我在这里错过了什么?

Task("Checkout")
    .Does(() =>
{
    var repositoryPath = "../../.foo";

    Information(GitBranchCurrent(repositoryPath).FriendlyName); //Prints 'master'

    GitCheckout(repositoryPath, "ReleaseRC", new FilePath[] {}); //Throws error.
});

不,目前无法通过 Cake.Git 插件实现。但是,将此功能添加到 Cake.Git 插件会出现问题,您可以在此处找到该插件:

https://github.com/cake-contrib/Cake_Git/issues/52

可以通过直接调用 git 可执行文件、使用 StartProcess 别名并提供所需参数来完成这项工作。

https://cakebuild.net/api/Cake.Common/ProcessAliases/81E648CC

例如:

var exitCodeWithArgument = StartProcess("git", new ProcessSettings{ Arguments = "branch foo" });

更新:从 Cake.Git 插件的 0.18.0 版开始,现在应该可以使用新的 GitCreateBranch 别名来执行此操作。