如何使用Cake执行git clone操作

Gar*_*ark 5 c# git cakebuild

是否可以使用Cake脚本克隆git存储库?如果是这样,怎么办呢?

Gar*_*ark 5

可以使用Cake.Git Addin执行大量的git操作.通常,您可以在此处找到有关如何使用此插件提供的别名的示例,但是,这些示例尚不存在.

在此期间,下面显示了如何使用四个GitClone别名中的每一个的示例.

注意:出于本答案的目的,我们将使用GitHub上的Cake Git存储库

GitClone(字符串,目录路径)

#addin nuget:?package=Cake.Git

Task("Git-Clone")
.Does(() =>
{
    GitClone("https://github.com/cake-build/cake.git", "c:/temp/cake");
});

RunTarget("Git-Clone");
Run Code Online (Sandbox Code Playgroud)

GitClone(string,DirectoryPath,GitCloneSettings)

#addin nuget:?package=Cake.Git

Task("Git-Clone")
.Does(() =>
{
    GitClone("https://github.com/cake-build/cake.git", "c:/temp/cake", 
        new GitCloneSettings{ BranchName = "main" });
});

RunTarget("Git-Clone");
Run Code Online (Sandbox Code Playgroud)

GitClone(字符串,DirectoryPath,字符串,字符串)

注意:此别名似乎不会创建输出目录.因此,EnsureDirectoryExists别名用于确保它存在.

#addin nuget:?package=Cake.Git

Task("Git-Clone")
.Does(() =>
{
    EnsureDirectoryExists("c:/temp/cake");
    GitClone("https://github.com/cake-build/cake.git", 
        "c:/temp/cake", 
        "username", 
        "password");
});

RunTarget("Git-Clone");
Run Code Online (Sandbox Code Playgroud)

GitClone(字符串,DirectoryPath,字符串,字符串,GitCloneSettings)

注意:此别名似乎不会创建输出目录.因此,EnsureDirectoryExists别名用于确保它存在.

#addin nuget:?package=Cake.Git

Task("Git-Clone")
.Does(() =>
{
    EnsureDirectoryExists("c:/temp/cake");
    GitClone("https://github.com/cake-build/cake.git", 
        "c:/temp/cake", 
        "username", 
        "password", 
        new GitCloneSettings{ BranchName = "main" });
});

RunTarget("Git-Clone");
Run Code Online (Sandbox Code Playgroud)