Last active
March 16, 2020 15:09
-
-
Save acleon/c9a866ea63f25c94e6021a85caad663c to your computer and use it in GitHub Desktop.
PHP CS Fixer Pre-commit Hook
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
#!/bin/bash | |
# Diff agaisnt HEAD, unless it's the first commit, in which case diff | |
# against an empty tree object. | |
if git rev-parse --verify HEAD > /dev/null | |
then | |
against=HEAD | |
else | |
# Initial commit: diff against an empty tree object | |
against=4b825dc642cb6eb9a060e54bf8d69288fbee4904 | |
fi | |
# Retrieve all files in staging area that are added, modified or renamed. Ignoring | |
# any deletions. | |
FILES=$(git diff-index --name-only --cached --diff-filter=ACMR $against -- | grep php$) | |
if [ "$FILES" == "" ]; then | |
exit 0 | |
fi | |
echo -n "PHP CS Fixer " | |
for FILE in $FILES | |
do | |
php-cs-fixer fix $FILE --rules=@Symfony,ordered_imports --quiet | |
echo -n . | |
done | |
echo " Done" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment