Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 26 additions & 13 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -1128,30 +1128,22 @@ Repository.prototype.getSubmoduleNames = function(callback) {
};

/**
* This will set the HEAD to point to the local branch and then attempt
* This will set the HEAD to point to the reference and then attempt
* to update the index and working tree to match the content of the
* latest commit on that branch
* latest commit on that reference
*
* @async
* @param {String|Reference} branch the branch to checkout
* @param {Reference} reference the reference to checkout
* @param {Object|CheckoutOptions} opts the options to use for the checkout
*/
Repository.prototype.checkoutBranch = function(branch, opts) {
Repository.prototype.checkoutRef = function(reference, opts) {
var repo = this;
var reference;
opts = opts || {};

opts.checkoutStrategy = opts.checkoutStrategy ||
(NodeGit.Checkout.STRATEGY.SAFE |
NodeGit.Checkout.STRATEGY.RECREATE_MISSING);
return repo.getReference(branch)
.then(function(ref) {
if (!ref.isBranch()) {
return false;
}
reference = ref;
return repo.getBranchCommit(ref.name());
})
return repo.getReferenceCommit(reference.name())
.then(function(commit) {
return commit.getTree();
})
Expand All @@ -1164,6 +1156,27 @@ Repository.prototype.checkoutBranch = function(branch, opts) {
});
};

/**
* This will set the HEAD to point to the local branch and then attempt
* to update the index and working tree to match the content of the
* latest commit on that branch
*
* @async
* @param {String|Reference} branch the branch to checkout
* @param {Object|CheckoutOptions} opts the options to use for the checkout
*/
Repository.prototype.checkoutBranch = function(branch, opts) {
var repo = this;

return repo.getReference(branch)
.then(function(ref) {
if (!ref.isBranch()) {
return false;
}
return repo.checkoutRef(ref, opts);
});
};

var fetchheadForeach = Repository.prototype.fetchheadForeach;
/**
* @async
Expand Down