diff options
| author | patrick-scho | 2025-06-03 14:28:54 +0200 |
|---|---|---|
| committer | patrick-scho | 2025-06-03 14:28:54 +0200 |
| commit | 1071cff3ca2626dca967eb0989c0874764c460e2 (patch) | |
| tree | 43bc1d5eae49b4aa7b45d61b614a8ba73e5d55f0 | |
| parent | 076923d8cd87e546f11c42252d227239436bf7f0 (diff) | |
| download | git-hooks-1071cff3ca2626dca967eb0989c0874764c460e2.tar.gz git-hooks-1071cff3ca2626dca967eb0989c0874764c460e2.zip | |
git-hooks/post-receive
| -rwxr-xr-x[-rw-r--r--] | blog/post-receive | 0 | ||||
| -rwxr-xr-x | git-hooks/post-receive | 19 |
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) |
