doom/update-pinned-package-form: improve error feedback

This commit is contained in:
Henrik Lissner 2020-02-06 15:27:03 -05:00
parent a4293b53a1
commit 77e58609d4
No known key found for this signature in database
GPG key ID: 5F6C0EA160557395

View file

@ -297,25 +297,29 @@ Grabs the latest commit id of the package using 'git'."
(user-error "Not on a `package!' call") (user-error "Not on a `package!' call")
(backward-char) (backward-char)
(let* ((recipe (cdr (sexp-at-point))) (let* ((recipe (cdr (sexp-at-point)))
(name (car recipe)) (package (car recipe))
(oldid (doom-package-get package :pin))
(id (id
(cdr (doom-call-process (cdr (doom-call-process
"git" "ls-remote" "git" "ls-remote"
(straight-vc-git--destructure (straight-vc-git--destructure
(doom-plist-merge (doom-plist-merge
(plist-get (cdr recipe) :recipe) (plist-get (cdr recipe) :recipe)
(or (cdr (straight-recipes-retrieve name)) (or (cdr (straight-recipes-retrieve package))
(plist-get (cdr (assq name doom-packages)) :recipe))) (plist-get (cdr (assq package doom-packages)) :recipe)))
(upstream-repo upstream-host) (upstream-repo upstream-host)
(straight-vc-git--encode-url upstream-repo upstream-host)))))) (straight-vc-git--encode-url upstream-repo upstream-host))))))
(unless id (unless id
(user-error "No id for %S package" name)) (user-error "No id for %S package" package))
(let* ((id (if select (let* ((id (if select
(car (split-string (completing-read "Commit: " (split-string id "\n" t)))) (car (split-string (completing-read "Commit: " (split-string id "\n" t))))
(car (split-string id)))) (car (split-string id))))
(id (substring id 0 10))) (id (substring id 0 10)))
(if (re-search-forward ":pin +\"\\([^\"]+\\)\"" (cdr (bounds-of-thing-at-point 'sexp)) t) (if (and oldid (string-match-p (concat "^" oldid) id))
(replace-match id t t nil 1) (user-error "No update necessary")
(thing-at-point--end-of-sexp) (if (re-search-forward ":pin +\"\\([^\"]+\\)\"" (cdr (bounds-of-thing-at-point 'sexp)) t)
(backward-char) (replace-match id t t nil 1)
(insert " :pin " (prin1-to-string id)))))))) (thing-at-point--end-of-sexp)
(backward-char)
(insert " :pin " (prin1-to-string id)))
(message "Updated %S: %s -> %s" package oldid id)))))))