John O
John O

Reputation: 5423

How do you do the equivalent of a "git show tagname" with JGit?

I can't find anything in org.eclipse.jgit.api that looks even remotely plausible. I was under the impression that "git show" is a porcelain command, and I see plenty of other classes for much more obscure commands.

Is this possible?

Upvotes: 3

Views: 572

Answers (1)

Rüdiger Herrmann
Rüdiger Herrmann

Reputation: 20985

The RevTag class represents a tag in JGit. To read a tag from a repository you'd want to use a RevWalk like so:

Repository repository = ...
ObjectId objectId = ObjectId.fromString("a33a2d4dff046b3a19e36b3d1026fbcc5b806889");
try (RevWalk revWalk = new RevWalk(repository)) {
  RevTag revTag = revWalk.parseTag(objectId);
  // do something with revTag
}

The JGit project also offers a command line interpreter with functionality much like native git. It can be found in the org.eclipse.jgit.pgm bundle/library. I recommend to have a look into the show command if you want to learn more about obtaining information from a tag or the referenced commit.

Upvotes: 2

Related Questions