Skip to content

Instantly share code, notes, and snippets.

@MarkVaughn
Forked from mindbat/pre-commit.lint
Last active June 27, 2018 17:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkVaughn/514686b454e91b2870fe8c2daae2b74d to your computer and use it in GitHub Desktop.
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.
#!/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