Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » EGit / JGit » Retrieve Tag information using JGit API
Retrieve Tag information using JGit API [message #725071] Tue, 13 September 2011 20:52 Go to next message
Kamal  is currently offline Kamal Friend
Messages: 2
Registered: September 2011
Junior Member
Hi

Can someone provide sample code snippet on how to retrieve the tag information from a git repository

Regards
Kamal
Re: Retrieve Tag information using JGit API [message #725074 is a reply to message #725071] Tue, 13 September 2011 21:14 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Kamal skrev 2011-09-13 22.52:
> Hi
>
> Can someone provide sample code snippet on how to retrieve the tag
> information from a git repository
>
> Regards
> Kamal

Map<String, Ref> tags = repository.getTags();

That will give you all tags in the repository.

-- robin
Re: Retrieve Tag information using JGit API [message #725075 is a reply to message #725074] Tue, 13 September 2011 21:24 Go to previous messageGo to next message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Robin Rosenberg skrev 2011-09-13 23.14:
> Kamal skrev 2011-09-13 22.52:
>> Hi
>>
>> Can someone provide sample code snippet on how to retrieve the tag
>> information from a git repository
>>
>> Regards
>> Kamal
>
> Map<String, Ref> tags = repository.getTags();
>

and you need to peel annoateted tags to get a reference

ref = repository.peel(ref)
ObjectId taggedObject = ref.getObjectId();

(tags may refer to any object type, not just commits)

A reverse operation is also possible to do the reverse,

Map<AnyObjectId, Set<Ref>> objectToFef = getAllRefsByPeeledObjectId();


> That will give you all tags in the repository.
>
> -- robin
>
Re: Retrieve Tag information using JGit API [message #725628 is a reply to message #725075] Thu, 15 September 2011 11:31 Go to previous messageGo to next message
Matthias Sohn is currently offline Matthias SohnFriend
Messages: 1268
Registered: July 2009
Senior Member
The other option is to use the ListTagCommand in the JGit porcelaine API.
Look at the corresponding test [1] to see how this works.

[1] see testListAllTagsInRepositoryInOrder() in TagCommandTest.java
Re: Retrieve Tag information using JGit API [message #727332 is a reply to message #725628] Wed, 21 September 2011 01:26 Go to previous messageGo to next message
Kamal  is currently offline Kamal Friend
Messages: 2
Registered: September 2011
Junior Member
Thanks Robin & Matthias.

My requirement is to identify whether any tag is associated with a specific commit, if so i need to retrieve the tag.
can you tell how can i retrieve based on the commit hash

Regards
Kamal
Re: Retrieve Tag information using JGit API [message #727695 is a reply to message #727332] Wed, 21 September 2011 20:00 Go to previous message
Robin Rosenberg is currently offline Robin RosenbergFriend
Messages: 332
Registered: July 2009
Senior Member
Kamal skrev 2011-09-21 03.26:
> Thanks Robin & Matthias.
>
> My requirement is to identify whether any tag is associated with a
> specific commit, if so i need to retrieve the tag.
> can you tell how can i retrieve based on the commit hash

You have to do the reverse lookup yourself, i.e. take all tags
and build a map with the target objects as key.

-- robin
Previous Topic:gitignore and folders bug
Next Topic:Tag icons
Goto Forum:
  


Current Time: Tue Mar 19 04:26:34 GMT 2024

Powered by FUDForum. Page generated in 0.03154 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top