-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpre-commit
executable file
·57 lines (49 loc) · 1.59 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/bin/bash
ROOT_DIR="$(pwd)/"
LIST=$(git diff-index --cached --name-only --diff-filter=ACMR HEAD)
ERRORS_BUFFER=""
for file in $LIST
do
EXTENSION=$(echo "$file" | grep -E "\.(php|inc|module|profile|install)$")
if [ "$EXTENSION" != "" ]; then
ERRORS=$(php -l "$ROOT_DIR$file" 2>&1 | grep "Parse error")
if [ "$ERRORS" != "" ]; then
if [ "$ERRORS_BUFFER" != "" ]; then
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
else
ERRORS_BUFFER="$ERRORS"
fi
echo "Syntax errors found in file: $file "
fi
# Check for xdebug statments
ERRORS=$(grep -nH xdebug_ "$ROOT_DIR$file" | \
sed -e 's/^/Found XDebug Statment : /')
if [ "$ERRORS" != "" ]; then
if [ "$ERRORS_BUFFER" != "" ]; then
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
else
ERRORS_BUFFER="$ERRORS"
fi
fi
# Check for devel
ERRORS=$(grep -nHE "(dsm|kpr|dpm|dpr|ddebug_backtrace|ksm|kint)\(" "$ROOT_DIR$file" | \
sed -e 's/^/Found Devel Statment : /')
if [ "$ERRORS" != "" ]; then
if [ "$ERRORS_BUFFER" != "" ]; then
ERRORS_BUFFER="$ERRORS_BUFFER\n$ERRORS"
else
ERRORS_BUFFER="$ERRORS"
fi
fi
fi
done
if [ "$ERRORS_BUFFER" != "" ]; then
echo
echo "Found PHP parse errors: "
echo -e $ERRORS_BUFFER
echo
echo "PHP parse errors found. Fix errors and commit again."
exit 1
else
echo "No PHP parse errors found."
fi