Skip to content

Instantly share code, notes, and snippets.

@avdgaag
Created March 19, 2013 19:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdgaag/5199350 to your computer and use it in GitHub Desktop.
Save avdgaag/5199350 to your computer and use it in GitHub Desktop.
Git post-checkout hook that automatically updates your bundled gems (if applicable), re-generates your tags index using exuberant ctags, and tries to advise you about pending migrations.
#!/bin/sh
set -e
OLDREV=$1
NEWREV=$2
IS_BRANCH_CHECKOUT=$3
function has_changes_to() {
git diff --name-only "$OLDREV" "$NEWREV" -- "$1" | grep "$1" > /dev/null
}
if [ -e Gemfile ]; then
echo '--> Checking Gem dependencies'
has_changes_to Gemfile || bundle check > /dev/null || (
echo ' Running bundle install'
bundle install | grep 'Installing '
)
fi
echo '--> Updating tags'
if [ -e Gemfile ]; then
echo ' Generating tags from bundled Gems'
bundle show --paths | xargs ctags -R 2>/dev/null
echo ' Generating project tags'
fi
/usr/local/bin/ctags -a --extra=+f --exclude=.git --exclude=log --exclude=tmp -R * 2>/dev/null
if [ -e db/schema.rb ]; then
echo '--> Checking for schema changes'
has_changes_to db/migrate || echo ' You have pending migrations. Run `rake db:migrate` to update your database.'
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment