From 48322af02020eba6dd88e11819d330235d09deed Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Thu, 6 May 2021 04:17:06 -0400 Subject: [PATCH] doom upgrade: delete straight if recipe changed By deleting straight, the latest pinned version will be reinstalled on the second part of the 'doom upgrade' process. This is a clumsy fix for a catch 22 where using straight to update straight would break due to backwards incompatibilities (see #4950). This will do while we wait for the CLI rewrite. --- core/cli/upgrade.el | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/core/cli/upgrade.el b/core/cli/upgrade.el index 93c11f334..deab424b2 100644 --- a/core/cli/upgrade.el +++ b/core/cli/upgrade.el @@ -44,6 +44,16 @@ following shell commands: (split-string stdout "\n" t) (error "Failed to check working tree in %s" dir)))) +(defun doom--get-straight-recipe () + (with-temp-buffer + (insert-file-contents (doom-path doom-core-dir "packages.el")) + (when (re-search-forward "(package! straight" nil t) + (goto-char (match-beginning 0)) + (let ((sexp (sexp-at-point))) + (plist-put sexp :recipe + (eval (plist-get sexp :recipe) + t)))))) + (defun doom-cli-upgrade (&optional auto-accept-p force-p) "Upgrade Doom to the latest version non-destructively." @@ -116,9 +126,22 @@ following shell commands: (print! (start "Upgrading Doom Emacs...")) (print-group! (doom-clean-byte-compiled-files) - (or (and (zerop (car (doom-call-process "git" "reset" "--hard" target-remote))) - (equal (cdr (doom-call-process "git" "rev-parse" "HEAD")) new-rev)) - (error "Failed to check out %s" (substring new-rev 0 10))) + (let ((straight-recipe (doom--get-straight-recipe))) + (or (and (zerop (car (doom-call-process "git" "reset" "--hard" target-remote))) + (equal (cdr (doom-call-process "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--get-straight-recipe)) + (print! (info "Preparing straight for an update")) + (delete-directory (doom-path straight-base-dir "straight/repos/straight.el") + 'recursive))) (print! (info "%s") (cdr result)) t)))))) (ignore-errors