-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathpre-commit
executable file
·42 lines (41 loc) · 1.23 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
#!/bin/bash
# Author: Remigijus Jarmalavičius <[email protected]>
# Author: Vytautas Povilaitis <[email protected]>
ROOT_DIR="$(pwd)/"
LIST=$(git status | grep -e '\#.*\(modified\|added\)')
ERRORS_BUFFER=""
for file in $LIST
do
if [ "$file" == '#' ]; then
continue
fi
if [ $(echo "$file" | grep 'modified') ]; then
FILE_ACTION="modified"
elif [ $(echo "$file" | grep 'added') ]; then
FILE_ACTION="added"
else
EXTENSION=$(echo "$file" | grep ".php$")
if [ "$EXTENSION" != "" ]; then
echo "Checking $FILE_ACTION file: $file"
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
fi
fi
done
if [ "$ERRORS_BUFFER" != "" ]; then
echo
echo "These errors were found in try-to-commit files: "
echo -e $ERRORS_BUFFER
echo
echo "Can't commit, fix errors first."
exit 1
else
echo "Commited successfully."
fi