I want to get a list of all tags of a repository together with the tagger and the commit-IDs with JGit.
First I tried the Git.tagList().call()
command and parse the tags:
objectIdOfTag = oneResultOfTheTagList.getObjectId();
// or should I call getPeeledObjectId() here?
RevWalk walk = new RevWalk(repository);
RevTag tag = walk.parseTag(objectIdOfTag);
This works for my repository, but I am unsure if this is the correct way: Is it correct to call Ref.getObjectId()
or should I call Ref.getPeeledObjectId()
? (What is a "peeled ObjectId"?)
Is there a difference between lightweight and annotated tags when retrieving the tag list with JGit?
getObjectId
is correct here. In the case of an annotated tag, you want to get the ID of the annotated tag object, not the ID of the commit the tag finally points to. See also the Javadoc of Ref.
To parse the tag, you will have to handle both the lightweight and annotated cases:
RevObject object = walk.parseAny(objectIdOfTag);
if (object instanceof RevTag) {
// annotated
} else if (object instanceof RevCommit) {
// lightweight
} else {
// invalid
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With