-
Notifications
You must be signed in to change notification settings - Fork 328
/
Copy pathhooks-wrapper
executable file
·38 lines (33 loc) · 1.13 KB
/
hooks-wrapper
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
# Runs all executable pre-commit-* hooks and exits after,
# if any of them was not successful.
#
# Based on
# https://github.com/ELLIOTTCABLE/Paws.js/blob/Master/Scripts/git-hooks/chain-hooks.sh
# http://osdir.com/ml/git/2009-01/msg00308.html
#
# assumes your scripts are located at <repo-root>/bin/git/hooks
exitcodes=()
hookname=`basename $0`
# our special hooks folder
CUSTOM_HOOKS_DIR=$(git rev-parse --show-toplevel)/dotgit/hooks
# find gits native hooks folder
NATIVE_HOOKS_DIR=$(git rev-parse --show-toplevel)/.git/hooks
# Run each hook, passing through STDIN and storing the exit code.
# We don't want to bail at the first failure, as the user might
# then bypass the hooks without knowing about additional issues.
for hook in $CUSTOM_HOOKS_DIR/$(basename $0)-*; do
test -x "$hook" || continue
$hook "$@"
exitcodes+=($?)
done
# check if there was a local hook that was moved previously
if [ -f "$NATIVE_HOOKS_DIR/$hookname.local" ]; then
out=`$NATIVE_HOOKS_DIR/$hookname.local "$@"`
exitcodes+=($?)
echo "$out"
fi
# If any exit code isn't 0, bail.
for i in "${exitcodes[@]}"; do
[ "$i" == 0 ] || exit $i
done