#!/usr/bin/env bash # # This script is used to populate hook directories # Use flag -c to clean the hook directories # If hook files are already present, they will be overwritten # # Add or remove in order to generate different hooks # For available hooks, see githooks(5) hooktypes="applypatch-msg \ pre-applypatch \ post-applypatch \ pre-commit \ prepare-commit-msg \ commit-msg \ post-commit \ pre-rebase \ post-checkout \ post-merge \ pre-receive \ update \ post-receive \ post-update \ pre-auto-gc \ post-rewrite \ pre-push" path=$(realpath $0) path=${path%/*}/.. # Clean the hook directories if -c flag is present if [[ $1 == "-c" ]]; then find $path/hooks -mindepth 1 -maxdepth 1 -not -name "_init.sh" -exec rm -r {} + find $path/custom.d -mindepth 1 -maxdepth 1 -not -name "README" -exec rm -r {} + else populate_hook() { echo "#!/usr/bin/env bash . \"\${0%/*}/_init.sh\" exec_all \$HOOK_PATH/$1.d exec_custom $1 " >$path/hooks/$1 chmod +x $path/hooks/$1 } for hooktype in $hooktypes; do mkdir -p $path/custom.d/$hooktype touch $path/custom.d/$hooktype/.gitkeep mkdir -p $path/hooks/$hooktype.d touch $path/hooks/$hooktype.d/.gitkeep populate_hook $hooktype done fi