Skip to content

Instantly share code, notes, and snippets.

@ches
Created February 7, 2011 13:17
Show Gist options
  • Save ches/814335 to your computer and use it in GitHub Desktop.
Save ches/814335 to your computer and use it in GitHub Desktop.
post-checkout git hook to intelligently run `bundle` if Gemfile was changed
#!/bin/sh
# Via http://tbaggery.com/2011/02/07/bundle-while-you-git.html
# Save as http://.git/hooks/post-checkout in your project and `chmod +x`
# See the post for how to tell Git you want this in new/newly cloned repos
if [ $1 = 0000000000000000000000000000000000000000 ]; then
# Special case for initial clone: compare to empty directory.
old=4b825dc642cb6eb9a060e54bf8d69288fbee4904
else
old=$1
fi
if [ -f Gemfile ] && command -v bundle >/dev/null &&
git diff --name-only $old $2 | egrep -q '^Gemfile|\.gemspec$'
then
(unset GIT_DIR; exec bundle) | grep -v '^Using ' | grep -v ' is complete'
true
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment