我找到了類似的question並基於它,但我得到錯誤Cannot invoke method getAuthorIdent() on null object
。我嘗試獲得最後一次提交,請檢查它是否等於badAuthor
。爲什麼它不能是null
?如果聲明會像我想要的那樣工作?Jgit作者最後提交
def authorEqual() {
def badAuthor = 'John'
Git git = Git.open(new File(".git"))
RevCommit lastCommit = null --> ERROR FROM HERE
List<Ref> branches = new Git(git.repository).branchList().setListMode(ListMode.ALL).call();
try {
RevWalk walk = new RevWalk(git.repository)
for(Ref branch : branches){
RevCommit commit = walk.parseCommit(branch.getObjectId());
PersonIdent aAuthor = commit.getAuthorIdent()
if(commit.getAuthorIdent().getWhen().compareTo(
-----------^ <-- HERE ERROR
lastCommit.getAuthorIdent().getWhen().equals(badAuthor)) > 0)
lastCommit = commit;
println commit
我想你在使用它之前沒有設置lastCommit。 – dynamo
'RevCommit lastCommit = null' - >鏈接問題示例 –
您應該檢查lastCommit是否爲空。無論如何,如果你想找到由不良演員提交的提交,爲什麼你需要最後一次提交 – dynamo