aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIgor Wiedler <igor@wiedler.ch>2010-03-10 20:07:10 +0100
committerIgor Wiedler <igor@wiedler.ch>2010-03-10 20:07:10 +0100
commitdb8c557e4c6fee0a66c78863d4082dc17ff22d57 (patch)
tree3443abfdfb8a1d7b47afecdb9ccd177cf3ea0909 /git-tools/hooks
parentMerge branch 'develop-olympus' of git://github.com/evil3/phpbb3 into develop-... (diff)
downloadphpbb-db8c557e4c6fee0a66c78863d4082dc17ff22d57.tar.gz
phpbb-db8c557e4c6fee0a66c78863d4082dc17ff22d57.tar.bz2
phpbb-db8c557e4c6fee0a66c78863d4082dc17ff22d57.zip
[git-tools] pre-commit hook for syntax checking
This pre-commit hook utilises PHP's command-line -l (lint) option, which checks for syntax errors. In case of an error the commit is rejected and the error displayed. Testing is welcome.
Diffstat (limited to 'git-tools/hooks')
-rwxr-xr-xgit-tools/hooks/pre-commit44
1 files changed, 44 insertions, 0 deletions
diff --git a/git-tools/hooks/pre-commit b/git-tools/hooks/pre-commit
new file mode 100755
index 0000000000..4a070d130c
--- /dev/null
+++ b/git-tools/hooks/pre-commit
@@ -0,0 +1,44 @@
+#!/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
+
+# 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
+ # store lint result in a temp file
+ tempfile="/tmp/$(basename $0).$$.tmp"
+ if ! php -l "$file" >/dev/null 2>"$tempfile"
+ then
+ error=1
+ cat "$tempfile"
+ fi
+ rm -f "$tempfile"
+done
+unset IFS
+
+if [ $error -eq 1 ]
+then
+ exit 1
+fi