Improve corrupt repo detection

If a repo is corrupted on startup, the merger is unable to correct
it due to a logic error.

This change corrects that by correcting the initialization sequence
so that we delete corrupt repos regardless of whether we are
performing the initialization.

Change-Id: I5e813f360609e7b06691bd4cf3b6ac0d1edf5b0b
This commit is contained in:
James E. Blair committed 2026-09-02 10:37:00 -07:00
1 parent 35dbb240d6
commit 36f15e647c
1 file changed
+3 -2
+3 -2
View File
@@ -173,11 +173,12 @@ class Repo(object):
def _ensure_cloned(self, zuul_event_id, build=None):
log = get_annotated_logger(self.log, zuul_event_id, build=build)
repo_is_cloned = os.path.exists(os.path.join(self.local_path, '.git'))
if self._initialized and repo_is_cloned:
if repo_is_cloned:
try:
# validate that the repo isn't corrupt
git.Repo(self.local_path)
return
if self._initialized:
return
except Exception:
# the repo is corrupt, delete the local path
shutil.rmtree(self.local_path)