blob: 822a324c6c96181d255cd8b26f272d30ae303aef [file] [log] [blame]
#! /usr/bin/env sh
dir=`realpath $(dirname "$BASH_SOURCE:-0")`
githookdir=`git rev-parse --git-dir`/hooks
# Space separated list of hooks to install
declare -a HOOKS=("pre-commit" "commit-msg")
for hook in ${HOOKS[@]}; do
if [ ! -f "${dir}/${hook}" ]; then
continue
fi
# Soft remove the old script in .git/hooks so that git doesn't try to run
# multiple hooks.
if [ -f "${githookdir}/${hook}" ]; then
mv "${githookdir}/${hook}" "${githookdir}/${hook}.old"
fi
git config --unset-all hook.${hook}.command
git config --add hook.${hook}.command "${dir}/${hook}"
# Sanity check: there should be a single hook per line and it should point to the
# git-hooks repository.
git hook list "${hook}"
done