treesummaryrefslogcommitdiff
diff options
context:
space:
mode:
authorpatrick-scho2025-06-03 14:28:54 +0200
committerpatrick-scho2025-06-03 14:28:54 +0200
commit1071cff3ca2626dca967eb0989c0874764c460e2 (patch)
tree43bc1d5eae49b4aa7b45d61b614a8ba73e5d55f0
parent076923d8cd87e546f11c42252d227239436bf7f0 (diff)
downloadgit-hooks-1071cff3ca2626dca967eb0989c0874764c460e2.tar.gz
git-hooks-1071cff3ca2626dca967eb0989c0874764c460e2.zip
git-hooks/post-receive
-rwxr-xr-x[-rw-r--r--]blog/post-receive0
-rwxr-xr-xgit-hooks/post-receive19
2 files changed, 16 insertions, 3 deletions
diff --git a/blog/post-receive b/blog/post-receive
index 32124b6..32124b6 100644..100755
--- a/blog/post-receive
+++ b/blog/post-receive
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)