Skip to content

Instantly share code, notes, and snippets.

@akiya64
Created November 5, 2017 03:56
Show Gist options
  • Select an option

  • Save akiya64/7618698356a7938daefa1843608e8868 to your computer and use it in GitHub Desktop.

Select an option

Save akiya64/7618698356a7938daefa1843608e8868 to your computer and use it in GitHub Desktop.
Auto fix php/css codingstyle for WordPressCoding at pre-commit
#!/bin/sh
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
# Redirect output to stderr.
exec 1>&2
IS_ERROR=0
# Staging files end with .css or .php
FILES=` git status --short | grep -E "^[M|A].*(.css|.php)$" | cut -c4-`
for FILE in $FILES
do
./phpcs/bin/phpcbf --standard=wordpress $FILE
if ! ./phpcs/bin/phpcs --standard=wordpress $FILE ; then
./phpcs/bin/phpcs --standard=wordpress $FILE
IS_ERROR=1
else
git add $FILE
fi
done
exit $IS_ERROR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment