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
CloneCommand().setURI("http://github.com/benhardy/nitpick.git";).
    setBare(false).
setCloneAllBranches(true).
    setCloneSubmodules(true).setDirectory(new File("/tmp/3435")).
    setNoCheckout(false).setBranch("master").call

scala> git.branchList.setListMode(ALL).call
res20: java.util.List[org.eclipse.jgit.lib.Ref] = [
    Ref[refs/remotes/origin/issue-1-setup=ff61a99138c096e245dde8f3eb29a1dabb5b83e3],
    Ref[refs/remotes/origin/master=2f80949eccbe646c1997bf11d26bab653c3e7dd9],
    Ref[refs/remotes/origin/milestone-1=8f28d0f7396d7170c284fdf573b697d1aa2f3f9e]
]

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
File("/tmp/3436")).setup().build()
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
them:

$ cd /tmp/3436
$ git branch -r
  origin/issue-1-setup
  origin/master
  origin/milestone-1

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.

Thanks
Ben


Back to the top