Skip to content

Instantly share code, notes, and snippets.

@tamsanh
Created January 20, 2016 11:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tamsanh/783a62adeba81ba47999 to your computer and use it in GitHub Desktop.
Save tamsanh/783a62adeba81ba47999 to your computer and use it in GitHub Desktop.
Don't run if git is dirty
ITERATING=0
MASTER_ONLY=0
if [ $ITERATING -ne 1 ]
then
git diff-index --quiet HEAD
if [ $? -ne 0 ]
then
echo "!!! There are untracked changes. You must commit before running this script."
echo "Will not allow running until you resolve the following files:"
echo
git diff-index HEAD
echo
echo "To commit these files, use the following command:"
echo "git commit -m \"<Reason why you're committing>\" -a"
echo
exit 1
fi
if [[ "`git rev-parse --abbrev-ref HEAD`" != "master" && $MASTER_ONLY -eq 1 ]]
then
echo "!!! You are not on the master branch. You cannot run this cript unless you are on master"
echo "To get to the master branch, use the following command:"
echo "git checkout master"
echo
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment