Skip to content

Commit 8b005cc

Browse files
authored
Merge pull request #29 from martinschaef/fixes
Address 0000000000000000 commit hash issue
2 parents 896ad70 + 860ef50 commit 8b005cc

File tree

2 files changed

+11
-4
lines changed

2 files changed

+11
-4
lines changed

Diff for: .github/workflows/self-test-and-release.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
if: steps.iam-role.outcome == 'success'
6565
shell: bash
6666
env:
67-
EXPECTED: 102
67+
EXPECTED: 103
6868
run: |
6969
[[ $(jq -r '.runs[0].results[].ruleId' code-guru/recommendations.sarif.json | wc -l) -eq $EXPECTED ]] || { echo "Expected $EXPECTED recommendations but got $(jq -r '.runs[0].results[].ruleId' code-guru/recommendations.sarif.json | wc -l)"; exit 1; }
7070

Diff for: src/main/java/com/amazonaws/gurureviewercli/adapter/GitAdapter.java

+10-3
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)