Skip to content

Instantly share code, notes, and snippets.

@bumi

bumi/post-merge

Created Jun 4, 2013
Embed
What would you like to do?
post-merge hook to automatically run bundle install and rake db:migrate if needed
#!/bin/sh
# INSTALL
#
# make sure you have installed lolcat and cowsay
# brew install cowsay
# gem install lolcat
#
# filename: post-merge
#
# Install as a global post-merge hook for every NEW git repository
# save it as git hook template in your share/git-core/templates/hooks (for example: /usr/local/Cellar/git/1.8.2.2/share/git-core/templates/hooks/)
#
# Or in your local git repository in $GIT_DIR/hooks/*
#
#
diff=`git diff --name-only HEAD@{2} HEAD`
migrate=`expr "$diff" : ".*db/migrate.*"`
bundle=`expr "$diff" : ".*Gemfile*"`
if [ ! "$bundle" -eq 0 ]
then
echo "Ui, detected a Gemfile change, let's run bundle install"
bundle install
fi
if [ ! "$migrate" -eq 0 ]
then
echo "Oh, we need to migrate, let's run rake db:migrate"
bundle exec rake db:migrate
fi
if [ -d "tmp" ]
then
touch 'tmp/restart.txt'
fi
echo ""
echo "`whoami`, have a great day and happy coding" | cowsay | lolcat
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.