Skip to content

Instantly share code, notes, and snippets.

@bumi
Created June 4, 2013 14:55
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bumi/5706550 to your computer and use it in GitHub Desktop.
Save bumi/5706550 to your computer and use it in GitHub Desktop.
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