2018-09-07 21:49:49 -04:00
|
|
|
;;; core/cli/upgrade.el -*- lexical-binding: t; -*-
|
|
|
|
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
(defcli! (upgrade up)
|
2020-01-27 00:51:12 -05:00
|
|
|
((force-p ["-f" "--force"] "Discard local changes to Doom and packages, and upgrade anyway")
|
2020-01-26 04:45:45 -05:00
|
|
|
(packages-only-p ["-p" "--packages"] "Only upgrade packages, not Doom"))
|
2019-07-21 15:39:45 +02:00
|
|
|
"Updates Doom and packages.
|
2019-01-05 15:33:06 -05:00
|
|
|
|
2019-07-25 19:42:01 +02:00
|
|
|
This requires that ~/.emacs.d is a git repo, and is the equivalent of the
|
|
|
|
following shell commands:
|
2019-01-05 15:33:06 -05:00
|
|
|
|
|
|
|
cd ~/.emacs.d
|
2019-07-28 13:47:57 +02:00
|
|
|
git pull --rebase
|
2019-01-05 15:33:06 -05:00
|
|
|
bin/doom clean
|
|
|
|
bin/doom refresh
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
bin/doom update"
|
2019-11-10 16:44:53 -05:00
|
|
|
:bare t
|
2020-01-27 00:51:12 -05:00
|
|
|
(let ((doom-auto-discard force-p))
|
|
|
|
(if (delq
|
|
|
|
nil (list
|
|
|
|
(unless packages-only-p
|
|
|
|
(doom-cli-upgrade doom-auto-accept doom-auto-discard))
|
|
|
|
(doom-cli-execute "refresh")
|
|
|
|
(when (doom-cli-packages-update)
|
|
|
|
(doom-cli-reload-package-autoloads)
|
|
|
|
t)))
|
|
|
|
(print! (success "Done! Restart Emacs for changes to take effect."))
|
|
|
|
(print! "Nothing to do. Doom is up-to-date!"))))
|
2018-09-07 21:49:49 -04:00
|
|
|
|
|
|
|
|
|
|
|
;;
|
2019-09-12 13:25:25 -04:00
|
|
|
;;; library
|
2018-09-07 21:49:49 -04:00
|
|
|
|
|
|
|
(defvar doom-repo-url "https://github.com/hlissner/doom-emacs"
|
2019-07-28 13:47:57 +02:00
|
|
|
"The git repo url for Doom Emacs.")
|
2018-09-07 21:49:49 -04:00
|
|
|
(defvar doom-repo-remote "_upgrade"
|
2019-07-28 13:47:57 +02:00
|
|
|
"The name to use as our staging remote.")
|
|
|
|
|
2018-09-07 21:49:49 -04:00
|
|
|
(defun doom--working-tree-dirty-p (dir)
|
2019-07-29 03:21:55 +02:00
|
|
|
(cl-destructuring-bind (success . stdout)
|
2019-11-09 11:06:06 -05:00
|
|
|
(doom-call-process "git" "status" "--porcelain" "-uno")
|
2019-07-29 20:57:20 +02:00
|
|
|
(if (= 0 success)
|
2019-12-13 14:53:52 -05:00
|
|
|
(split-string stdout "\n" t)
|
2019-07-28 13:47:57 +02:00
|
|
|
(error "Failed to check working tree in %s" dir))))
|
|
|
|
|
|
|
|
|
Rewrite core-cli
Highlights:
- 'doom purge' now purges builds, elpa packages, and repos by default.
Regrafting repos is now opt-in with the -g/--regraft switches.
Negation flags have been added for elpa/repos: -e/--no-elpa and
-r/--no-repos.
- Removed 'doom rebuild' (it is now just 'doom build' or 'doom b').
- Removed 'doom build's -f flag, this is now the default. Added the -r
flag instead, which only builds packages that need rebuilding.
- 'doom update' now updates packages synchronously, but produces more
informative output about the updating process.
- Straight can now prompt in batch mode, which resolves a lot of issues
with 'doom update' (and 'doom upgrade') freezing indefinitely or
throwing repo branch errors.
- 'bin/doom's switches are now positional. Switches aimed at `bin/doom`
must precede any subcommands. e.g.
Do: 'doom -yd upgrade'
Don't do: 'doom upgrade -yd'
- Moved 'doom doctor' from bin/doom-doctor to core/cli/doctor, and
integrated core/doctor.el into it, as to avoid naming conflicts
between it and Emacs doctor.
- The defcli! macro now has a special syntax for declaring flags, their
arguments and descriptions.
Addresses #1981, #1925, #1816, #1721, #1322
2019-11-07 15:59:56 -05:00
|
|
|
(defun doom-cli-upgrade (&optional auto-accept-p force-p)
|
2018-09-07 21:49:49 -04:00
|
|
|
"Upgrade Doom to the latest version non-destructively."
|
|
|
|
(require 'vc-git)
|
2019-07-28 13:47:57 +02:00
|
|
|
(let ((default-directory doom-emacs-dir)
|
|
|
|
process-file-side-effects)
|
|
|
|
(print! (start "Preparing to upgrade Doom Emacs and its packages..."))
|
|
|
|
|
2019-07-29 03:34:35 +02:00
|
|
|
(let* ((branch (vc-git--symbolic-ref doom-emacs-dir))
|
2019-07-29 03:18:06 +02:00
|
|
|
(target-remote (format "%s/%s" doom-repo-remote branch)))
|
2019-07-28 13:47:57 +02:00
|
|
|
(unless branch
|
|
|
|
(error! (if (file-exists-p! ".git" doom-emacs-dir)
|
|
|
|
"Couldn't find Doom's .git directory. Was Doom cloned properly?"
|
|
|
|
"Couldn't detect what branch you're on. Is Doom detached?")))
|
|
|
|
|
|
|
|
;; We assume that a dirty .emacs.d is intentional and abort
|
2019-12-13 14:53:52 -05:00
|
|
|
(when-let (dirty (doom--working-tree-dirty-p default-directory))
|
2019-07-28 13:47:57 +02:00
|
|
|
(if (not force-p)
|
2019-12-13 14:53:52 -05:00
|
|
|
(user-error! "%s\n\n%s\n\n %s"
|
2019-07-28 13:47:57 +02:00
|
|
|
(format "Refusing to upgrade because %S has been modified." (path doom-emacs-dir))
|
2019-12-13 14:53:52 -05:00
|
|
|
"Either stash/undo your changes or run 'doom upgrade -f' to discard local changes."
|
|
|
|
(string-join dirty "\n"))
|
2019-07-28 13:47:57 +02:00
|
|
|
(print! (info "You have local modifications in Doom's source. Discarding them..."))
|
2019-11-09 11:06:06 -05:00
|
|
|
(doom-call-process "git" "reset" "--hard" (format "origin/%s" branch))
|
|
|
|
(doom-call-process "git" "clean" "-ffd")))
|
2019-07-28 13:47:57 +02:00
|
|
|
|
2019-11-09 11:06:06 -05:00
|
|
|
(doom-call-process "git" "remote" "remove" doom-repo-remote)
|
2019-07-29 03:47:56 +02:00
|
|
|
(unwind-protect
|
2019-12-02 20:21:41 -05:00
|
|
|
(let (result)
|
2019-11-09 11:06:06 -05:00
|
|
|
(or (zerop (car (doom-call-process "git" "remote" "add" doom-repo-remote doom-repo-url)))
|
2019-07-29 03:47:56 +02:00
|
|
|
(error "Failed to add %s to remotes" doom-repo-remote))
|
2019-12-02 20:21:41 -05:00
|
|
|
(or (zerop (car (setq result (doom-call-process "git" "fetch" "--tags" doom-repo-remote branch))))
|
2019-07-29 03:47:56 +02:00
|
|
|
(error "Failed to fetch from upstream"))
|
|
|
|
|
|
|
|
(let ((this-rev (vc-git--rev-parse "HEAD"))
|
|
|
|
(new-rev (vc-git--rev-parse target-remote)))
|
|
|
|
(cond
|
|
|
|
((and (null this-rev)
|
|
|
|
(null new-rev))
|
|
|
|
(error "Failed to get revisions for %s" target-remote))
|
|
|
|
|
|
|
|
((equal this-rev new-rev)
|
2019-08-07 20:33:28 -04:00
|
|
|
(print! (success "Doom is already up-to-date!"))
|
|
|
|
t)
|
2019-07-29 03:47:56 +02:00
|
|
|
|
2019-07-29 20:57:20 +02:00
|
|
|
((print! (info "A new version of Doom Emacs is available!\n\n Old revision: %s (%s)\n New revision: %s (%s)\n"
|
2019-07-29 03:47:56 +02:00
|
|
|
(substring this-rev 0 10)
|
2019-11-09 11:06:06 -05:00
|
|
|
(cdr (doom-call-process "git" "log" "-1" "--format=%cr" "HEAD"))
|
2019-07-29 03:47:56 +02:00
|
|
|
(substring new-rev 0 10)
|
2019-11-09 11:06:06 -05:00
|
|
|
(cdr (doom-call-process "git" "log" "-1" "--format=%cr" target-remote))))
|
2019-07-29 03:47:56 +02:00
|
|
|
|
2019-09-12 13:25:25 -04:00
|
|
|
(when (and (not auto-accept-p)
|
|
|
|
(y-or-n-p "View the comparison diff in your browser?"))
|
2019-07-29 03:47:56 +02:00
|
|
|
(print! (info "Opened github in your browser."))
|
|
|
|
(browse-url (format "https://github.com/hlissner/doom-emacs/compare/%s...%s"
|
|
|
|
this-rev
|
|
|
|
new-rev)))
|
2019-09-12 13:25:25 -04:00
|
|
|
|
|
|
|
(if (not (or auto-accept-p
|
|
|
|
(y-or-n-p "Proceed with upgrade?")))
|
2019-08-07 20:33:28 -04:00
|
|
|
(ignore (print! (error "Aborted")))
|
|
|
|
(print! (start "Upgrading Doom Emacs..."))
|
|
|
|
(print-group!
|
|
|
|
(doom-clean-byte-compiled-files)
|
2019-12-02 20:21:41 -05:00
|
|
|
(if (and (zerop (car (doom-call-process "git" "reset" "--hard" target-remote)))
|
|
|
|
(equal (vc-git--rev-parse "HEAD") new-rev))
|
|
|
|
(print! (info "%s") (cdr result))
|
2019-08-07 20:33:28 -04:00
|
|
|
(error "Failed to check out %s" (substring new-rev 0 10)))
|
|
|
|
(print! (success "Finished upgrading Doom Emacs")))
|
2019-11-24 19:37:29 -05:00
|
|
|
t)))))
|
2019-07-29 03:47:56 +02:00
|
|
|
(ignore-errors
|
2019-11-09 11:06:06 -05:00
|
|
|
(doom-call-process "git" "remote" "remove" doom-repo-remote))))))
|