Rewrite (and hopefully fix) doom//upgrade again

This commit is contained in:
Henrik Lissner 2018-05-26 23:25:06 +02:00
parent 41f4a31096
commit b5ec39f0ec
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -209,43 +209,50 @@ recompile. Run this whenever you:
;; ;;
;; FIXME Detect & enforce remote ;; FIXME Detect & enforce remote
(defvar doom-remote "origin" (defvar doom-repo-url "https://github.com/hlissner/doom-emacs"
"TODO")
(defvar doom-repo-remote "upgrade"
"TODO") "TODO")
(defun doom//upgrade () (defun doom//upgrade ()
"Upgrade Doom to the latest version." "Upgrade Doom to the latest version."
(interactive) (interactive)
(require 'vc-git) (require 'vc-git)
(let* ((core-file (expand-file-name "core.el" doom-core-dir)) (let* ((gitdir (expand-file-name ".git" doom-emacs-dir))
(branch (vc-git--symbolic-ref core-file)) (branch (vc-git--symbolic-ref doom-emacs-dir))
(default-directory doom-emacs-dir)) (default-directory doom-emacs-dir))
(unless (file-exists-p core-file) (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 core-file))) (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 %s a repo?"
(abbreviate-file-name doom-emacs-dir))) (abbreviate-file-name doom-emacs-dir)))
(unless (eq (vc-state core-file 'Git) 'up-to-date) (unless (eq (vc-state doom-emacs-dir 'Git) 'up-to-date)
(user-error "Doom has been modified; refusing to upgrade. 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)))
(when (zerop (process-file "git" nil buf nil (process-file "git" nil buf nil "remote" "remove" doom-repo-remote)
"fetch" "--tags" doom-remote branch)) (when (and (zerop (process-file "git" nil buf nil "remote" "add"
(let ((current-rev (vc-git-working-revision core-file)) doom-repo-remote doom-repo-url))
(rev (shell-command-to-string (format "git rev-parse %s/%s" doom-remote branch)))) (zerop (process-file "git" nil buf nil
"fetch" "--tags" doom-repo-remote branch)))
(let ((current-rev (vc-git-working-revision doom-emacs-dir))
(rev (string-trim (shell-command-to-string (format "git rev-parse %s/%s" doom-repo-remote branch)))))
(unless rev (unless rev
(error "Couldn't detect Doom's version. Is %s a repo?" (error "Couldn't detect Doom's version. Is %s a repo?"
(abbreviate-file-name doom-emacs-dir))) (abbreviate-file-name doom-emacs-dir)))
(if (equal current-rev rev) (if (equal current-rev rev)
(message "Doom is up to date!") (message "Doom is up to date!")
(when (or doom-auto-accept (message "Doom is out of date.\n\n Old rev: %s\n New rev: %s\n"
(y-or-n-p "Doom is out of date, update?")) current-rev rev)
(when (file-exists-p (byte-compile-dest-file core-file)) (if (not (or doom-auto-accept
(message "Your config is byte-compiled, removing byte-compiled files") (y-or-n-p "Proceed?")))
(doom//clean-byte-compiled-files)) (error "Aborted")
(unless (zerop (process-file "git" nil buf nil (message "Removing byte-compiled files from your config (if any)")
"checkout" (format "%s/%s" doom-remote branch))) (doom//clean-byte-compiled-files)
(error "An error occurred while checking out the latest commit")) (unless (zerop (process-file "git" nil buf nil "pull" "--rebase"))
(error "An error occurred while checking out the latest commit\n\n%s"
(buffer-string)))
(doom//reload) (doom//reload)
(message "Done! Please restart Emacs for changes to take effect"))))))))) (message "Done! Please restart Emacs for changes to take effect")))))))))