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) +