I've found similar question and base on it, but I got error Cannot invoke method getAuthorIdent() on null object
. I try to get last commit, check if it's equal to badAuthor
. Why it cannot be null
? And if statement will work like I want?
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