Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Discovering remote branches of previously cloned repositories.

Hi folks,

Question for you. I'm using the Porcelain API.

I've found that It's easy enough to discover the remote branches of a
freshly cloned repo at the time I clone it.

scala> val git = new
    setCloneSubmodules(true).setDirectory(new File("/tmp/3435")).

scala> git.branchList.setListMode(ALL).call
res20: java.util.List[org.eclipse.jgit.lib.Ref] = [

Fair enough, that's all well and good.

The problem is when I reopen that same cloned repo later on, I can't
seem to retrieve any branch information.

scala> val repo2 = new FileRepository("/tmp/3435")
scala> val git2 = new Git(repo2)
scala> git2.branchList.setListMode(ALL).call
res24: java.util.List[org.eclipse.jgit.lib.Ref] = []

^^ as you can see, the branch list comes out empty here.

This is a rather unintuitive result, and I've not been able to figure
out where I'm going wrong here.

Am I doing something wrong with the construction of the
FileRepository? Should I be using FileRespositoryBuilder or something
like that? I tried that and got the same result:

scala> val fr = (new FileRepositoryBuilder).setGitDir(new
scala> val git3 = new Git(fr)
scala> git3.branchList.setListMode(ALL).call
res25: java.util.List[org.eclipse.jgit.lib.Ref] = []

However, the remote branch information is clearly present in the
remote repository, because if I use the command line git, it sees

$ cd /tmp/3436
$ git branch -r

So, what do I need to do differently to get the same info out of JGit?

Same thing also happens if I clone the repo with the command line then
open with JGit, so I suspect it's the way the FileRepository is being
opened to be the problem, rather than than the CloneCommand.

And advice would be appreciated, as I suspect it's something obvious
that I must as a jgit newbie be overlooking.


Back to the top