Skip to content

Instantly share code, notes, and snippets.

@JoshuaEstes
Last active August 29, 2015 14:03
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 JoshuaEstes/f5bb632811aa36f239ea to your computer and use it in GitHub Desktop.
Save JoshuaEstes/f5bb632811aa36f239ea to your computer and use it in GitHub Desktop.
Various git hooks
#!/bin/sh
###
#
# Runs phpcs to check for violations
#
PHPCS_BIN=$(command -v phpcs)
if [ ! $PHPCS_BIN ]; then
exit 0
fi
if [ ! $(git config --bool hooks.phpcs.enabled) ]; then
exit 0;
fi
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
FILES=$(git diff --cached --name-only --diff-filter=ACMR $against | grep \.php)
for f in $FILES; do
$PHPCS_BIN $f
if [ $? != 0 ]; then
echo "Fix the file"
exit 1
fi
done
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment