Skip to content
Browse files

Add recommend pre-commit hook for PHP lint

New hook scans the entire work tree for likely PHP files and runs PHP's lint mode over them.

If PHP's lint mode reports an error for any of those files, the commit is aborted.
  • Loading branch information...
1 parent 761d122 commit 940689bb3f20e1282e9bd259af767f13f0fdecd4 @stephen-smith committed Feb 4, 2011
Showing with 19 additions and 0 deletions.
  1. +19 −0 git-hooks/recommended/pre-commit
View
19 git-hooks/recommended/pre-commit
@@ -0,0 +1,19 @@
+#!/bin/sh
+
+php_lint_errors=$({
+ find . -type f \( -name '*.php' -o -name '*.php[45]' \) \
+ -exec php -l {} \; \
+ | grep -v '^No syntax errors detected in ';
+} 2>/dev/null)
+
+if ! [ -z "$php_lint_errors" ]; then
+ printf >&2 '%s\n' "PHP's lint mode detected the following errors:" \
+ "$php_lint_errors" \
+ "Aborting commit due to PHP errors detected by PHP's lint" \
+ 'mode in the working tree.' \
+ 'Full error messages including affected filenames are' \
+ 'reported above.'
+ exit 1
+fi
+
+exit 0

0 comments on commit 940689b

Please sign in to comment.
Something went wrong with that request. Please try again.