使用NodeGit CloneOptions克隆分支

Ant*_*ick 8 git node.js libgit2

我试图找出如何将克隆选项传递给nodegit克隆方法.

节点git文档声明克隆方法的第3个参数是克隆选项对象 http://www.nodegit.org/nodegit/#Repo-clone

git.Repo.clone(URL, path, CloneOptions, callback);
Run Code Online (Sandbox Code Playgroud)

但是,此对象不包含在nodegit的标准版本中.

我已将clone_options.cc文件的绑定添加到bindings.gyp文件中,我可以访问克隆选项对象.但是,我无法弄清楚如何使用有效的分支名称实例化它.libgit2 api显示该选项是checkout_branch http://libgit2.github.com/libgit2/#HEAD/type/git_clone_options

任何人都有任何关于如何做到这一点的见解?或者在支持克隆节点中的git分支的替代库中?

var CloneOptions = nodegit.CloneOptions;
var options = new CloneOptions({checkout_branch: branchName});
git.Repo.clone(url, temp, options, function (err, repo) {...});
Run Code Online (Sandbox Code Playgroud)

结果是

Error: git_clone_options is required.
Run Code Online (Sandbox Code Playgroud)

nodegit的github问题页面上还有一个开放的线程

https://github.com/nodegit/nodegit/issues/127

Lea*_*iam 5

你可以尝试这个......

    var Git = require('nodegit');
    var clone = Git.Clone.clone;
    var branch = 'development';
    var cloneOptions = new Git.CloneOptions();    

    cloneOptions.checkoutBranch = branch;  
    clone(url, directory, cloneOptions)
        .then(function(repository){
            console.log(repository);
        });
Run Code Online (Sandbox Code Playgroud)