I have a bare repo located at main.git
and am trying to fetch a branch (foo
, let's say) in another repo, test
, which has only just been git init
'd:
fetchtest/
|- main.git/
|- test/
|- .git/
Using regular git commands, I can do a git fetch ../main.git foo:foo
and this will make a new branch foo
in test/
and fetch the objects required for the branch. I then want to do the same thing but programmatically using JGit, ie not using the git CLI but using only Java code. There is no way I can use the git CLI:
Git git = Git.init().setDirectory(new File("fetchtest/test/")).call();
git.fetch().setRemote(new File("../main.git"))
.setRefSpecs(new RefSpec("foo:foo"))
.call();
but it just errors with:
org.eclipse.jgit.api.errors.TransportException: Remote does not have foo available for fetch.
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:137)
// ......
Caused by: org.eclipse.jgit.errors.TransportException: Remote does not have foo available for fetch.
at org.eclipse.jgit.transport.FetchProcess.expandSingle(FetchProcess.java:349)
at org.eclipse.jgit.transport.FetchProcess.executeImp(FetchProcess.java:139)
at org.eclipse.jgit.transport.FetchProcess.execute(FetchProcess.java:113)
at org.eclipse.jgit.transport.Transport.fetch(Transport.java:1069)
at org.eclipse.jgit.api.FetchCommand.call(FetchCommand.java:128)
How do I get this to work?