giteapc: automatically switch remotes when updating repos

This commit is contained in:
Lephenixnoir 2024-03-13 23:00:32 +01:00
parent 2fcd9726a0
commit 4e00af20a3
Signed by: Lephenixnoir
GPG Key ID: 1BBA026E13FC0495
1 changed files with 14 additions and 0 deletions

View File

@ -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"])