]> gitweb.ps.run Git - git-hooks/commitdiff
git-hooks/post-receive
authorpatrick-scho <patrick.schoenberger@posteo.de>
Tue, 3 Jun 2025 12:28:54 +0000 (14:28 +0200)
committerpatrick-scho <patrick.schoenberger@posteo.de>
Tue, 3 Jun 2025 12:28:54 +0000 (14:28 +0200)
blog/post-receive [changed mode: 0644->0755]
git-hooks/post-receive

old mode 100644 (file)
new mode 100755 (executable)
index 33368010368d21af1075281800b9cbcba7dca988..8e4c8372f6c39074cc17d8bfb110bf9d03edaf05 100755 (executable)
@@ -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)