diff --git a/lib/repository.js b/lib/repository.js index 50a165bf5..aea3440f1 100644 --- a/lib/repository.js +++ b/lib/repository.js @@ -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(); }) @@ -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