]> gitweb.ps.run Git - git-hooks/blobdiff - git-hooks/post-receive
add chmod to git-hooks/post-receive
[git-hooks] / git-hooks / post-receive
index 33368010368d21af1075281800b9cbcba7dca988..2c425d7c2d03e5ea6328da43731417245b8b385b 100755 (executable)
@@ -1,11 +1,32 @@
 #!/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"
+
+# cd into repo
+os.chdir(REPO)
+
+# list all directories
+dirs = check(["git", "ls-tree", "--name-only", BRANCH]).splitlines()
 
 for d in dirs:
-    files = os.listdir(d)
+    # list all files
+    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}')
+        # print the hook and write it to the git repo
+        file = check(["git", "--no-pager", "show", f"{BRANCH}:{d}/{f}"])
+
+        hookpath = f"/srv/git/{d}/hooks/{f}"
+        with open(hookpath, "w") as fd:
+            fd.write(file)
+
+        check(["chmod", "+x", hookpath])