Skip to content
Open
Show file tree
Hide file tree
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
Change how getReferenceCommit() retrieves commits
If a tag is annotated, its target() will return a tag object instead
of the tag's underlying commit. This causes Repository's
getReferenceCommit() to not work as it will try to find a commit
based on the tag's oid. By replacing target() with peel(), the code
can now find the actual underlying commit regardless of whether a tag
is annotated or not.

Signed-off-by: Remy Suen <remy.suen@gmail.com>
  • Loading branch information
rcjsuen committed Mar 19, 2018
commit 749844bac0b1ad44176977d06156ae1f6dfe7727
4 changes: 1 addition & 3 deletions lib/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -1067,10 +1067,8 @@ Repository.prototype.getReference = function(name, callback) {
* @return {Commit}
*/
Repository.prototype.getReferenceCommit = function(name, callback) {
var repository = this;

return this.getReference(name).then(function(reference) {
return repository.getCommit(reference.target()).then(function(commit) {
return reference.peel(NodeGit.Object.TYPE.COMMIT).then(function(commit) {
if (typeof callback === "function") {
callback(null, commit);
}
Expand Down
36 changes: 36 additions & 0 deletions test/tests/repository.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,4 +327,40 @@ describe("Repository", function() {
assert.equal(numMergeHeads, 1);
});
});

it("can get reference commit that points at lightweight tag", function() {
var repository = this.repository;
var oid = null;
return repository.getHeadCommit()
.then(function(commit) {
oid = commit.id().toString();
return repository.createLightweightTag(
oid, "getReferenceCommitLightweight");
})
.then(function() {
return repository.getReferenceCommit(
"refs/tags/getReferenceCommitLightweight");
})
.then(function(commit) {
assert.equal(commit.id().toString(), oid);
});
});

it("can get reference commit that points at annotated tag", function() {
var repository = this.repository;
var oid = null;
return repository.getHeadCommit()
.then(function(commit) {
oid = commit.id().toString();
return repository.createTag(
oid, "getReferenceCommitAnnotated", "");
})
.then(function() {
return repository.getReferenceCommit(
"refs/tags/getReferenceCommitAnnotated");
})
.then(function(commit) {
assert.equal(commit.id().toString(), oid);
});
});
});