gpt4 book ai didi

git - JGit BlameCommand 不断返回 null

转载 作者:行者123 更新时间:2023-12-02 13:40:39 25 4
gpt4 key购买 nike

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

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)
}
}
当我导航到终端中的存储库时, checkout 旧提交(与我的代码中的提交 ID 相同)并在相同的文件(与我的代码中的路径相同)上运行 git blame 命令,它确实做了它应该做的事情并为我提供与我需要的信息。这个问题的原因可能是什么?我很确定我也为函数提供了合法的参数。我对 BlameCommand 的处理是否不正确?

最佳答案

您可以将您对该命令的处理与 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)实际上引用的是文件,而不是文件夹。

关于git - JGit BlameCommand 不断返回 null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63769467/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com