]> gitweb.ps.run Git - git-hooks/blob - git-hooks/post-receive
git-hooks/post-receive
[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 os.chdir(REPO)
15
16 dirs = check(["git", "ls-tree", "--name-only", BRANCH]).splitlines()
17
18 for d in dirs:
19     files = check(["git", "ls-tree", "--name-only", f"{BRANCH}:{d}"]).splitlines()
20
21     for f in files:
22         file = check(["git", "--no-pager", "show", f"{BRANCH}:{d}/{f}"])
23         with open(f"/srv/git/{d}/hooks/{f}", "w") as fd:
24             fd.write(file)