From 702267a7a15d3ccf4fd018ddc6a29cbd33050f28 Mon Sep 17 00:00:00 2001 From: alemi Date: Thu, 8 Feb 2024 14:55:36 +0100 Subject: [PATCH] feat: fetch mirrors in subdirs too --- fetch-mirrors | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/fetch-mirrors b/fetch-mirrors index 56bb80c..936bcc3 100755 --- a/fetch-mirrors +++ b/fetch-mirrors @@ -1,10 +1,10 @@ #!/usr/bin/env python3 import os -import os.path import subprocess +from pathlib import Path -GIT_ROOT = os.environ.get("GIT_ROOT_DIR") or "/srv/git/" +GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/") def is_mirror(repo): cmd = ["git", "config", "-f", f"{GIT_ROOT}{repo}/config", "remote.origin.mirror"] @@ -29,8 +29,8 @@ def push_all(repo): subprocess.run(["git", "push", "origin"], cwd=GIT_ROOT+repo) #subprocess.run([f"{GIT_ROOT}.hooks/post-update"], cwd=GIT_ROOT+repo) -if __name__ == "__main__": - for element in os.listdir(GIT_ROOT): +def run_on_all_repos(root: Path): + for element in os.listdir(root): if element.endswith(".git"): if is_mirror(element): direction = get_direction(element) @@ -38,4 +38,9 @@ if __name__ == "__main__": push_all(element) if direction == "down": fetch_all(element) - + elif os.path.isdir(root / element): + run_on_all_repos(root / element) + +if __name__ == "__main__": + run_on_all_repos(GIT_ROOT) +