Skip to content

Commit 860ef50

Browse files
author
Martin Schaef
committed
adding workaround for all-zero commit
1 parent 722e4c7 commit 860ef50

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main/java/com/amazonaws/gurureviewercli/adapter/GitAdapter.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
*/
3131
public final class GitAdapter {
3232

33+
private static final String GITHUB_UNKNOWN_COMMIT = "0000000000000000000000000000000000000000";
34+
// this is the sha for an empty commit, so any diff against this will return the full repo content.
35+
private static final String GITHUB_EMPTY_COMMIT_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";
36+
3337
@Nonnull
3438
public static GitMetaData getGitMetaData(final Configuration config, final Path pathToRepo) throws IOException {
3539
val gitDir = pathToRepo.toRealPath().resolve(".git");
@@ -122,20 +126,23 @@ private static Collection<Path> getChangedFiles(final Repository repository) thr
122126

123127
private static boolean validateCommits(final Configuration config, final Repository repo)
124128
throws GitAPIException {
129+
String beforeCommitSha = config.getBeforeCommit();
130+
if (GITHUB_UNKNOWN_COMMIT.equals(config.getBeforeCommit())) {
131+
beforeCommitSha = GITHUB_EMPTY_COMMIT_SHA;
132+
}
125133

126-
val beforeTreeIter = treeForCommitId(repo, config.getBeforeCommit());
134+
val beforeTreeIter = treeForCommitId(repo, beforeCommitSha);
127135
val afterTreeIter = treeForCommitId(repo, config.getAfterCommit());
128136

129137
// Resolve git constants, such as HEAD^^ to the actual commit hash
130-
config.setBeforeCommit(resolveSha(repo, config.getBeforeCommit()));
138+
config.setBeforeCommit(resolveSha(repo, beforeCommitSha));
131139
config.setAfterCommit(resolveSha(repo, config.getAfterCommit()));
132140

133141
val diffEntries = new Git(repo).diff().setOldTree(beforeTreeIter).setNewTree(afterTreeIter).call();
134142
if (diffEntries.isEmpty()) {
135143
throw new GuruCliException(ErrorCodes.GIT_EMPTY_DIFF, String.format("No difference between {} and {}",
136144
beforeTreeIter, afterTreeIter));
137145
}
138-
139146
return true;
140147
}
141148

0 commit comments

Comments
 (0)