mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-05-23 09:09:36 +02:00
[git-bridge] Added warning on non-fresh repo initialisations (#32432)
* [git-bridge] Added warning on non-fresh repo initialisations Addresses a TODO by adding a warning when trying to initialise a repo that already exists and is not fresh. GitOrigin-RevId: f801df9e1c77bfbc8a9a4101f01d5a71c383dc0f
This commit is contained in:
@@ -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
|
if (repo.getObjectDatabase().exists()) {
|
||||||
// sure whether the repo to be init'd doesn't exist or is just fresh
|
boolean isFreshRepo = true;
|
||||||
// and we crashed / aborted while committing
|
try {
|
||||||
if (repo.getObjectDatabase().exists()) return;
|
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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user