Created
June 28, 2013 22:19
-
-
Save mindbat/5888602 to your computer and use it in GitHub Desktop.
Git pre-commit script to run all the modified files through php-lint. Won't let you commit php file with a syntax error.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# | |
# Hook script to check the changed files with php lint | |
# Called by "git commit" with no arguments. | |
# | |
# To enable this hook, rename this file to "pre-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 | |
if !(git diff --cached --name-only --diff-filter=AM $against | grep 'php' | xargs -P 10 -n1 php -l) | |
then | |
echo | |
echo "Error: You attempted to commit one or more php files with syntax errors." | |
echo | |
echo "Please fix them and retry the commit." | |
echo | |
exit 1 | |
fi | |
exec git diff-index --check --cached $against -- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maybe use
against=$(git rev-list --max-parents=0 HEAD)
for initial commit instead of4b825dc642cb6eb9a060e54bf8d69288fbee4904