[英]How to JGit blame a file before commit?
上下文:我的合并遇到冲突,并且我有一个类似于以下示例的文件:
Foo.txt (合并)
1
<<<<<< HEAD
2-master
======
2-side
>>>>>> df803849788fde47965b3dc8f07f07d48320ea9c
3
问题:为了使开发人员实际更改了冲突的行,如何在提交之前责怪结果文件(上)? 它适用于git blame Foo.txt
问题:我尝试执行以下操作,但null
内的错误为null
。
MergeResult m = runMerge(aScenario);
BlameCommand blamer = new BlameCommand(git.getRepository());
BufferedReader br = new BufferedReader(new FileReader(new File(mergedfilepath)));
BlameResult blame = blamer.setFilePath(mergedfilepath).call();
for (int i = 0; (line= br.readLine())!=null ; i++) {
// the blame at this point is null.
PersonIdent person = blame.getSourceAuthor(i);
System.out.println(person.getName() + ": "+ line);
}
我认为遍历的来源应该是结果的内容。
从那里开始,您可以遍历更改的区域并要求作者。 例如:
BlameResult blameResult = git.blame().setFilePath( ... ).call();
int size = blameResult.getResultContents().size();
for( int i = 0; i < size; i++ ) {
System.out.println( blameResult.getSourceAuthor( i ) );
}
至少对于添加到该文件的工作目录版本中的行,将返回一个名为Not Committed Yet的作者。
但是,应准备好代码,使之与返回null
getSourceAuthor()
适应。 JavaDoc声明返回值可以为null 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.