forked from pivotal-cf/git-hooks-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
.base-hook
executable file
·57 lines (43 loc) · 971 Bytes
/
.base-hook
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env bash
set -eu
git_dir=$( git rev-parse --git-dir )
script_name=$(basename $0)
if [ -f "${git_dir}/hooks/${script_name}" ]; then
"${git_dir}/hooks/${script_name}" $@
fi
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
WHITELISTS=${DIR}/whitelists
whitelisted() {
file=$1
path=${DIR}/whitelists.d/$file
if [ -f "${path}" ]; then
while read -r; do
if [ $REPLY == $(pwd) ]; then
return 0
fi
done < ${path}
fi
return 1
}
whitelist=""
has_whitelist() {
hookPath=$1
while read -ra LINE; do
whitelistEntry="${LINE[0]}"
if [ "$hookPath" == "$whitelistEntry" ]; then
whitelist="${LINE[1]}"
return 0
fi
done < ${WHITELISTS}
return 1
}
HOOKS_DIR="${DIR}/$( basename ${0} ).d"
for hook in $( ls $HOOKS_DIR ); do
REL_HOOK="$( basename ${0} ).d"/$hook
if has_whitelist $REL_HOOK; then
if whitelisted $whitelist; then
continue
fi
fi
$HOOKS_DIR/$hook $@
done