-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit-hook-example
More file actions
39 lines (31 loc) · 987 Bytes
/
pre-commit-hook-example
File metadata and controls
39 lines (31 loc) · 987 Bytes
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
#!/bin/bash
# this is an example pre-commit hook script
# to use it, copy it to the .svn/hooks/ dir on your repo and ensure it can be executed
#
# This example will abort any commits whose diff contain any "forbidden" word
# list of words that cannot be committed
blacklist='fixme todo debug'
# redirect stdout to stderr
exec 1>&2
declare -a filelist
declare -a changelist
for arg in "$@"; do
if [ "$arg" = '--cl' -o "$arg" = '--changelist' ]; then
changelist=( '--cl' )
elif [ "${#changelist[@]}" = 1 ]; then
changelist+=( "$arg" )
elif [ -e "$arg" ]; then
filelist+=("$arg")
fi
done
if [ ${#filelist[@]} -eq 0 ]; then
filelist+=(".")
fi
difflist="$(svn diff -x -U0 "${filelist[@]}" "${changelist[@]}" )"
if grep -qiE "^\\+.*(${blacklist// /|})" <<< "$difflist"; then
echo ${blacklist// /, } comments found:
echo
grep -iEe "^\\+.*(${blacklist// /|})" -e '^index:' <<< "$difflist" \
| grep --color=always -ie ${blacklist// / -e } -B 1
exit 1
fi