Skip to content

Instantly share code, notes, and snippets.

@mattslack
Last active May 8, 2020 14:17
Show Gist options
  • Save mattslack/dfc3a61b01ac24becf8a0cf595394159 to your computer and use it in GitHub Desktop.
Save mattslack/dfc3a61b01ac24becf8a0cf595394159 to your computer and use it in GitHub Desktop.
Checkout a branch, update gems, run migrations, and prune merged branches
#!/bin/sh
BRANCH="master"
ROOT=`git rev-parse --show-toplevel`
[[ 0 < $# ]] && BRANCH=$1
[[ `git status -b -s --porcelain | egrep '^\#\# ($BRANCH)'` ]] || git checkout ${BRANCH} && {
(git pull origin ${BRANCH} || git pull --rebase origin ${branch} ) &&
git fetch -a &&
git branch --merged | grep --color -v "\*" | xargs -n 1 git branch -d &&
git remote prune origin && {
echo "Clearing logs… \c"
for LOGFILE in `find ${ROOT}/log -name "*.log"`; do
cat /dev/null > ${LOGFILE}
done
echo "done."
} &&
[[ -e ${ROOT}/Gemfile ]] &&
[[ -x `command -v bundle` ]] && {
echo "Checking gems…"
bundle check || bundle
echo "Done checking gems"
}
[[ -e ${ROOT}/Rakefile ]] && {
if [ `bundle exec rake db:migrate:status | egrep "^(\s)*down" | wc -l` -gt 0 ]
then
echo "Running migrations…"
bundle exec rake db:migrate
bundle exec rake db:migrate RAILS_ENV=test
fi
echo "Migrations are up to date."
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment