mirror of
https://github.com/doomemacs/doomemacs
synced 2025-08-03 12:27:26 -05:00
Refactor doom//upgrade
This commit is contained in:
@ -229,49 +229,58 @@ problems with doom."
|
|||||||
(doom//byte-compile nil 'recompile)))
|
(doom//byte-compile nil 'recompile)))
|
||||||
|
|
||||||
(defun doom//upgrade ()
|
(defun doom//upgrade ()
|
||||||
"Upgrade Doom to the latest version."
|
"Upgrade Doom to the latest version non-destructively."
|
||||||
(interactive)
|
(interactive)
|
||||||
(require 'vc-git)
|
(require 'vc-git)
|
||||||
(let* ((gitdir (expand-file-name ".git" doom-emacs-dir))
|
(let* ((gitdir (expand-file-name ".git" doom-emacs-dir))
|
||||||
(branch (vc-git--symbolic-ref doom-emacs-dir))
|
(branch (vc-git--symbolic-ref doom-emacs-dir))
|
||||||
(default-directory doom-emacs-dir))
|
(default-directory doom-emacs-dir))
|
||||||
(unless (file-exists-p gitdir)
|
(unless (file-exists-p gitdir)
|
||||||
(error "Couldn't find %s, was Doom cloned properly?"
|
(error "Couldn't find %s. Was Doom cloned properly?"
|
||||||
(abbreviate-file-name gitdir)))
|
(abbreviate-file-name gitdir)))
|
||||||
(unless branch
|
(unless branch
|
||||||
(error "Couldn't detect what branch you're using. Is %s a repo?"
|
(error "Couldn't detect what branch you're using. Is Doom detached?"
|
||||||
(abbreviate-file-name doom-emacs-dir)))
|
(abbreviate-file-name doom-emacs-dir)))
|
||||||
(when (doom--working-tree-dirty-p doom-emacs-dir)
|
(when (doom--working-tree-dirty-p doom-emacs-dir)
|
||||||
(user-error "Refusing to upgrade because Doom has been modified. Stash or undo your changes"))
|
(user-error "Refusing to upgrade because Doom has been modified. Stash or undo your changes"))
|
||||||
(with-temp-buffer
|
(with-temp-buffer
|
||||||
(let ((buf (current-buffer)))
|
(let ((buf (current-buffer)))
|
||||||
(process-file "git" nil buf nil "remote" "remove" doom-repo-remote)
|
(condition-case e
|
||||||
(when (and (zerop (process-file "git" nil buf nil "remote" "add"
|
(progn
|
||||||
doom-repo-remote doom-repo-url))
|
(process-file "git" nil buf nil "remote" "remove" doom-repo-remote)
|
||||||
(zerop (process-file "git" nil buf nil
|
(unless (zerop (process-file "git" nil buf nil "remote" "add"
|
||||||
"fetch" "--tags" doom-repo-remote branch)))
|
doom-repo-remote doom-repo-url))
|
||||||
(let ((current-rev (vc-git-working-revision doom-emacs-dir))
|
(error "Failed to add %s to remotes" doom-repo-remote))
|
||||||
(rev (string-trim (shell-command-to-string (format "git rev-parse %s/%s" doom-repo-remote branch)))))
|
(unless (zerop (process-file "git" nil buf nil "fetch" "--tags"
|
||||||
(unless rev
|
doom-repo-remote branch))
|
||||||
(error "Couldn't detect Doom's version. Is %s a repo?"
|
(error "Failed to fetch from upstream"))
|
||||||
(abbreviate-file-name doom-emacs-dir)))
|
(when
|
||||||
(if (equal current-rev rev)
|
(let ((current-rev (vc-git-working-revision doom-emacs-dir))
|
||||||
(message "Doom is up to date!")
|
(rev (string-trim (shell-command-to-string (format "git rev-parse %s/%s" doom-repo-remote branch)))))
|
||||||
(message "Doom is out of date.\n\n Old rev: %s\n New rev: %s\n"
|
(unless rev
|
||||||
current-rev rev)
|
(error "Couldn't detect Doom's version. Is %s a repo?"
|
||||||
(if (not (or doom-auto-accept
|
(abbreviate-file-name doom-emacs-dir)))
|
||||||
(y-or-n-p "Proceed?")))
|
(unless (equal current-rev rev)
|
||||||
(error "Aborted")
|
(user-error "Doom is up to date!"))
|
||||||
(message "Removing byte-compiled files from your config (if any)")
|
(message "Updates for Doom are available!\n\n Old revision: %s\n New revision: %s\n"
|
||||||
(doom//clean-byte-compiled-files)
|
current-rev rev)
|
||||||
(unless (zerop (process-file "git" nil buf nil "reset" "--hard"
|
;; TODO Display newsletter diff
|
||||||
(format "%s/%s" doom-repo-remote branch)))
|
(unless (or doom-auto-accept (y-or-n-p "Proceed?"))
|
||||||
(error "An error occurred while checking out the latest commit\n\n%s"
|
(error "Aborted"))
|
||||||
(buffer-string)))
|
(message "Removing byte-compiled files from your config (if any)")
|
||||||
(unless (equal (vc-git-working-revision doom-emacs-dir) rev)
|
(doom//clean-byte-compiled-files)
|
||||||
(error "Failed to checkout latest commit.\n\n%s" (buffer-string)))
|
(unless (zerop (process-file "git" nil buf nil "reset" "--hard"
|
||||||
(doom//refresh)
|
(format "%s/%s" doom-repo-remote branch)))
|
||||||
(message "Done! Please restart Emacs for changes to take effect")))))))))
|
(error "An error occurred while checking out the latest commit\n\n%s"
|
||||||
|
(buffer-string)))
|
||||||
|
(unless (equal (vc-git-working-revision doom-emacs-dir) rev)
|
||||||
|
(error "Failed to checkout latest commit.\n\n%s" (buffer-string)))
|
||||||
|
(doom//refresh)
|
||||||
|
(message "Done! Please restart Emacs for changes to take effect"))))
|
||||||
|
(error
|
||||||
|
(message "There was an unexpected error.\n\n%s -> %s\n\nOutput:\n%s"
|
||||||
|
(car e) (error-message-string e)
|
||||||
|
(buffer-string))))))))
|
||||||
|
|
||||||
(defun doom//quickstart ()
|
(defun doom//quickstart ()
|
||||||
"Quickly deploy a private module and Doom.
|
"Quickly deploy a private module and Doom.
|
||||||
|
Reference in New Issue
Block a user