diff --git a/tools/upgrade.sh b/tools/upgrade.sh index d5e7e8ba8..e167b1813 100644 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -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 +