首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >缺少jgit的小斑点

缺少jgit的小斑点
EN

Stack Overflow用户
提问于 2019-08-29 11:35:12
回答 1查看 316关注 0票数 0

我正在使用jgit进行以下尝试:

代码语言:javascript
复制
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)
       }
    }
}

但我得到了以下例外:

代码语言:javascript
复制
    "org.eclipse.jgit.errors.MissingObjectException: Missing blob 9645ba8461cd88af20fd66a3e44055deb24f826e"

有人看到代码有什么问题了吗?

编辑:使用相当空的repo (只有一个提交和唯一文件中唯一行的更改)的完整堆栈跟踪:

代码语言:javascript
复制
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)
EN

回答 1

Stack Overflow用户

发布于 2022-11-15 13:27:30

不确定这是否有帮助,但我在这个问题上浪费了一些时间,如果将来有人掉进了这个漏洞:当您试图区分的最新更改没有提交时,这似乎是DiffFormatter类中的一些问题。

我的用例是获取单个文件的更改,为了使其工作,我直接使用了gitDiff接口,如下所示:

代码语言:javascript
复制
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));
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57709307

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档