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
repo.getReferenceCommit() does not work with annotated tags #1370
Comments
I managed to get this working by following the referenced discussion. To save other people time, here's the code I ended up using. const git = require('nodegit')
;(async () => {
const repo = await git.Repository.open('.')
const refs = await repo.getReferences(git.Reference.TYPE.OID)
const tagRefs = refs.filter((ref) => ref.isTag())
const tagRef = tagRefs[0]
const targetRef = await tagRef.peel(git.Object.TYPE.COMMIT)
const commit = await repo.getCommit(targetRef)
})() The important line is this one: const targetRef = await tagRef.peel(git.Object.TYPE.COMMIT) Unlike with a branch reference, you have to peel a tag reference back to the commit to which it points. I found this is necessary regardless of whether the tag is annotated or lightweight. |
This really feels like a dirty part of the API. Can we agree on an API that allows a program to navigate from a tag to a commit in a more elegant way? |
@mojavelinux The following code should work. const repository = await git.Repository.open('.')
const reference = await repository.getReference("refs/tags/tagName");
const commit = await reference.peel(NodeGit.Object.TYPE.COMMIT): It's not completely clear to me what you are looking for though. You want a way to go from the name of a tag to its commit or from an actual |
@rcjsuen That's precisely what the code I showed is doing. We're just getting the references a different way. (My code is discovering the references since I don't know the names up front).
My use case is simple. I want to read the files in a tag by walking the tree. For that, I need to resolve the tree. The tree is accessible from a commit. So the first thing I need to do is find the commit. I'm using this in a content system that reads files from the branches and/or tags of a bare git repository. |
@mojavelinux Never mind, I think I misunderstood what you originally were trying to say. Sorry about that. There is a related discussion about these APIs at #403. |
Thanks for the pointer! |
The method
getReferenceCommit()
on aRepository
works with a tag given in the formrefs/tags/v0.1.5
only when the tag is a lightweight tag. If it is an annotated tag, calling this method results in an error:See also the discussion at https://gitter.im/nodegit/nodegit?at=59b5026e66c1c7c477342023
The text was updated successfully, but these errors were encountered: