9

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

1
  • You can also try change property on your code: checkout_branch to checkoutBranch Commented Feb 29, 2016 at 15:00

1 Answer 1

4

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);
        });
Sign up to request clarification or add additional context in comments.

2 Comments

getting error new Git.cloneOptions(); is not a constructor @Leandro William
cant we do using simple-git package?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.