使用NodeGit CloneOptions克隆分支

我正在尝试解决如何将克隆选项传递给nodegit克隆方法。

节点git文档指出,clone方法的第三个参数是clone选项对象http://www.nodegit.org/nodegit/#Repo-clone

git.Repo.clone(URL, path, CloneOptions, callback); 

但是这个对象不包含在nodegit的标准构build中。

我已经将clone_options.cc文件的绑定添加到了bindings.gyp文件中,并且可以访问clone选项对象。 不过,我不能解决如何使用有效的分支名称来实例化它。 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) {...}); 

结果是

 Error: git_clone_options is required. 

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

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

你可以试试这个…

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