Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/self-test-and-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ jobs:
if: steps.iam-role.outcome == 'success'
shell: bash
env:
EXPECTED: 102
EXPECTED: 103
run: |
[[ $(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; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
*/
public final class GitAdapter {

private static final String GITHUB_UNKNOWN_COMMIT = "0000000000000000000000000000000000000000";
// this is the sha for an empty commit, so any diff against this will return the full repo content.
private static final String GITHUB_EMPTY_COMMIT_SHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904";

@Nonnull
public static GitMetaData getGitMetaData(final Configuration config, final Path pathToRepo) throws IOException {
val gitDir = pathToRepo.toRealPath().resolve(".git");
Expand Down Expand Up @@ -122,20 +126,23 @@ private static Collection<Path> getChangedFiles(final Repository repository) thr

private static boolean validateCommits(final Configuration config, final Repository repo)
throws GitAPIException {
String beforeCommitSha = config.getBeforeCommit();
if (GITHUB_UNKNOWN_COMMIT.equals(config.getBeforeCommit())) {
beforeCommitSha = GITHUB_EMPTY_COMMIT_SHA;
}

val beforeTreeIter = treeForCommitId(repo, config.getBeforeCommit());
val beforeTreeIter = treeForCommitId(repo, beforeCommitSha);
val afterTreeIter = treeForCommitId(repo, config.getAfterCommit());

// Resolve git constants, such as HEAD^^ to the actual commit hash
config.setBeforeCommit(resolveSha(repo, config.getBeforeCommit()));
config.setBeforeCommit(resolveSha(repo, beforeCommitSha));
config.setAfterCommit(resolveSha(repo, config.getAfterCommit()));

val diffEntries = new Git(repo).diff().setOldTree(beforeTreeIter).setNewTree(afterTreeIter).call();
if (diffEntries.isEmpty()) {
throw new GuruCliException(ErrorCodes.GIT_EMPTY_DIFF, String.format("No difference between {} and {}",
beforeTreeIter, afterTreeIter));
}

return true;
}

Expand Down