-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·39 lines (33 loc) · 915 Bytes
/
pre-commit
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
EXIT=0
function search_warning {
OUTPUT=''
PATTERN=$1
FILES=$2
while read name; do
git diff --cached $name | grep -E "^\+.*$PATTERN" &> /dev/null
if [ $? -eq 0 ]; then
OUTPUT=$OUTPUT${OUTPUT:+"\n"}$name
fi
done <<< "`
if [ -z $FILES ]; then
git diff --cached --name-only
else
git diff --cached --name-only | sed -e "/\.\($FILES\)$/!d"
fi
`"
if [ -n "$OUTPUT" ]; then
echo "Pre-commit error: pattern '$PATTERN' is defined in files below"
echo -e $OUTPUT;
EXIT=1;
fi
}
# warning if `console.` is defined in js|tt|html|htm
search_warning 'console\.' 'js\|tt\|html\|htm'
# warning if `!!!` is defined in js|tt|html|htm
search_warning '!!!' 'js\|tt\|html\|htm'
# warning if `=======` is defined
search_warning '======='
if [ $EXIT = 1 ]; then
exit $EXIT;
fi