Ad

Is It Possible To Create And Checkout A New Git Branch From CakeBuild?

- 1 answer

My question is two parts question

1) I need to create and checkout a new git branch through cake build. In git, this would be exactly like we do

git branch Foo
git checkout Foo

The Cake.Git addin gives information of the current branch name but I doubt it have functionality to branch and checkout.

2) The existing GitCheckout method throws exception. There is an existing ReleaseRC branch of this repo, still it throws exception. What am I missing here?

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

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

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

Error

Ad

Answer

No, this is not currently possible through the Cake.Git addin. There is however an issue for adding this functionality to the Cake.Git addin, which you can find here:

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

It would be possible to do this work by calling the git executable directly, using the StartProcess alias, and providing the required arguments.

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

For example:

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

UPDATE: As of version 0.18.0 of the Cake.Git addin it should now be possible to use a new GitCreateBranch alias for doing this.

Ad
source: stackoverflow.com
Ad