【发布时间】:2012-07-03 11:48:59
【问题描述】:
我有一个位于 main.git 的裸仓库,我正试图在另一个仓库 test 中获取一个分支(假设是 foo),它刚刚是 git init'd:
fetchtest/
|- main.git/
|- test/
|- .git/
使用常规 git 命令,我可以执行 git fetch ../main.git foo:foo,这将在 test/ 中创建一个新分支 foo 并获取分支所需的对象。 然后我想做同样的事情,但以编程方式使用 JGit,即不使用 git CLI,而只使用 Java 代码。我无法使用 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();
但它只是错误:
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)
如何让它工作?
【问题讨论】:
-
你不寻找的答案:学习命令行git d=
-
@David:我应该补充一点,我不能使用 git 命令行 - 我必须以编程方式使用它。 (J)Git 实际上是我正在构建的应用程序的一部分,它将在客户端的硬件上运行,并且不会安装 git(我也不想安装它,在 Windows 上设置很痛苦)。他们唯一拥有的就是 Java。
标签: java git version-control jgit git-fetch