Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change how getReferenceCommit() retrieves commits #1420

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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