c262ffbb68e6dfc30b619e6ce6bdbd00f27b8a71

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

Message

fix(update): define `$ZSH` if undefined (#12273)

Fixes #12273
Fixes https://github.com/topgrade-rs/topgrade/issues/519

Diff

 1diff --git a/tools/upgrade.sh b/tools/upgrade.sh
 2index d7016aa449ccf1fe06bcc70306cda3879d1f7c92..5eb90ab41579a99942948a7041091d601ff9b89f 100755
 3--- a/tools/upgrade.sh
 4+++ b/tools/upgrade.sh
 5@@ -10,9 +10,14 @@ fi
 6 
 7 # Protect against unwanted sourcing
 8 case "$ZSH_EVAL_CONTEXT" in
 9-  *:file) echo "error: this file should not be sourced" && return ;;
10+  *:file) echo "error: this file should not be sourced" && return 1 ;;
11 esac
12 
13+# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script
14+if [[ -z "$ZSH" ]]; then
15+  ZSH="${0:a:h:h}"
16+fi
17+
18 cd "$ZSH"
19 
20 verbose_mode="default"