Stefan Tauner | 7634708 | 2016-11-27 17:45:49 +0100 | [diff] [blame] | 1 | #!/bin/sh -e |
| 2 | |
| 3 | root=$(git rev-parse --show-cdup 2>/dev/null) || \ |
| 4 | { echo "Not under git control. Cannot install git hooks." >&2 ; exit 0 ; } |
| 5 | |
| 6 | dst="${root}"$(git rev-parse --git-path hooks/) |
| 7 | src=util/git-hooks/ # relative to root |
| 8 | hooks=$(cd "${root}${src}" && git ls-files -c | grep -Ev 'install.sh|wrapper.sh') |
| 9 | |
| 10 | for 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 Tauner | 68b5f00 | 2017-10-01 16:52:55 +0200 | [diff] [blame] | 17 | ln -s "$(git rev-parse --prefix $(git rev-parse --git-path hooks/) --show-cdup)${src}wrapper.sh" \ |
| 18 | "${dst}$h" |
Stefan Tauner | 7634708 | 2016-11-27 17:45:49 +0100 | [diff] [blame] | 19 | fi |
| 20 | done |