trap EXIT is just too brittle, use plain || die Suggested-by: geirha on #bash IRC channel
41 lines
1.1 KiB
Bash
Executable File
41 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
# Framework for running git hooks in git-obs and osc
|
|
#
|
|
# To install the hooks on the system, place executables under:
|
|
# - /usr/local/share/git-obs-hooks/<git-hook>.d/<filename>
|
|
# - /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.
|
|
set -eu
|
|
|
|
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
|
GIT_OBS_HOOKS_DEBUG=${GIT_OBS_HOOKS_DEBUG:-${GIT_TRACE:-0}}
|
|
|
|
hook_name=${0##*/}
|
|
|
|
die() {
|
|
exit_code=$?
|
|
printf >&2 '%s\n' "$1"
|
|
exit "$exit_code"
|
|
}
|
|
|
|
debug_msg() {
|
|
if [ "$GIT_OBS_HOOKS_DEBUG" = 1 ]; then
|
|
printf >&2 '%s\n' "$1"
|
|
fi
|
|
}
|
|
|
|
debug_msg "Running $hook_name hooks:"
|
|
for hook in \
|
|
"$XDG_DATA_HOME/git-obs-hooks/$hook_name.d"/* \
|
|
"/usr/local/share/git-obs-hooks/$hook_name.d"/* \
|
|
"/usr/share/git-obs-hooks/$hook_name.d"/*
|
|
do
|
|
if [ -f "$hook" ] && [ -x "$hook" ] ; then
|
|
debug_msg " - Running $hook"
|
|
"$hook" "$@" || die "ERROR: '$hook' failed with exit status $?"
|
|
fi
|
|
done
|