|
@@ -66,10 +66,22 @@ public class GitProjectRepo implements ProjectRepo {
|
|
|
initRepositoryField(repoStore);
|
|
initRepositoryField(repoStore);
|
|
|
Preconditions.checkState(repository.isPresent());
|
|
Preconditions.checkState(repository.isPresent());
|
|
|
Repository repo = this.repository.get();
|
|
Repository repo = this.repository.get();
|
|
|
- // TODO: assert that this is a fresh repo. At the moment, we can't be
|
|
|
|
|
- // sure whether the repo to be init'd doesn't exist or is just fresh
|
|
|
|
|
- // and we crashed / aborted while committing
|
|
|
|
|
- if (repo.getObjectDatabase().exists()) return;
|
|
|
|
|
|
|
+ if (repo.getObjectDatabase().exists()) {
|
|
|
|
|
+ boolean isFreshRepo = true;
|
|
|
|
|
+ try {
|
|
|
|
|
+ isFreshRepo = repo.resolve("HEAD") == null;
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ Log.warn(
|
|
|
|
|
+ "[{}] initRepo could not resolve HEAD to determine repo freshness", projectName, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (!isFreshRepo) {
|
|
|
|
|
+ // if the repo has commits (due to a previous crash/abort while it was being initialised),
|
|
|
|
|
+ // we're returning early, expecting the repo to be reset to a clean state.
|
|
|
|
|
+ // Logging a warning to track this scenario.
|
|
|
|
|
+ Log.warn("[{}] initRepo called on repo that already has commits", projectName);
|
|
|
|
|
+ }
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
repo.create();
|
|
repo.create();
|
|
|
}
|
|
}
|
|
|
|
|
|