-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpre-commit.sh
More file actions
31 lines (25 loc) · 759 Bytes
/
pre-commit.sh
File metadata and controls
31 lines (25 loc) · 759 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
#!/bin/bash
FILES_TO_CHECK=$(git status | grep -e '\#.*\(modified\|new file\)'| egrep "(.php|.module|.inc|.install)" | awk '{print $NF}')
ERRORS=""
echo -e "\n=============="
echo -e "= PHP pre commit verification"
echo -e "=============="
for FILE in $FILES_TO_CHECK; do
echo -ne "Checking \e[01;33m$FILE\e[00m..."
ERROR=$(php -l $PWD/$FILE 2>&1 | grep "PHP Parse error")
if [ "$ERROR" == "" ]; then
echo -e "\e[00;34mOK\e[00m"
else
echo -e "\e[00;31mERROR\e[00m"
ERRORS="$ERRORS\n$FILE => $ERROR"
fi
done
if [ "$ERRORS" == "" ]; then
echo -e "\e[01;32mAll seems to be OK... proceed to commit...\e[00m"
else
echo -e "\e[00;31mErrors where encountered processing files.\e[00m"
echo -e $ERRORS
echo "=========="
echo "Exiting"
exit 1
fi