Skip to content

Instantly share code, notes, and snippets.

@petitJAM
Last active May 22, 2019 15:36
Show Gist options
  • Save petitJAM/7f3cb7de846cbe1878d1f8b2945e03e2 to your computer and use it in GitHub Desktop.
Save petitJAM/7f3cb7de846cbe1878d1f8b2945e03e2 to your computer and use it in GitHub Desktop.
Post-merge check for Rails things (migrations, gems, yarn packages)
#!/bin/bash
# https://gist.github.com/petitJAM/7f3cb7de846cbe1878d1f8b2945e03e2
DIFF=`git diff --name-only HEAD@{1} HEAD`
YARN=`expr "$DIFF" : ".*package\.json.*"`
MIGRATE=`expr "$DIFF" : ".*db/migrate.*"`
BUNDLE=`expr "$DIFF" : ".*Gemfile*"`
BLINK='\e[5m'
RED='\033[0;31m'
NC='\033[0m' # No Color
if [ ! "$BUNDLE" -eq 0 ] || [ ! "$MIGRATE" -eq 0 ] || [ ! "$YARN" -eq 0 ]
then
echo -e "${BLINK}Hey! Listen!"
fi
if [ ! "$BUNDLE" -eq 0 ]
then
echo -e "${RED}There are changes in the Gemfile! Run 'bundle install'${NC}"
fi
if [ ! "$MIGRATE" -eq 0 ]
then
echo -e "${RED}There are new migrations! Run 'rails db:migrate'${NC}"
fi
if [ ! "$YARN" -eq 0 ]
then
echo -e "${RED}There are new JavaScript dependencies! Run 'yarn install'${NC}"
fi
@petitJAM
Copy link
Author

This goes in .git/hooks/post-merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment