Skip to content

Instantly share code, notes, and snippets.

@shaunlee
Last active March 2, 2016 10:20
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 shaunlee/0672f0f274b3d418e115 to your computer and use it in GitHub Desktop.
Save shaunlee/0672f0f274b3d418e115 to your computer and use it in GitHub Desktop.
Git hooks for phpcs
#!/bin/bash
#.git/hooks/pre-commit
EXEC=`php -r "echo 'php ', implode(DIRECTORY_SEPARATOR, [__DIR__, 'vendor', 'bin', 'phpcs']);"`
FILES=`git diff --cached --name-only | grep -i php$ | grep ^app`
ARGS='--standard=psr2 --encoding=utf8 -p'
for fn in $FILES; do
if [ ! -f $fn ]; then
DELETE=($fn)
FILES=("${FILES[@]/$DELETE}")
echo Ignore $fn
fi
done
if [ -n "$FILES" ]; then
$EXEC $ARGS $FILES
if [ $? != 0 ]; then
echo COMMIT FAILED!!!
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment