diff options
author | Tuowen Zhao <ztuowen@gmail.com> | 2021-09-27 13:03:58 -0600 |
---|---|---|
committer | Tuowen Zhao <ztuowen@gmail.com> | 2021-09-27 13:03:58 -0600 |
commit | c674485e6b4abe313469900997d893d2940ee843 (patch) | |
tree | d6ca6edaff3d81849489f31ca13b127acef89c75 /tools/upgrade.sh | |
parent | 3c73976ef306d68a85d60c94be9a1dcdc33fa2bf (diff) | |
parent | 93ad3a88214b95f571e03c21f7d9bd76f9110938 (diff) | |
download | zsh-c674485e6b4abe313469900997d893d2940ee843.tar.gz zsh-c674485e6b4abe313469900997d893d2940ee843.tar.bz2 zsh-c674485e6b4abe313469900997d893d2940ee843.zip |
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'tools/upgrade.sh')
-rwxr-xr-x | tools/upgrade.sh | 28 |
1 files changed, 24 insertions, 4 deletions
diff --git a/tools/upgrade.sh b/tools/upgrade.sh index e9f8bc0f9..1424d1433 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -1,16 +1,23 @@ #!/usr/bin/env zsh +# Protect against running with shells other than zsh if [ -z "$ZSH_VERSION" ]; then exec zsh "$0" "$@" fi +# Protect against unwanted sourcing +case "$ZSH_EVAL_CONTEXT" in + *:file) echo "error: this file should not be sourced" && return ;; +esac + cd "$ZSH" # Use colors, but only if connected to a terminal # and that terminal supports them. -local -a RAINBOW -local RED GREEN YELLOW BLUE BOLD DIM UNDER RESET +setopt typeset_silent +typeset -a RAINBOW +typeset RED GREEN YELLOW BLUE BOLD DIM UNDER RESET if [ -t 1 ]; then RAINBOW=( @@ -59,10 +66,20 @@ git config rebase.autoStash true local ret=0 +# repository settings +remote=${"$(git config --local oh-my-zsh.remote)":-origin} +branch=${"$(git config --local oh-my-zsh.branch)":-master} + +# repository state +last_head=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD) +# checkout update branch +git checkout -q "$branch" -- || exit 1 +# branch commit before update (used in changelog) +last_commit=$(git rev-parse "$branch") + # Update Oh My Zsh printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh" -last_commit=$(git rev-parse HEAD) -if git pull --rebase --stat origin master; then +if git pull --rebase --stat $remote $branch; then # Check if it was really updated or not if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then message="Oh My Zsh is already at the latest version." @@ -96,6 +113,9 @@ else printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?' fi +# go back to HEAD previous to update +git checkout -q "$last_head" -- + # Unset git-config values set just for the upgrade case "$resetAutoStash" in "") git config --unset rebase.autoStash ;; |