summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
authorJoakim Reinert <mail@jreinert.com>2015-05-04 19:15:00 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-05-05 12:21:27 +0200
commit8ec8aa2ad859b2e8586da299400477c243ecc4f2 (patch)
tree25430b423a92b936562a6e9fc89250fca0293a62 /scripts
parente9f7b053141043e683a549783eea634072051a69 (diff)
Add install script for git hooks
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/hooks-wrapper.sh12
-rwxr-xr-xscripts/install-git-hooks.sh15
2 files changed, 27 insertions, 0 deletions
diff --git a/scripts/hooks-wrapper.sh b/scripts/hooks-wrapper.sh
new file mode 100755
index 000000000..e89a3567d
--- /dev/null
+++ b/scripts/hooks-wrapper.sh
@@ -0,0 +1,12 @@
+#!/usr/bin/bash
+if [ -x $0.local ]; then
+ $0.local "$@" || exit $?
+fi
+
+basename=$(basename "$0")
+hooks_dir="$GIT_DIR/../git-hooks"
+hook="$hooks_dir/$basename"
+
+if [ -x "$hook" ]; then
+ "$hook" "$@" || exit $?
+fi
diff --git a/scripts/install-git-hooks.sh b/scripts/install-git-hooks.sh
new file mode 100755
index 000000000..63faa345b
--- /dev/null
+++ b/scripts/install-git-hooks.sh
@@ -0,0 +1,15 @@
+#!/usr/bin/bash
+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_DIR/hooks-wrapper.sh $HOOK_DIR/$hook
+done