From 024df497d161fa02b97d392cc4d4c52153c844d9 Mon Sep 17 00:00:00 2001 From: 2 * r + 2 * t <61896496+soramanew@users.noreply.github.com> Date: Sun, 14 Jun 2026 23:41:02 +1000 Subject: [PATCH] fix: re-clone repo if url changed --- src/caelestia/utils/dots/source.py | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/src/caelestia/utils/dots/source.py b/src/caelestia/utils/dots/source.py index 76f45f3..23ae9c3 100644 --- a/src/caelestia/utils/dots/source.py +++ b/src/caelestia/utils/dots/source.py @@ -1,3 +1,4 @@ +import shutil import subprocess from pathlib import Path @@ -27,13 +28,23 @@ class DotsSource: return dots_dir / relpath def ensure(self) -> None: - """Clone the repo if absent, otherwise fetch the latest refs.""" + """Clone the repo if absent, otherwise fetch the latest refs. + + If the configured url changed, the stale clone is removed and re-cloned + from the new source. + """ if self.exists(): - self._git("fetch", "--prune", "origin", self.branch) - else: - dots_dir.parent.mkdir(parents=True, exist_ok=True) - self._run("git", "clone", "--branch", self.branch, self.url, str(dots_dir)) + if self.current_url() == self.url: + self._git("fetch", "--prune", "origin", self.branch) + return + shutil.rmtree(dots_dir) + + dots_dir.parent.mkdir(parents=True, exist_ok=True) + self._run("git", "clone", "--branch", self.branch, self.url, str(dots_dir)) + + def current_url(self) -> str: + return self._git("remote", "get-url", "origin").strip() def checkout_tip(self) -> str: """Reset the working tree to the fetched tip and return its commit hash."""