From a6fd4c4f5ad2c44c607edab305a4c81bca94363c Mon Sep 17 00:00:00 2001 From: Miguel Serrano Date: Wed, 25 Mar 2026 14:49:40 +0100 Subject: [PATCH] [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 --- .../bridge/repo/GitProjectRepo.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepo.java b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepo.java index 86754f8ab4..54c5a57b86 100644 --- a/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepo.java +++ b/services/git-bridge/src/main/java/uk/ac/ic/wlgitbridge/bridge/repo/GitProjectRepo.java @@ -66,10 +66,22 @@ public class GitProjectRepo implements ProjectRepo { initRepositoryField(repoStore); Preconditions.checkState(repository.isPresent()); 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(); }