Last active
September 22, 2017 15:03
-
-
Save wrseward/258cab96c73840335e5823b308c59d77 to your computer and use it in GitHub Desktop.
git pre-commit hook for php-cs-fixer
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
#!/usr/bin/env bash | |
set -e | |
echo "php-cs-fixer start" | |
PHP_CS_FIXER="./vendor/bin/php-cs-fixer" | |
if [ -x $PHP_CS_FIXER ]; then | |
if git diff --cached --name-only --diff-filter=ACMRTUXB | grep -q '\.php$'; then | |
STAGED_FILES=$(git diff --cached --name-only --diff-filter=ACMRTUXB | grep '\.php$') | |
$PHP_CS_FIXER fix --verbose --config=.php_cs.dist -- ${STAGED_FILES[@]}; | |
git add ${STAGED_FILES[@]} | |
fi | |
else | |
echo "" | |
echo "Please install php-cs-fixer, e.g.:" | |
echo "" | |
echo " composer require --dev friendsofphp/php-cs-fixer" | |
echo "" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment