Skip to content

Instantly share code, notes, and snippets.

@renatomarinho
Created February 9, 2017 10:10
Show Gist options
  • Select an option

  • Save renatomarinho/f3cb9eb40de43a2b3f465d52c1fe0738 to your computer and use it in GitHub Desktop.

Select an option

Save renatomarinho/f3cb9eb40de43a2b3f465d52c1fe0738 to your computer and use it in GitHub Desktop.
pre-commit
#!/usr/bin/env bash
# gist: https://gist.github.com/jwage/b1614c96ea22ccaf68b7
ROOT="/path/code/"
echo "php-cs-fixer pre commit hook start"
PHP_CS_FIXER="/usr/local/bin/php-cs-fixer"
HAS_PHP_CS_FIXER=false
if [ -x $PHP_CS_FIXER ]; then
HAS_PHP_CS_FIXER=true
fi
if $HAS_PHP_CS_FIXER; then
git status --porcelain | grep -e '^[AM]\(.*\).php$' | cut -c 3- | while read line; do
$PHP_CS_FIXER fix --verbose "$line";
rm -Rf .php_cs.cache
git add "$line";
git rm .php_cs.cache
done
else
echo ""
echo "Please install php-cs-fixer, e.g.:"
echo ""
echo " composer require --dev fabpot/php-cs-fixer:dev-master"
echo ""
fi
echo "php-cs-fixer pre commit hook finish"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment