Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get repository from commit in jgit

Tags:

java

git

jgit

I have a RevCommit (api) object. I want to get the Repository (api) object from it. My main goal is to get the origin url. So I planned to get Repository -> getConfig() -> -> load() -> getString().

How to get config object from RevCommit object? Is this the correct way to get origin url from a commit?

I tried googling but no success.

like image 365
Abhishek Gupta Avatar asked Feb 18 '26 19:02

Abhishek Gupta


1 Answers

The RevCommit does not reference the repository it was loaded from. You'll have to track that in your application code. If you have a list of known repositories, you could lookup (repository.resolve( commit.name() )) the commit. It feels a bit hacky though. And of course, you'll end up with multiple hits if there are multiple repositories with the same content.

Once you hold the repository in question you may use repository.getConfig().getString() to obtain the origins.

If you believe that RevComit should reference the repository it belongs to, you may want to open an enhancement request to discuss that with the JGit team.

like image 51
Rüdiger Herrmann Avatar answered Feb 20 '26 11:02

Rüdiger Herrmann



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!