From 1071cff3ca2626dca967eb0989c0874764c460e2 Mon Sep 17 00:00:00 2001 From: patrick-scho Date: Tue, 3 Jun 2025 14:28:54 +0200 Subject: [PATCH] git-hooks/post-receive --- blog/post-receive | 0 git-hooks/post-receive | 19 ++++++++++++++++--- 2 files changed, 16 insertions(+), 3 deletions(-) mode change 100644 => 100755 blog/post-receive diff --git a/blog/post-receive b/blog/post-receive old mode 100644 new mode 100755 diff --git a/git-hooks/post-receive b/git-hooks/post-receive index 3336801..8e4c837 100755 --- a/git-hooks/post-receive +++ b/git-hooks/post-receive @@ -1,11 +1,24 @@ #!/usr/bin/env python import os +import subprocess -dirs = [d for d in os.listdir() if not d.startswith('.')] +def check(args, input=None): + return subprocess.check_output(args, text=True, input=input).strip() + + +# config repo and branch +REPO = "/srv/git/git-hooks" +BRANCH = "main" + +os.chdir(REPO) + +dirs = check(["git", "ls-tree", "--name-only", BRANCH]).splitlines() for d in dirs: - files = os.listdir(d) + files = check(["git", "ls-tree", "--name-only", f"{BRANCH}:{d}"]).splitlines() for f in files: - print(f'cp {d}/{f} /srv/git/{d}/hooks/{f}') + file = check(["git", "--no-pager", "show", f"{BRANCH}:{d}/{f}"]) + with open(f"/srv/git/{d}/hooks/{f}", "w") as fd: + fd.write(file) -- 2.50.1