summaryrefslogtreecommitdiffstats
path: root/scripts/install-git-hooks.sh
blob: 1a4113f8d25370d242503cb27110384f04478d99 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#!/bin/bash

set -e

SCRIPTS_DIR=$(realpath $(dirname "$0"))
HOOK_DIR=$(realpath "$SCRIPTS_DIR/../.git/hooks")
HOOK_NAMES="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"

for hook in $HOOK_NAMES; do
    # If the hook already exists, is executable, and is not a symlink
    if [ ! -h $HOOK_DIR/$hook -a -x $HOOK_DIR/$hook ]; then
        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
    ln -s -f ../../scripts/hooks-wrapper.sh $HOOK_DIR/$hook
done