-
-
Save MarkVaughn/514686b454e91b2870fe8c2daae2b74d 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 hidden or 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=$(git rev-list --max-parents=0 HEAD) | |
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