Skip to content

Instantly share code, notes, and snippets.

@whyisjake
Created May 27, 2016 15:04
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 whyisjake/bcc83c2a97fc7348f5697d281d26699e to your computer and use it in GitHub Desktop.
Save whyisjake/bcc83c2a97fc7348f5697d281d26699e to your computer and use it in GitHub Desktop.
#!/bin/sh
PATH="/usr/local/bin:$PATH"
git diff --quiet --cached -- submodules/ || {
echo "$(tput setaf 1) ABORT: Submodules change detected. Please verify your submodules are correct and try again. \n"; exit 1;
}
# is VERBOTEN ( ie, protect us from ourselves )
find ./wp-content/themes/Phoenix/ -type f -name "*.php" -o -name "*.styl" -o -name "*.js" | \
xargs egrep -i '(^<<<<<<<\s)|(^>>>>>>>\s)|(^=======$)'
if [ $? -eq 0 ]; then
echo "$(tput setaf 1) ABORT: Unresolved merge conflicts found in this branch. Please fix and try again. \n"; exit 1;
fi
# no crazy terrible errors? lint the code
gulp jshint || { echo "$(tput setaf 1) ABORT: jShint has found syntax errors with this commit. Please fix jshint errors and try again. \n"; exit 1; }
gulp jscs || { echo "$(tput setaf 1) ABORT: jscs has found style issues with this commit. Please fix style issues and commit again. \n"; exit 1; }
gulp phplint || { echo "$(tput setaf 1) ABORT: phplint has found syntax errors with this commit. Please fix phplint errors and try again. \n"; exit 1; }
gulp stylint || { echo "$(tput setaf 1) ABORT: stylint has found syntax errors with this commit. Please fix stylint errors and try again. \n"; exit 1; }
PROJECT=`php -r "echo dirname(dirname(dirname(realpath('$0'))));"`
STAGED_FILES_CMD=`git diff --cached --name-only --diff-filter=ACMR HEAD | grep \\\\.php`
# Determine if a file list is passed
if [ "$#" -eq 1 ]
then
oIFS=$IFS
IFS='
'
SFILES="$1"
IFS=$oIFS
fi
SFILES=${SFILES:-$STAGED_FILES_CMD}
echo "Checking PHP Lint..."
for FILE in $SFILES
do
php -l -d display_errors=0 $PROJECT/$FILE
if [ $? != 0 ]
then
echo "Fix the error before commit."
exit 1
fi
FILES="$FILES $PROJECT/$FILE"
done
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment