aboutsummaryrefslogtreecommitdiff
blob: 612947019605b6e11d6941514b165220fe3e924f (plain)
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
#!/bin/sh
#
# A hook to disallow php syntax errors to be committed
# by running php -l (lint) on them. It requires php-cli
# to be installed.
#
# This is a pre-commit hook.
#
# To install this you can either copy or symlink it to
# $GIT_DIR/hooks, example:
#
# ln -s ../../git-tools/hooks/pre-commit \\
#   .git/hooks/pre-commit

PHP_BIN=php

# necessary check for initial commit
if git rev-parse --verify HEAD >/dev/null 2>&1
then
	against=HEAD
else
	# Initial commit: diff against an empty tree object
	against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
fi

error=0

# get a list of staged .php files, omitting file removals
IFS=" "
for file in $(git diff --cached --name-status $against | grep -v -E '^D' | cut -f2 | grep -E '\.php$')
do
	# hide output, but show errors
	if ! $PHP_BIN -l "$file" >/dev/null
	then
		error=1
	fi
done
unset IFS

if [ $error -eq 1 ]
then
	exit 1
fi