Last active
December 30, 2015 12:09
-
-
Save rommsen/7826867 to your computer and use it in GitHub Desktop.
Symfony2 post-checkout hook
includes check for composer.lock, bower.json and possible entity paths
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 | |
# put this file at: .git/hooks/post-checkout | |
# and make it executable | |
# You can install it system wide too, see http://stackoverflow.com/a/2293578/685587 | |
PREV_COMMIT=$1 | |
POST_COMMIT=$2 | |
NOCOLOR='\x1B[0m' | |
REDCOLOR='\x1B[37;41m' | |
# assigns standard input to the keyboard | |
exec < /dev/tty | |
ENTITYDIR="src/Ipark/ApplicationBundle/Model/Entities src/Ipark/FrameworkBundle/Model/Entities" | |
if [[ -f composer.lock ]]; then | |
DIFF=`git diff --shortstat $PREV_COMMIT..$POST_COMMIT composer.lock` | |
if [[ $DIFF != "" ]]; then | |
echo -e "$REDCOLOR composer.lock has changed. You must run composer install$NOCOLOR" | |
fi | |
fi | |
if [[ -f bower.json ]]; then | |
DIFF=`git diff --shortstat $PREV_COMMIT..$POST_COMMIT bower.json` | |
if [[ $DIFF != "" ]]; then | |
echo -e "$REDCOLOR bower.json has changed. You must run bower update$NOCOLOR" | |
fi | |
fi | |
if [[ -f app/console ]]; then | |
DIFF=`git diff --shortstat $PREV_COMMIT..$POST_COMMIT $ENTITYDIR` | |
if [[ $DIFF != "" ]]; then | |
while true; do | |
read -p "Entities seem to have changed, run schema:update? [(f)orce|(d)ump|(N)o]" yn | |
if [ "$yn" = "" ]; then | |
yn='n' | |
fi | |
case $yn in | |
[Ff] ) php app/console doctrine:schema:update --force; break;; | |
[Dd] ) php app/console doctrine:schema:update --dump-sql; break;; | |
[Nn] ) exit;; | |
* ) echo "Please answer f for force, d for dump or n for no.";; | |
esac | |
done | |
fi | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment