Skip to content

Instantly share code, notes, and snippets.

@Koziolek
Forked from damienrg/git-multi-hook-template
Created November 7, 2020 16:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Koziolek/fe9cbebf4576f8fd86f864f0942c3653 to your computer and use it in GitHub Desktop.
Save Koziolek/fe9cbebf4576f8fd86f864f0942c3653 to your computer and use it in GitHub Desktop.
Script to allow multi hooks per hook type for git
#!/usr/bin/env bash
# Allow multiple hooks.
#
# To use it copy this script with executable permission in ".git/hooks/hook-name"
# where hook-name is the name of the hook (see man githooks to know available hooks).
# Then place your scripts with executable permission in ".git/hooks/hook-name.d/".
hook_type=${BASH_SOURCE##*/}
case "$hook_type" in
applypatch-msg \
|commit-msg \
|fsmonitor-watchman \
|post-checkout \
|post-commit \
|post-merge \
|post-update \
|pre-applypatch \
|pre-commit \
|prepare-commit-msg \
|pre-push \
|pre-rebase \
|pre-receive \
|update)
IFS= read -rd '' stdin
for file in "${BASH_SOURCE[0]}.d"/*; do
"./$file" "$@" <<<"$stdin" || exit 2
done
exit 0
;;
*)
echo "unknown hook type: $hook_type"
exit 2
;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment