|
30 | 30 | */
|
31 | 31 | public final class GitAdapter {
|
32 | 32 |
|
| 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 | + |
33 | 37 | @Nonnull
|
34 | 38 | public static GitMetaData getGitMetaData(final Configuration config, final Path pathToRepo) throws IOException {
|
35 | 39 | val gitDir = pathToRepo.toRealPath().resolve(".git");
|
@@ -122,20 +126,23 @@ private static Collection<Path> getChangedFiles(final Repository repository) thr
|
122 | 126 |
|
123 | 127 | private static boolean validateCommits(final Configuration config, final Repository repo)
|
124 | 128 | throws GitAPIException {
|
| 129 | + String beforeCommitSha = config.getBeforeCommit(); |
| 130 | + if (GITHUB_UNKNOWN_COMMIT.equals(config.getBeforeCommit())) { |
| 131 | + beforeCommitSha = GITHUB_EMPTY_COMMIT_SHA; |
| 132 | + } |
125 | 133 |
|
126 |
| - val beforeTreeIter = treeForCommitId(repo, config.getBeforeCommit()); |
| 134 | + val beforeTreeIter = treeForCommitId(repo, beforeCommitSha); |
127 | 135 | val afterTreeIter = treeForCommitId(repo, config.getAfterCommit());
|
128 | 136 |
|
129 | 137 | // Resolve git constants, such as HEAD^^ to the actual commit hash
|
130 |
| - config.setBeforeCommit(resolveSha(repo, config.getBeforeCommit())); |
| 138 | + config.setBeforeCommit(resolveSha(repo, beforeCommitSha)); |
131 | 139 | config.setAfterCommit(resolveSha(repo, config.getAfterCommit()));
|
132 | 140 |
|
133 | 141 | val diffEntries = new Git(repo).diff().setOldTree(beforeTreeIter).setNewTree(afterTreeIter).call();
|
134 | 142 | if (diffEntries.isEmpty()) {
|
135 | 143 | throw new GuruCliException(ErrorCodes.GIT_EMPTY_DIFF, String.format("No difference between {} and {}",
|
136 | 144 | beforeTreeIter, afterTreeIter));
|
137 | 145 | }
|
138 |
| - |
139 | 146 | return true;
|
140 | 147 | }
|
141 | 148 |
|
|
0 commit comments