1
0
mirror of https://github.com/ohmyzsh/ohmyzsh.git synced 2026-10-23 04:53:45 +08:00

fix(updater): restore state on interrupt

Co-authored-by: mcornella <1441704+mcornella@users.noreply.github.com>
This commit is contained in:
copilot-swe-agent[bot]
2026-10-21 17:56:58 +00:00
committed by GitHub
parent 657ef5744d
commit a77431ce82

View File

@@ -238,7 +238,7 @@ print_banner() {
fi
setopt localtraps
trap 'printf "\033[?25h"; exit 130' INT
trap '_omz_upgrade_cleanup; printf "\033[?25h"; exit 130' INT
printf '\033[?25l'
for (( col = step; ; col += step )); do
(( col > width )) && col=width
@@ -319,6 +319,17 @@ git checkout -q "$branch" -- || exit 1
# branch commit before update (used in changelog)
last_commit=$(git rev-parse "$branch")
_omz_upgrade_cleanup() {
# 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 ;;
*) git config rebase.autoStash "$resetAutoStash" ;;
esac
}
# Update Oh My Zsh
if [[ $verbose_mode != silent ]]; then
printf "${BLUE}%s${RESET}\n" "Updating Oh My Zsh"
@@ -374,14 +385,7 @@ 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 ;;
*) git config rebase.autoStash "$resetAutoStash" ;;
esac
_omz_upgrade_cleanup
# Exit with `1` if the update failed
exit $ret