Symfony2 Checks For Composer and Database

A friend of mine @markbadolato got me into using this git post-checkout hook:

https://gist.github.com/mbadolato/5869968
update: he also made a blog post with more explanations.

#!/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'
 
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 app/console ]]; then
    php app/console doctrine:schema:update --dump-sql
fi

Mind you need to do it as a post-checkout hook.

I added the doctrine part so that it also tells you if you need to run migrations or update the schema.

All credits to its author. I only added the last part. And I adapted it from @markbadolato polished version.

Enjoy and visit us also at the shop if you want to thank for sharing http://pilotci.com!

Leave a Reply

Your email address will not be published. Required fields are marked *