我正在使用jgit进行以下尝试:
val git = Git.open(File("/path/toMyRepo"))
val diffFormatter = DiffFormatter(DisabledOutputStream.INSTANCE).apply {
setRepository(git.repository)
}
git.diff().call().forEach {
if (it.changeType == DiffEntry.ChangeType.MODIFY) {
diffFormatter.toFileHeader(it).toEditList().forEach {
println(it)
}
}
}但我得到了以下例外:
"org.eclipse.jgit.errors.MissingObjectException: Missing blob 9645ba8461cd88af20fd66a3e44055deb24f826e"有人看到代码有什么问题了吗?
编辑:使用相当空的repo (只有一个提交和唯一文件中唯一行的更改)的完整堆栈跟踪:
Exception in thread "main" org.eclipse.jgit.errors.MissingObjectException: Missing blob f7891cbde46bbb6ca96065ecf1900ef6a223f679
at org.eclipse.jgit.internal.storage.file.WindowCursor.open(WindowCursor.java:149)
at org.eclipse.jgit.diff.ContentSource$ObjectReaderSource.open(ContentSource.java:140)
at org.eclipse.jgit.diff.ContentSource$Pair.open(ContentSource.java:276)
at org.eclipse.jgit.diff.DiffFormatter.open(DiffFormatter.java:1020)
at org.eclipse.jgit.diff.DiffFormatter.createFormatResult(DiffFormatter.java:950)
at org.eclipse.jgit.diff.DiffFormatter.toFileHeader(DiffFormatter.java:915)
at MainKt.main(Main.kt:17)发布于 2022-11-15 13:27:30
不确定这是否有帮助,但我在这个问题上浪费了一些时间,如果将来有人掉进了这个漏洞:当您试图区分的最新更改没有提交时,这似乎是DiffFormatter类中的一些问题。
我的用例是获取单个文件的更改,为了使其工作,我直接使用了gitDiff接口,如下所示:
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
String filename = "mafile.java";
Git.open(File("/path/toMyRepo")).diff() // calling diff command
.setPathFilter(PathFilter.create(filename)) //setting to just look for changes in specific file
.setContextLines(0) // just the changes itself, not the bordering lines
.setOutputStream(byteArrayOutputStream) // the outputstream to print the changes
.call();
System.out.println(byteArrayOutputStream.toString(StandardCharsets.UTF_8));https://stackoverflow.com/questions/57709307
复制相似问题