はじめに
- githooks - Chaining git hooks - Stack Overflow のとおり
- sh だけでできるので手軽で便利
簡単な手順
スクリプト作成
.git/hooks/hook-chain
#!/bin/bash
#
# author: orefalo
hookname=`basename $0`
FILE=`mktemp`
trap 'rm -f $FILE' EXIT
cat - > $FILE
for hook in $GIT_DIR/hooks/$hookname.*
do
if test -x "$hook"; then
# echo $hook
cat $FILE | $hook "$@"
status=$?
if test $status -ne 0; then
echo Hook $hook failed with error code $status
exit $status
fi
fi
done
フックに設定(pre-commit に設定する場合)
$ cd .git/hooks
$ chmod +x hook-chain
$ mv pre-commit pre-commit.rename_if_already_exist
$ ln -s hook-chain pre-commit