Skip to content

Instantly share code, notes, and snippets.

@bdmac
Forked from dedico/pre-commit
Last active August 29, 2015 14:12
Show Gist options
  • Save bdmac/e8097c41420570417ef4 to your computer and use it in GitHub Desktop.
Save bdmac/e8097c41420570417ef4 to your computer and use it in GitHub Desktop.
#!/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 vendor/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...'
bundle exec 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