简体   繁体   中英

Using NodeGit CloneOptions to clone a branch

I am trying to work out how to pass clone options to the nodegit clone method.

The node git documentation states that the 3rd param to the clone method is the clone options object http://www.nodegit.org/nodegit/#Repo-clone

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

However this object is not included in the standard build of nodegit.

I have added the binding for the clone_options.cc file into the bindings.gyp file and I can get access to the clone options object. However I can not work out how to instantiate it with a valid branch name. The libgit2 api shows that the option is checkout_branch http://libgit2.github.com/libgit2/#HEAD/type/git_clone_options

Anyone have any insight on how to do this? Or on an alternative library that supports cloning of git branches in node?

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

results in

Error: git_clone_options is required.

There is also an open thread on the github issues page for nodegit

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

You can try this...

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM