Skip to content

Conversation

rcjsuen
Copy link
Member

@rcjsuen rcjsuen commented Dec 26, 2017

The current code in repository.js assumes that the return value from reference.target() is an oid that points to a commit.

nodegit/lib/repository.js

Lines 1057 to 1069 in b6e1478

Repository.prototype.getReferenceCommit = function(name, callback) {
var repository = this;
return this.getReference(name).then(function(reference) {
return repository.getCommit(reference.target()).then(function(commit) {
if (typeof callback === "function") {
callback(null, commit);
}
return commit;
});
}, callback);
};

However, this is not true for annotated commits as its target oid is actually the tag object itself. To get around this, reference.peel(NodeGit.Object.TYPE.COMMIT) should be used instead so that the reference object will fully unwrap itself to the underlying commit object. This should fix #1370.

@rcjsuen rcjsuen force-pushed the getReferenceCommit branch from ff4062c to 9ff5708 Compare March 7, 2018 08:35
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

repo.getReferenceCommit() does not work with annotated tags
1 participant