85c49414926ad86f76d7bad3635f948bb5f883cb

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

Message

fix(cli)!: remove harmful `--unattended` flag for `omz update` (#12935)

Co-authored-by: Carlo Sala <carlosalag@protonmail.com>

Diff

 1diff --git a/README.md b/README.md
 2index 58828cf7f679c521012e5c7506157cc52767916b..f7455228ad69f7cb24c65d98d42c1ae5296e779e 100644
 3--- a/README.md
 4+++ b/README.md
 5@@ -487,6 +487,17 @@ wait a week?) you just need to run:
 6 omz update
 7 ```
 8 
 9+> [!NOTE]
10+> If you want to automate this process in a script, you should call directly the `upgrade` script, like this:
11+>
12+> ```sh
13+> $ZSH/tools/upgrade.sh
14+> ```
15+>
16+> See more options in the [FAQ: How do I update Oh My Zsh?](https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#how-do-i-update-oh-my-zsh).
17+>
18+> **USE OF `omz update --unattended` HAS BEEN REMOVED, AS IT HAS SIDE EFFECTS**.
19+
20 Magic! 🎉
21 
22 ## Uninstalling Oh My Zsh
23diff --git a/lib/cli.zsh b/lib/cli.zsh
24index c63185a3d25e115b3565e0ea51464c177a01246e..aed86e75815b4f750499d32fe247eba25802c8fb 100644
25--- a/lib/cli.zsh
26+++ b/lib/cli.zsh
27@@ -823,6 +823,13 @@ function _omz::update {
28     return 1
29   }
30 
31+  # Check if --unattended was passed
32+  [[ "$1" != --unattended ]] || {
33+    _omz::log error "the \`\e[2m--unattended\e[0m\` flag is no longer supported, use the \`\e[2mupgrade.sh\e[0m\` script instead."
34+    _omz::log error "for more information see https://github.com/ohmyzsh/ohmyzsh/wiki/FAQ#how-do-i-update-oh-my-zsh"
35+    return 1
36+  }
37+
38   local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD 2>/dev/null)
39   [[ $? -eq 0 ]] || {
40     _omz::log error "\`$ZSH\` is not a git directory. Aborting..."
41@@ -831,11 +838,7 @@ function _omz::update {
42 
43   # Run update script
44   zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default
45-  if [[ "$1" != --unattended ]]; then
46-    ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $?
47-  else
48-    ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -v $verbose_mode || return $?
49-  fi
50+  ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode || return $?
51 
52   # Update last updated file
53   zmodload zsh/datetime
54@@ -844,7 +847,7 @@ function _omz::update {
55   command rm -rf "$ZSH/log/update.lock"
56 
57   # Restart the zsh session if there were changes
58-  if [[ "$1" != --unattended && "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
59+  if [[ "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
60     # Old zsh versions don't have ZSH_ARGZERO
61     local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
62     # Check whether to run a login shell