Last active
December 14, 2015 11:50
-
-
Save oziks/5082303 to your computer and use it in GitHub Desktop.
pre-commit hook (atoum - propel migration - PHP CS)
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 | |
#pre-commit | |
function abort() { | |
echo -e "\n\terror: Commit abort" | |
echo -e "\t$1" | |
exit 1 | |
} | |
echo $(tput bold)$(tput setaf 5)"Running pre-commit hook..."$(tput sgr0) | |
VALID=$(git st --porcelain | sed "s/^[MADRCU][MADRCU]/c2is/" | grep "^c2is" | wc -l) | |
[ $VALID -ne 0 ] && abort "At least one file appears in both your staging area and in your files not added." | |
git stash -u --keep-index | |
echo "Running propel migration check" | |
SCHEMA=$(git st --porcelain | sed "s/app\/config\/Propel\/schema.xml/c2is/" | grep c2is | wc -l) | |
MIGRAT=$(git st --porcelain | sed "s/app\/resources\/migrations\//c2is/" | grep c2is | wc -l) | |
[ $SCHEMA -eq 1 ] && [ $MIGRAT -eq 0 ] && abort "Propel migration script not found. Please execute propel-gen diff" | |
echo "Running atoum..." | |
./console tests:units | |
ATOUM=$? | |
echo "Running PHP_CodeSniffer..." | |
./console tests:sniff --modified-files | |
PHPCS=$? | |
git stash pop -q --index | |
# [ $ATOUM -eq 0 ] && abort | |
[ $PHPCS -eq 1 ] && abort "PHP_CodeSniffer failed." | |
# All tests pass | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment