daml/dev-env/bin/da-install-git-hooks
Digital Asset GmbH 05e691f558 open-sourcing daml
2019-04-04 09:33:38 +01:00

24 lines
875 B
Bash
Executable File

#!/usr/bin/env bash
set -Eeuo pipefail
HOOK_NAMES=(pre-push)
TOP_DIR=$(git rev-parse --show-toplevel)
HOOK_DIR=$TOP_DIR/.git/hooks
REPO_HOOKS=$TOP_DIR/dev-env/git-hooks
for hook in "${HOOK_NAMES[@]}"; do
# If the hook already exists, is executable, and is not a symlink
if [[ ! -h "$HOOK_DIR/$hook" && -x "$HOOK_DIR/$hook" ]]; then
echo "Saving local $HOOK_DIR/$hook hook"
mv "$HOOK_DIR/$hook" "$HOOK_DIR/$hook.local"
fi
# create the symlink, overwriting the file if it exists
# probably the only way this would happen is if you're using an old version of git
# -- back when the sample hooks were not executable, instead of being named ____.sample
# we link all hooks to the wrapper, so we could also invoke .local hooks
echo "Installing $HOOK_DIR/$hook hook"
ln -s -f "$REPO_HOOKS/hook-wrapper" "$HOOK_DIR/$hook"
done