feat: fetch mirrors in subdirs too

This commit is contained in:
əlemi 2024-02-08 14:55:36 +01:00
parent 2bb737e89b
commit 702267a7a1
Signed by: alemi
GPG key ID: A4895B84D311642C

View file

@ -1,10 +1,10 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import os.path
import subprocess 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): def is_mirror(repo):
cmd = ["git", "config", "-f", f"{GIT_ROOT}{repo}/config", "remote.origin.mirror"] 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(["git", "push", "origin"], cwd=GIT_ROOT+repo)
#subprocess.run([f"{GIT_ROOT}.hooks/post-update"], cwd=GIT_ROOT+repo) #subprocess.run([f"{GIT_ROOT}.hooks/post-update"], cwd=GIT_ROOT+repo)
if __name__ == "__main__": def run_on_all_repos(root: Path):
for element in os.listdir(GIT_ROOT): for element in os.listdir(root):
if element.endswith(".git"): if element.endswith(".git"):
if is_mirror(element): if is_mirror(element):
direction = get_direction(element) direction = get_direction(element)
@ -38,4 +38,9 @@ if __name__ == "__main__":
push_all(element) push_all(element)
if direction == "down": if direction == "down":
fetch_all(element) fetch_all(element)
elif os.path.isdir(root / element):
run_on_all_repos(root / element)
if __name__ == "__main__":
run_on_all_repos(GIT_ROOT)