fix: re-clone repo if url changed

This commit is contained in:
2 * r + 2 * t
2026-06-14 23:41:02 +10:00
parent 994f2d86f5
commit 024df497d1
+16 -5
View File
@@ -1,3 +1,4 @@
import shutil
import subprocess import subprocess
from pathlib import Path from pathlib import Path
@@ -27,13 +28,23 @@ class DotsSource:
return dots_dir / relpath return dots_dir / relpath
def ensure(self) -> None: 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(): if self.exists():
self._git("fetch", "--prune", "origin", self.branch) if self.current_url() == self.url:
else: self._git("fetch", "--prune", "origin", self.branch)
dots_dir.parent.mkdir(parents=True, exist_ok=True) return
self._run("git", "clone", "--branch", self.branch, self.url, str(dots_dir)) 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: def checkout_tip(self) -> str:
"""Reset the working tree to the fetched tip and return its commit hash.""" """Reset the working tree to the fetched tip and return its commit hash."""