-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgit-obs-hook-template
55 lines (43 loc) · 1.28 KB
/
git-obs-hook-template
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/bin/sh
# Framework for running git hooks in git-obs and osc
#
# To install the hooks on the system, place executables under:
# - /usr/share/git-obs-hooks/<git-hook>.d/<filename>
# - ~/.local/share/git-obs-hooks/<git-hook>.d/<filename>
# To enable git-obs-hooks in the current git repo, run: install-git-obs-hooks
#
# See githooks(5) man page for more help on the hooks.
XDG_DATA_HOME="${XDG_DATA_HOME:-${HOME}/.local/share}"
GIT_OBS_HOOKS_DEBUG="${GIT_OBS_HOOKS_DEBUG:-0}"
HOOK_NAME="$(basename "$0")"
HOOK_DIR="$(readlink -f "$0").d"
HOME_HOOK_DIR="${XDG_DATA_HOME}/git-obs-hooks/${HOOK_NAME}"
trap_exit() {
exit_code=$?
if [ ${exit_code} -ne 0 ]; then
echo "ERROR: ${HOOK_NAME} hook '${hook}' failed with exit code ${exit_code}"
fi
exit $exit_code
}
trap "trap_exit" EXIT
debug_msg() {
if [ "${GIT_OBS_HOOKS_DEBUG}" != "1" ]; then
return
fi
echo "$@" >&1
}
debug_msg "Running ${HOOK_NAME} hooks:"
for hook in "${HOOK_DIR}"/*.sh ; do
if [ -x "${hook}" ] ; then
debug_msg " - Running ${hook}"
${hook} "$@"
fi
done
if [ -d "${HOME_HOOK_DIR}" ]; then
for hook in "${HOME_HOOK_DIR}"/*.sh ; do
if [ -x "${hook}" ] ; then
debug_msg " - Running ${hook}"
${hook} "$@"
fi
done
fi