aboutsummaryrefslogtreecommitdiffstats
path: root/roles/obsd_git/templates/hooks/post-receive
blob: 18034d5b300a4d6b1679f5480e37bc39c8469592 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#!/bin/sh
#
# Run the post-receive scripts in post-receive.d/
#
# 1. After `git push` to a repository, when git finishes updating the refs in
#    the bare repo, it would run this `post-receive` hook.
# 2. When run, the bare repo is the working directory and Git will write one
#    line per updated ref to stdin e.g. <old-sha> <new-sha> refs/heads/main
# 3. *This script* then runs every executable that exists in post-receive.d
#    sequentially.
set -o errexit
set -o nounset

main() {
	input=$(cat)
	for hook in "$(dirname "$0")"/post-receive.d/*; do
		is_executable "$hook" || continue
		printf '%s\n' "$input" | "$hook"
	done
}

is_executable() {
	[ -x "$1" ]
}

main