From 2eff2c44760cba2a3391589e7b82fc587516f4ce Mon Sep 17 00:00:00 2001 From: Lawrence Kwan Date: Mon, 16 Feb 2026 04:08:22 +0800 Subject: [PATCH] fix: clean up partial clone artifacts when git clone fails When GitHub (or any git remote) is unavailable and clone_repository raises pygit2.GitError, the partially created repo directory was left behind with broken symlinks and incomplete files. On subsequent sync attempts, _discover_repository would find these artifacts, leading to an accumulation of broken symlinks in the filesystem. This fix removes the partial clone directory when a clone fails, preventing broken symlinks from accumulating. Fixes #634 --- packages/opal-server/opal_server/git_fetcher.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/opal-server/opal_server/git_fetcher.py b/packages/opal-server/opal_server/git_fetcher.py index 67e1016e9..364549a41 100644 --- a/packages/opal-server/opal_server/git_fetcher.py +++ b/packages/opal-server/opal_server/git_fetcher.py @@ -230,6 +230,13 @@ async def _clone(self): ) except pygit2.GitError: logger.exception(f"Could not clone repo at {self._source.url}") + # Clean up any partial clone artifacts (broken symlinks, incomplete dirs) + # that may have been created before the error occurred + if self._repo_path.exists(): + logger.warning( + "Cleaning up partial clone at {path}", path=self._repo_path + ) + shutil.rmtree(self._repo_path, ignore_errors=True) else: logger.info(f"Clone completed: {self._source.url}") await self._notify_on_changes(repo)