Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Pre-Commit Git Hook for SALT
#!/bin/bash
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}
docker-compose up -d web
echo "Checking PHP Lint..."
for FILE in $SFILES
do
docker-compose exec -T web php -l -d display_errors=0 $FILE
if [ $? -ne 0 ]; then
echo "Fix the error before commit."
exit 1
fi
FILES="$FILES $FILE"
done
if [ "X$FILES" != "X" ]; then
echo "Running PHP Code Beautifier..."
docker-compose exec -T web vendor/bin/phpcbf --report=full --encoding=utf-8 -n -p $FILES
echo "Running PHP Code Sniffer..."
docker-compose exec -T web vendor/bin/phpcs --report=full --encoding=utf-8 -n -p $FILES
if [ $? -ne 0 ]; then
echo "PHPCS: Errors Found Not Fixable Automatically"
exit 1
fi
git add $FILES
fi
exit $?
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment