Get repository from commit in 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.
One Solution collect form web for “Get repository from commit in jgit”
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.