mirror of
https://git.alemi.dev/gitshell.git
synced 2024-11-21 23:14:53 +01:00
fix: properly recur in subdirs, handle paths
This commit is contained in:
parent
702267a7a1
commit
d2aa3b61cf
1 changed files with 20 additions and 17 deletions
|
@ -6,38 +6,41 @@ from pathlib import Path
|
||||||
|
|
||||||
GIT_ROOT = Path(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_path):
|
||||||
cmd = ["git", "config", "-f", f"{GIT_ROOT}{repo}/config", "remote.origin.mirror"]
|
cmd = ["git", "config", "-f", f"{repo_path}/config", "remote.origin.mirror"]
|
||||||
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
||||||
if proc.stdout.decode().strip() == "true":
|
if proc.stdout.decode().strip() == "true":
|
||||||
return True
|
return True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
def get_direction(repo):
|
def get_direction(repo_path):
|
||||||
cmd = ["git", "config", "-f", f"{GIT_ROOT}{repo}/config", "remote.origin.direction"]
|
cmd = ["git", "config", "-f", f"{repo_path}/config", "remote.origin.direction"]
|
||||||
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
proc = subprocess.run(cmd, stdout=subprocess.PIPE)
|
||||||
return proc.stdout.decode().strip()
|
return proc.stdout.decode().strip()
|
||||||
|
|
||||||
def fetch_all(repo):
|
def fetch_all(repo_path):
|
||||||
print(f"[<] Fetching {repo}")
|
print(f"[<] Fetching {repo_path}")
|
||||||
subprocess.run(["git", "fetch", "--all"], cwd=GIT_ROOT+repo)
|
subprocess.run(["git", "fetch", "--all"], cwd=repo_path)
|
||||||
if os.path.isfile(f"{GIT_ROOT}{repo}/hooks/post-receive"):
|
if os.path.isfile(f"{repo_path}/hooks/post-receive"):
|
||||||
subprocess.run([f"{GIT_ROOT}{repo}/hooks/post-receive"])
|
subprocess.run([f"{repo_path}/hooks/post-receive"])
|
||||||
|
|
||||||
def push_all(repo):
|
def push_all(repo_path):
|
||||||
print(f"[>] Pushing {repo}")
|
print(f"[>] Pushing {repo_path}")
|
||||||
subprocess.run(["git", "push", "origin"], cwd=GIT_ROOT+repo)
|
subprocess.run(["git", "push", "origin"], cwd=repo_path)
|
||||||
#subprocess.run([f"{GIT_ROOT}.hooks/post-update"], cwd=GIT_ROOT+repo)
|
#subprocess.run([f"{GIT_ROOT}.hooks/post-update"], cwd=GIT_ROOT+repo)
|
||||||
|
|
||||||
def run_on_all_repos(root: Path):
|
def run_on_all_repos(root: Path):
|
||||||
for element in os.listdir(root):
|
for element in os.listdir(root):
|
||||||
if element.endswith(".git"):
|
full_path = root / element
|
||||||
if is_mirror(element):
|
if element.startswith("."):
|
||||||
direction = get_direction(element)
|
pass # ignore hidden files
|
||||||
|
elif element.endswith(".git"):
|
||||||
|
if is_mirror(full_path):
|
||||||
|
direction = get_direction(full_path)
|
||||||
if direction == "up":
|
if direction == "up":
|
||||||
push_all(element)
|
push_all(full_path)
|
||||||
if direction == "down":
|
if direction == "down":
|
||||||
fetch_all(element)
|
fetch_all(full_path)
|
||||||
elif os.path.isdir(root / element):
|
elif os.path.isdir(root / element):
|
||||||
run_on_all_repos(root / element)
|
run_on_all_repos(root / element)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue