You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
repo.getReferenceCommit() does not work with annotated tags #1370
The method getReferenceCommit() on a Repository works with a tag given in the form refs/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:
Error: the requested type does not match the type in the ODB
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 Tag object to its commit?
@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).
It's not completely clear to me what you are looking for though.
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.
Activity
mojavelinux commentedon Mar 7, 2018
I managed to get this working by following the referenced discussion. To save other people time, here's the code I ended up using.
The important line is this one:
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.
mojavelinux commentedon Mar 7, 2018
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?
rcjsuen commentedon Mar 7, 2018
@mojavelinux The following code should work.
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
Tagobject to its commit?mojavelinux commentedon Mar 7, 2018
@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.
rcjsuen commentedon Mar 7, 2018
@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.
mojavelinux commentedon Mar 7, 2018
Thanks for the pointer!