使用JGit更新子模块时出现MissingObjectException

时间:2017-04-04 17:45:37

标签: git jgit

我正在尝试更新子模块:

git.submoduleUpdate().call()

但我明白了:

org.eclipse.jgit.api.errors.JGitInternalException: Missing unknown e88da827bdc5c5a4b0d87b8be79b81567759411b
    at org.eclipse.jgit.api.SubmoduleUpdateCommand.call(SubmoduleUpdateCommand.java:211)
    at kontinuum.WorkPackageProcessorKt.processWorkPackages(WorkPackageProcessor.kt:43)
    at kontinuum.MainKt.main(Main.kt:30)
Caused by: org.eclipse.jgit.errors.MissingObjectException: Missing unknown e88da827bdc5c5a4b0d87b8be79b81567759411b
    at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:145)
    at org.eclipse.jgit.lib.ObjectReader.open(ObjectReader.java:226)
    at org.eclipse.jgit.revwalk.RevWalk.parseAny(RevWalk.java:859)
    at org.eclipse.jgit.revwalk.RevWalk.parseCommit(RevWalk.java:772)
    at org.eclipse.jgit.api.SubmoduleUpdateCommand.call(SubmoduleUpdateCommand.java:175)
    ... 2 more

有趣的是在控制台上它可以工作:

kontinuum@ligi-tp ~/k/w/l/SurvivalManual> git submodule update
remote: Counting objects: 27, done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 27 (delta 17), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (27/27), done.
From https://github.com/ligi/SurvivalManual.wiki
   b72e23e..e88da82  master     -> origin/master
Submodule path 'android/src/main/assets/md': checked out 'e88da827bdc5c5a4b0d87b8be79b81567759411b'

2 个答案:

答案 0 :(得分:2)

正如@ max630指出这是一个jgit错误:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=470318

这是我现在的解决方法:

val walk = SubmoduleWalk.forIndex(git.repository)
while (walk.next()) {
   val submodule = walk.repository
   Git.wrap(submodule).fetch().call()
   submodule.close()
}

答案 1 :(得分:1)

与git不同,JGit不会在子模块更新时获取新对象。要避免这种情况,您可以尝试启用递归获取:

git config fetch.recurseSubmodules true

我不知道jgit是否实现了它