JGit BlameCommand 不断返回 null

JGit BlameCommand keeps returning null

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

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 命令代码)它确实做了它应该做的事情并为我提供了我需要的信息。这个问题的原因可能是什么?我很确定我也为函数提供了 legit 参数。我对 BlameCommand 的处理不知何故不正确吗?

您可以将您对该命令的处理与org.eclipse.jgit.test/tst/org/eclipse/jgit/api/BlameCommandTest.java like here

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

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