Last active
May 8, 2020 14:17
-
-
Save mattslack/dfc3a61b01ac24becf8a0cf595394159 to your computer and use it in GitHub Desktop.
Checkout a branch, update gems, run migrations, and prune merged branches
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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