JGit BlameCommand不断返回null

对于我当前的项目,我需要找出哪些用户最后修改了给定文件中的一系列行。为此,我一直在使用JGit,并用Kotlin编写了代码。到目前为止,到目前为止,我已经意识到,当我尝试使用JGit blame命令时,即使它没有引发异常,它也始终返回null。这是我目前拥有的原型函数,它将在感兴趣的范围内逐行打印最后一个提交者的电子邮件(请注意LocationInfo类,这是一个自定义数据类,其中包含我要检查的文件路径和范围): / p>

fun getcontributors(location: LocationInfo,git: Git,commitID: ObjectId)  {
    val blamer = blameCommand(git.repository)
    blamer.setfilePath(location.path.substringAfter(git.repository.directory.parent)) 
    blamer.setStartCommit(commitID)
    val blameResult = blamer.call() // blameResult is always null!
    println("Blaming: ${location.path.substringAfter(git.repository.directory.parent + "/")}")
    for (line in location.range.start..location.range.end) {
        println(blameResult.getsourceCommitter(line).emailaddress)
    }
}

当我导航到终端中的存储库时,签出旧的提交(与我的代码中的提交ID相同)并在相同的文件(与我的代码中的路径相同)上运行git blame命令,确实可以实现它的目的并提供我所需的信息。造成此问题的原因是什么?我很确定我也为该函数提供了合法的参数。我对blameCommand的处理不正确吗?

iCMS 回答:JGit BlameCommand不断返回null

您可以将此命令的处理方式与org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java之类的here进行比较

BlameCommand command = new BlameCommand(db);
command.setFilePath("file.txt");
BlameResult lines = command.call();

因此请确保location.path.substringAfter(git.repository.directory.parent)实际上引用了文件,而不是文件夹。

本文链接:https://www.f2er.com/1613911.html

大家都在问