Skip to content

Commit 4579d16

Browse files
author
Benjamin Pick
committed
Include Githook for commit abort when php syntax error
1 parent 0b5bf2d commit 4579d16

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

.githooks/pre-commit

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#!/bin/sh
2+
FILES=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
3+
PROJECT=`php -r "echo dirname(dirname(realpath('$0')));"`
4+
5+
# Determine if a file list is passed
6+
if [ "$#" -eq 1 ]
7+
then
8+
oIFS=$IFS
9+
IFS='
10+
'
11+
SFILES="$1"
12+
IFS=$oIFS
13+
fi
14+
SFILES=${SFILES:-$FILES}
15+
16+
for FILE in $SFILES
17+
do
18+
php -l -n -d display_errors=0 $PROJECT/$FILE 1> /dev/null
19+
if [ $? != 0 ]
20+
then
21+
echo
22+
echo "Fix the error before commit."
23+
exit 1
24+
fi
25+
FILES="$FILES $PROJECT/$FILE"
26+
done

deploy.sh

+1
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,7 @@ README.md
146146
CHANGELOG.md
147147
.git
148148
.gitignore
149+
.githooks
149150
tests
150151
test
151152
phpunit.xml

0 commit comments

Comments
 (0)