098bcda6910aa2f734fb0ad59ac089157a239c87

Author
Marc Cornellà <hello@mcornella.com>
Committer
Marc Cornellà <hello@mcornella.com>
Date

Message

feat(update): allow updating from branch set up on install

Closes #8788

Co-authored-by: Nikolas Garofil <nikolas@garofil.be>

Diff

  1diff --git a/tools/install.sh b/tools/install.sh
  2index cfc2808fe93b5dd3f3f6fd89947bc875d1e74f8d..510f83ce84b4d1d804ae7d335862498207fbb93c 100755
  3--- a/tools/install.sh
  4+++ b/tools/install.sh
  5@@ -53,7 +53,7 @@ KEEP_ZSHRC=${KEEP_ZSHRC:-no}
  6 
  7 
  8 command_exists() {
  9-	command -v "$@" >/dev/null 2>&1
 10+  command -v "$@" >/dev/null 2>&1
 11 }
 12 
 13 fmt_error() {
 14@@ -65,27 +65,27 @@ fmt_underline() {
 15 }
 16 
 17 fmt_code() {
 18-  # shellcheck disable=SC2016 # backtic in single-quote
 19+  # shellcheck disable=SC2016 # backtick in single-quote
 20   printf '`\033[38;5;247m%s%s`\n' "$*" "$RESET"
 21 }
 22 
 23 setup_color() {
 24-	# Only use colors if connected to a terminal
 25-	if [ -t 1 ]; then
 26-		RED=$(printf '\033[31m')
 27-		GREEN=$(printf '\033[32m')
 28-		YELLOW=$(printf '\033[33m')
 29-		BLUE=$(printf '\033[34m')
 30-		BOLD=$(printf '\033[1m')
 31-		RESET=$(printf '\033[m')
 32-	else
 33-		RED=""
 34-		GREEN=""
 35-		YELLOW=""
 36-		BLUE=""
 37-		BOLD=""
 38-		RESET=""
 39-	fi
 40+  # Only use colors if connected to a terminal
 41+  if [ -t 1 ]; then
 42+    RED=$(printf '\033[31m')
 43+    GREEN=$(printf '\033[32m')
 44+    YELLOW=$(printf '\033[33m')
 45+    BLUE=$(printf '\033[34m')
 46+    BOLD=$(printf '\033[1m')
 47+    RESET=$(printf '\033[m')
 48+  else
 49+    RED=""
 50+    GREEN=""
 51+    YELLOW=""
 52+    BLUE=""
 53+    BOLD=""
 54+    RESET=""
 55+  fi
 56 }
 57 
 58 setup_ohmyzsh() {
 59@@ -114,6 +114,8 @@ setup_ohmyzsh() {
 60     -c fsck.zeroPaddedFilemode=ignore \
 61     -c fetch.fsck.zeroPaddedFilemode=ignore \
 62     -c receive.fsck.zeroPaddedFilemode=ignore \
 63+    -c oh-my-zsh.remote=origin \
 64+    -c oh-my-zsh.branch="$BRANCH" \
 65     --depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
 66     fmt_error "git clone of oh-my-zsh repo failed"
 67     exit 1
 68@@ -157,9 +159,9 @@ setup_zshrc() {
 69   sed "/^export ZSH=/ c\\
 70 export ZSH=\"$ZSH\"
 71 " "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
 72-	mv -f ~/.zshrc-omztemp ~/.zshrc
 73+  mv -f ~/.zshrc-omztemp ~/.zshrc
 74 
 75-	echo
 76+  echo
 77 }
 78 
 79 setup_shell() {
 80diff --git a/tools/upgrade.sh b/tools/upgrade.sh
 81index 7dec398fd6f8f93638c7796753bd32b6257e7ec0..1424d1433bd576cce15b4f6a50777a695b964c76 100755
 82--- a/tools/upgrade.sh
 83+++ b/tools/upgrade.sh
 84@@ -66,10 +66,20 @@ git config rebase.autoStash true
 85 
 86 local ret=0
 87 
 88+# repository settings
 89+remote=${"$(git config --local oh-my-zsh.remote)":-origin}
 90+branch=${"$(git config --local oh-my-zsh.branch)":-master}
 91+
 92+# repository state
 93+last_head=$(git symbolic-ref --quiet --short HEAD || git rev-parse HEAD)
 94+# checkout update branch
 95+git checkout -q "$branch" -- || exit 1
 96+# branch commit before update (used in changelog)
 97+last_commit=$(git rev-parse "$branch")
 98+
 99 # Update Oh My Zsh
100 printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
101-last_commit=$(git rev-parse HEAD)
102-if git pull --rebase --stat origin master; then
103+if git pull --rebase --stat $remote $branch; then
104   # Check if it was really updated or not
105   if [[ "$(git rev-parse HEAD)" = "$last_commit" ]]; then
106     message="Oh My Zsh is already at the latest version."
107@@ -103,6 +113,9 @@ else
108   printf "${RED}%s${RESET}\n" 'There was an error updating. Try again later?'
109 fi
110 
111+# go back to HEAD previous to update
112+git checkout -q "$last_head" --
113+
114 # Unset git-config values set just for the upgrade
115 case "$resetAutoStash" in
116   "") git config --unset rebase.autoStash ;;