fix(cli): more future resistant 'doom upgrade'

In the future, should doom-core-dir or {doom-core-dir}/packages.el
change, 'doom upgrade' won't leave the repo in a broken state.
Unfortunately, this cannot retroactively prevent the issue; users will
experience this as soon as they update to b9933e6 or beyond, so users
will have to upgrade manually to overcome it:

  cd ~/.emacs.d
  git reset --hard 35a89bdfa6
  git pull origin master
  doom sync -u

Fix: #6598
Amend: b9933e6637
This commit is contained in:
Henrik Lissner 2022-07-31 00:43:15 +02:00
parent 29dc2fed29
commit 615848e3a7
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -36,10 +36,21 @@ following shell commands:
(sync-cmd (append '("sync" "-u") (if jobs `("-j" ,num)))))
(cond
(packages?
;; HACK It's messy to use straight to upgrade straight, due to the
;; potential for backwards incompatibility, so we staticly check if
;; Doom's `package!' declaration for straight has changed. If it has,
;; delete straight so 'doom sync' will install the new version for us.
;;
;; Clumsy, but a better solution is in the works.
(let ((recipe (doom-cli-context-get context 'straight-recipe)))
(when (and recipe (not (equal recipe (doom-upgrade--get-straight-recipe))))
(print! (item "Preparing straight for an update"))
(delete-directory (doom-path straight-base-dir "straight/repos/straight.el")
'recursive)))
(call! sync-cmd)
(print! (success "Finished upgrading Doom Emacs")))
((doom-cli-upgrade force? force?)
((doom-cli-upgrade context force? force?)
;; Reload Doom's CLI & libraries, in case there were any upstream changes.
;; Major changes will still break, however
(print! (item "Reloading Doom Emacs"))
@ -54,7 +65,7 @@ following shell commands:
;;
;;; Helpers
(defun doom-cli-upgrade (&optional auto-accept-p force-p)
(defun doom-cli-upgrade (context &optional auto-accept-p force-p)
"Upgrade Doom to the latest version non-destructively."
(let ((default-directory doom-emacs-dir)
process-file-side-effects)
@ -126,24 +137,10 @@ following shell commands:
(print! (start "Upgrading Doom Emacs..."))
(print-group!
(doom-compile-clean)
(let ((straight-recipe (doom-upgrade--get-straight-recipe)))
(or (and (zerop (car (sh! "git" "reset" "--hard" target-remote)))
(equal (cdr (sh! "git" "rev-parse" "HEAD")) new-rev))
(error "Failed to check out %s" (substring new-rev 0 10)))
;; HACK It's messy to use straight to upgrade straight, due
;; to the potential for backwards incompatibility, so we
;; staticly check if Doom's `package!' declaration for
;; straight has changed. If it has, delete straight so
;; 'doom upgrade's second stage will install the new
;; version for us.
;;
;; Clumsy, but a better solution is in the works.
(unless (equal straight-recipe (doom-upgrade--get-straight-recipe))
(print! (item "Preparing straight for an update"))
(delete-directory (doom-path straight-base-dir "straight/repos/straight.el")
'recursive)))
(print! (item "%s") (cdr result))
t))))))
(doom-cli-context-put context 'straight-recipe (doom-upgrade--get-straight-recipe))
(or (and (zerop (car (sh! "git" "reset" "--hard" target-remote)))
(equal (cdr (sh! "git" "rev-parse" "HEAD")) new-rev))
(error "Failed to check out %s" (substring new-rev 0 10)))))))))
(ignore-errors
(sh! "git" "branch" "-D" target-remote)
(sh! "git" "remote" "remove" doom-upgrade-remote))))))