Skip to content

Instantly share code, notes, and snippets.

@dedico
Created May 30, 2012 12:07
Show Gist options
  • Save dedico/2835854 to your computer and use it in GitHub Desktop.
Save dedico/2835854 to your computer and use it in GitHub Desktop.
Git pre-commit hook to precompile assets if anything changed in app/assets or vendor/assets
#!/bin/bash
# source rvm and .rvmrc if present
[ -s "$HOME/.rvm/scripts/rvm" ] && . "$HOME/.rvm/scripts/rvm"
[ -s "$PWD/.rvmrc" ] && . "$PWD/.rvmrc"
should_precompile=0
# check if anything changed in app/assets
if git diff-index --name-only HEAD | egrep '^app/assets' >/dev/null ; then
should_precompile=1
fi
# check if anything changed in app/assets
if git diff-index --name-only HEAD | egrep '^vendor/assets' >/dev/null ; then
should_precompile=1
fi
# precompile assets if any have been updated
if [ $should_precompile -eq 1 ]; then
echo 'Precompiling assets...'
rake assets:precompile:all RAILS_ENV=production RAILS_GROUPS=assets
git add public/assets/*
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment