Last active
August 29, 2015 14:03
-
-
Save JoshuaEstes/f5bb632811aa36f239ea to your computer and use it in GitHub Desktop.
Various git hooks
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 | |
### | |
# | |
# 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