prompt user if repo has changes before upgrading

This commit is contained in:
James Pullar 2016-01-06 21:57:25 -08:00
commit d1f769b147

View file

@ -20,10 +20,7 @@ else
NORMAL=""
fi
printf "${BLUE}%s${NORMAL}\n" "Updating Oh My Zsh"
cd "$ZSH"
if git pull --rebase --stat origin master
then
success_upgrading() {
printf '%s' "$GREEN"
printf '%s\n' ' __ __ '
printf '%s\n' ' ____ / /_ ____ ___ __ __ ____ _____/ /_ '
@ -34,6 +31,38 @@ then
printf "${BLUE}%s\n" "Hooray! Oh My Zsh has been updated and/or is at the current version."
printf "${BLUE}${BOLD}%s${NORMAL}\n" "To keep up on the latest news and updates, follow us on twitter: https://twitter.com/ohmyzsh"
printf "${BLUE}${BOLD}%s${NORMAL}\n" "Get your Oh My Zsh swag at: http://shop.planetargon.com/"
else
exit 0
}
error_upgrading() {
printf "${RED}%s${NORMAL}\n" 'There was an error updating. Try again later?'
exit 1
}
run_upgrade() {
if git pull --rebase --stat origin master
then
success_updating
else
error_updating
fi
}
printf "${BLUE}%s${NORMAL}\n" "Updating Oh My Zsh"
cd "$ZSH"
if output=$(git status --porcelain); then
while true; do
printf "${RED}%s${NORMAL}\n" "You have changes that are preventing Oh My Zsh from upgrading."
printf "${RED}%s${NORMAL}" "Do you want to stash these changes and continue? "
read -p "" answer
case $answer in
[Yy]* ) git stash; run_update;;
[Nn]* ) exit;;
* ) echo "Please answer yes or no.";;
esac
done
else
run_update
fi