-
Notifications
You must be signed in to change notification settings - Fork 1
/
pre-receive
48 lines (39 loc) · 906 Bytes
/
pre-receive
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
#!/bin/bash
ERRORS_FOUND=0
while read COMMIT_START COMMIT_END REFNAME
do
echo "Start: $COMMIT_START"
echo "End: $COMMIT_END"
echo "Ref.: $REFNAME"
echo ""
# changes to branch
FILES_CHANGED=$(git diff-tree --no-commit-id --name-only -r $COMMIT_START $COMMIT_END 2> /dev/null)
if [ $? -gt 0 ]
then
# new branch
FILES_CHANGED=$(git diff-tree --no-commit-id --name-only -r $COMMIT_END 2> /dev/null)
if [ $? -gt 0 ]
then
# probably removing a branch
continue
fi
fi
echo "Starting PHP Syntax check..."
for FILE in $FILES_CHANGED
do
if [ ${FILE: -4} == ".php" ]
then
git show $COMMIT_END:$FILE | php -l 1> /dev/null
if [ $? -gt 0 ]
then
echo "in $FILE"
ERRORS_FOUND=$((ERRORS_FOUND + 1))
fi
fi
done
done
if [ $ERRORS_FOUND -gt 0 ]
then
echo "Not deployed. Syntax errors found"
exit 1
fi