Skip to content

Commit

Permalink
Fix NPE from getDirectory() by using known root directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwiddis committed Jan 17, 2022
1 parent 226fec2 commit b420ffc
Showing 1 changed file with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public enum DateSource {
private final GitPathResolver pathResolver;
private final Repository repository;
private final TimeZone timeZone;
private final boolean shallow;

/**
* Creates a new {@link GitLookup} for a repository that is detected from the supplied {@code anyFile}.
Expand All @@ -78,7 +79,8 @@ public GitLookup(File anyFile, DateSource dateSource, TimeZone timeZone, int che
/* A workaround for https://bugs.eclipse.org/bugs/show_bug.cgi?id=457961 */
this.repository.getObjectDatabase().newReader().getShallowCommits();

this.pathResolver = new GitPathResolver(repository.getWorkTree().getAbsolutePath());
String rootDir = repository.getWorkTree().getAbsolutePath();
this.pathResolver = new GitPathResolver(rootDir);
this.dateSource = dateSource;
switch (dateSource) {
case COMMITER:
Expand All @@ -95,6 +97,7 @@ public GitLookup(File anyFile, DateSource dateSource, TimeZone timeZone, int che
throw new IllegalStateException("Unexpected " + DateSource.class.getName() + " " + dateSource);
}
this.checkCommitsCount = checkCommitsCount;
this.shallow = new File(rootDir + File.separatorChar + ".git" + File.separatorChar + "shallow").exists();
}

/**
Expand Down Expand Up @@ -186,9 +189,7 @@ String getAuthorEmailOfCreation(File file) throws IOException, GitAPIException {
}

boolean isShallowRepository() {
File dotGit = repository.getDirectory();
File shallow = new File(dotGit.getPath() + File.separator + "shallow");
return shallow.exists();
return this.shallow;
}

private boolean isFileModifiedOrUnstaged(String repoRelativePath) throws GitAPIException {
Expand Down

0 comments on commit b420ffc

Please sign in to comment.