Created
March 27, 2019 20:57
-
-
Save andysnell/134947374a33b82e07b765b60b6d0d42 to your computer and use it in GitHub Desktop.
Pre-Commit Git Hook for SALT
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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