From 4e00af20a38326553b0a546ed02ef6d9f08dfac9 Mon Sep 17 00:00:00 2001 From: Lephenixnoir Date: Wed, 13 Mar 2024 23:00:32 +0100 Subject: [PATCH] giteapc: automatically switch remotes when updating repos --- giteapc/repos.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/giteapc/repos.py b/giteapc/repos.py index e419a22..d223d22 100644 --- a/giteapc/repos.py +++ b/giteapc/repos.py @@ -101,10 +101,24 @@ class LocalRepo: return False raise e + def updateRemotes(self): + # Automatically switch old gitea URLs to Forgejo + for r in self._git(["remote"], stdout=PIPE).stdout.split(): + url = self._git(["remote", "get-url", r], stdout=PIPE).stdout.rstrip(b"\n") + new = url + if url.startswith(b"gitea@gitea.planet-casio.com:"): + new = b"forgejo@git" + url[11:] + if url.startswith(b"https://gitea.planet-casio.com/"): + new = b"https://git." + url[14:] + if new != url: + self._git(["remote", "set-url", r, new]) + def fetch(self): + self.updateRemotes() self._git(["fetch"]) def pull(self): + self.updateRemotes() if self.is_on_branch(): self._git(["pull"])