使用jgit,我克隆了一个git repo的主分支,然后我用这个检查了一个远程分支
git.checkout()
.setCreateBranch(true)
.setName(branch)
.setUpstreamMode(CreateBranchCommand.SetupUpstreamMode.TRACK)
.setStartPoint(s"origin/$branch")
.setForce(true)
.call()
然后我尝试git pull on this branch,
git.pull()。()调用
但最终出现此错误
Exception in thread "main" org.eclipse.jgit.api.errors.InvalidConfigurationException: No value for key branch.X.Y.Z.merge found in configuration
at org.eclipse.jgit.api.PullCommand.call(PullCommand.java:217)
at com.baml.cesium.sphinx.token.TestGIT$delayedInit$body.apply(TestGIT.scala:52)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at com.baml.cesium.sphinx.token.TestGIT$.main(TestGIT.scala:15)
at com.baml.cesium.sphinx.token.TestGIT.main(TestGIT.scala)
我发现签出的分支没有在.git / config中更新,这可能是此错误消息的原因。那么这个配置可以通过checkout以某种方式更新,或者jgit实际上是否允许在签出的分支上进行git pull?
(我知道我可以直接用jgit克隆一个分支,但我仍然想找到上面的答案)
谢谢!
答案 0 :(得分:1)
请事先尝试设置该配置:
StoredConfig config = git.getRepository().getConfig();
config.setString("branch", "master", "merge", "refs/heads/master");