8

I was wondering hows it would be possible to list all the branches of a remote Git repo with jgit but without cloning it.

While going through the jgit's javadoc, I found the ListBranchCommand but that only seem to work with an already opened Repository object. But I was not able to find how to create a Repository object over HTTP without cloning it in local.

Is it possible ? Thanks

Augier
  • 352
  • 4
  • 14

2 Answers2

5

Ok, never mind, after hours searching for the answer, I find it right before asking it there...

So, the answer is in the CookBook :

Collection<Ref> refs = Git.lsRemoteRepository()
            .setHeads(true)
            .setTags(true)
            .setRemote(REMOTE_URL)
            .call();
Augier
  • 352
  • 4
  • 14
5

There is the LsRemoteCommand to list the branches of a remote repository. To obtain the command, use either

Git.wrap(repo).lsRemote()

or

Git.lsRemoteRepository()

The statically created LsRemoteCommand has its limitations. For certain transport protocols, a local repository is necessary to obtain configuration settings. Therefore I usually create an empty temporary local repository with Git.init() and then use the first approach.

If you want to avoid creating the extra repository, you can test with Transport.open() if it succeeds without a repository. It throws a NotSupportedException otherwise.

Rüdiger Herrmann
  • 20,512
  • 11
  • 62
  • 79
  • Doesn't cloning the repo to local represent a problem when the distant repo is very large ? – Augier Apr 14 '14 at 14:30
  • @user3459089: There is no need to clone the remote repository. Just an empty local repository (as can be created with `Git.init()`) is necessary for certain transport protocols to work. – Rüdiger Herrmann Apr 14 '14 at 21:23
  • Ok, thank you for the answer. I have to admit that I never did researches in that way since it seemed pretty logic to me that you had to clone the repo to do these sort of commands. – Augier Apr 15 '14 at 08:01