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
git clone -b <branchname> --single-branch <remote-repo-url> Here -b is just an alias for --branch This performs the same action as option one, except that the --single-branch option was introduced in Git version 1.7.10 and later. It allows you to only fetch files from the specified branch without fetching other branches.
git clone -b <branchname> <remote-repo-url>. Here -b is just an alias for --branch. With this, you fetch all the branches in the repository, checkout to the one you specified, and the specific branch becomes the configured local branch for git push and git pull . But you still fetched all files from each branch.
While you can clone repositories with the git clone command, keep in mind that this clones the branch and the remote HEAD. This is usually master by default and includes all other branches in the repository. So when you clone a repository, you clone the master and all other branches.
Now let's clone a specific branch from our demo repository. There are two ways to clone a specific branch. You can either: Clone the repository, fetch all branches, and checkout to a specific branch immediately. Clone the repository and fetch only a single branch.
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);
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With