Skip to content

Instantly share code, notes, and snippets.

@damienrg
Last active November 24, 2023 14:22
Show Gist options
  • Save damienrg/411f63a5120206bb887929f4830ad0d0 to your computer and use it in GitHub Desktop.
Save damienrg/411f63a5120206bb887929f4830ad0d0 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
@Konfekt
Copy link

Konfekt commented Nov 24, 2023

Hello, for your possible interest, here's an adaption that also takes care of the global hooks (introduced in 2.9): https://gist.github.com/Konfekt/d9e86763b0f3febd7b2f7ca589f6c482

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment