]> gitweb.ps.run Git - git-hooks/blob - git-hooks/post-receive
2c425d7c2d03e5ea6328da43731417245b8b385b
[git-hooks] / git-hooks / post-receive
1 #!/usr/bin/env python
2
3 import os
4 import subprocess
5
6 def check(args, input=None):
7   return subprocess.check_output(args, text=True, input=input).strip()
8
9
10 # config repo and branch
11 REPO = "/srv/git/git-hooks"
12 BRANCH = "main"
13
14 # cd into repo
15 os.chdir(REPO)
16
17 # list all directories
18 dirs = check(["git", "ls-tree", "--name-only", BRANCH]).splitlines()
19
20 for d in dirs:
21     # list all files
22     files = check(["git", "ls-tree", "--name-only", f"{BRANCH}:{d}"]).splitlines()
23
24     for f in files:
25         # print the hook and write it to the git repo
26         file = check(["git", "--no-pager", "show", f"{BRANCH}:{d}/{f}"])
27
28         hookpath = f"/srv/git/{d}/hooks/{f}"
29         with open(hookpath, "w") as fd:
30             fd.write(file)
31
32         check(["chmod", "+x", hookpath])