使用 NodeGit 的 CloneOptions 克隆一个分支

9
我正在努力找出如何将克隆选项传递给nodegit克隆方法。
Node Git文档指出,clone方法的第三个参数是克隆选项对象。 http://www.nodegit.org/nodegit/#Repo-clone
git.Repo.clone(URL, path, CloneOptions, callback);

然而,这个对象并没有包含在nodegit的标准构建中。
我已经将clone_options.cc文件的绑定添加到bindings.gyp文件中,并可以访问克隆选项对象。然而,我无法找出如何使用有效的分支名称来实例化它。 libgit2 api显示该选项为checkout_branch: http://libgit2.github.com/libgit2/#HEAD/type/git_clone_options 有人知道如何做吗?或者有其他支持在node中克隆git分支的库吗?
var CloneOptions = nodegit.CloneOptions;
var options = new CloneOptions({checkout_branch: branchName});
git.Repo.clone(url, temp, options, function (err, repo) {...});

导致

Error: git_clone_options is required.

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

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


你也可以尝试在代码中更改属性:将checkout_branch改为checkoutBranch - Leandro William
1个回答

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);
        });

得到错误 new Git.cloneOptions(); 不是一个构造函数 @Leandro William - karan arora
我们不能使用 simple-git 包吗? - karan arora

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接