Git clone issue in cake

2019-08-17 08:10发布

问题:

Cloning the source using below link

http://cakebuild.net/api/Cake.Git/GitAliases/2ACDDC0F

GitClone("https://github.com/cake-build/cake.git", 
    "c:/temp/cake", 
    "username", 
    "password",
    new GitCloneSettings{ BranchName = "development" });

It works for cloning the branch source.

When i use the tag name(tags/12.4.2.1) instead of branchName facing the below issue

reference 'refs/remotes/origin/tags/12.4.2.1' not found

Note: tags/12.4.2.1 is exist

回答1:

As a starting point, for the moment found only workaround, to execute git clone specific tag commands through cmd StartProcess

    Task("Default")
        .Does(() =>
        {
            GitClone("https://github.com/cake-build/cake.git", 
                "d:/temp/cake", 
                "userName", 
                "password",
                new GitCloneSettings{ BranchName = "main" });

            Cmd("cd /D D:\\temp\\cake",
                " & git checkout v0.8.0",
                " & git branch -D main",
                " & git checkout -b main");
        });

private void Cmd(params object[] parameters)
{
    if (parameters.Any())
    {
        var args =  new ProcessArgumentBuilder()
            .Append(@"/c");

        foreach (var param in parameters)
            args.Append($"{param}");

        StartProcess("cmd", new ProcessSettings { Arguments = args });
    }
}