blob: d557c2f8a24b0e6f3c24a9e5e0b12e00f610ebdf [file] [log] [blame]
Stefan Tauner76347082016-11-27 17:45:49 +01001#!/bin/sh -e
2
3root=$(git rev-parse --show-cdup 2>/dev/null) || \
4 { echo "Not under git control. Cannot install git hooks." >&2 ; exit 0 ; }
5
6dst="${root}"$(git rev-parse --git-path hooks/)
7src=util/git-hooks/ # relative to root
8hooks=$(cd "${root}${src}" && git ls-files -c | grep -Ev 'install.sh|wrapper.sh')
9
10for h in $hooks; do
11 # Test if hook is not already installed, i.e. doesn't point at the wrapper
12 if [ ! "${dst}$h" -ef "${root}${src}wrapper.sh" ]; then
13 # preserve custom hooks if any
14 if [ -e "${dst}$h" ]; then
15 mv "${dst}$h" "${dst}$h.local"
16 fi
Stefan Tauner68b5f002017-10-01 16:52:55 +020017 ln -s "$(git rev-parse --prefix $(git rev-parse --git-path hooks/) --show-cdup)${src}wrapper.sh" \
18 "${dst}$h"
Stefan Tauner76347082016-11-27 17:45:49 +010019 fi
20done