Add script for installing hooks This script automates the process of adding all the hooks to git config. It should be run from the parent repo that has the git-hooks repository as a submodule. Bug: b/187094215 Change-Id: I2da6a931eae6aad1fa8eb5fb6aecf6ce6e825cca
diff --git a/install_hooks.sh b/install_hooks.sh new file mode 100755 index 0000000..90c3480 --- /dev/null +++ b/install_hooks.sh
@@ -0,0 +1,15 @@ +#! /usr/bin/env sh + +#git config --add hook.pre-commit.command `realpath +dir=`realpath $(dirname "$BASH_SOURCE:-0")` + +# 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 + git config --add hook.${hook}.command "${dir}/${hook}" + git list hook "${hook}" +done