fix(lib): doom/bumpify-diffs missing packages

This command would skip over consecutive package! statements in the
generated commit message. This commit fixes that.

That said, this command is still a temporary measure until formal bump
CI/CD is done, but should make dealing with doom/bumpify-diffs and
doom/commit-bumps a little less painful.
This commit is contained in:
Henrik Lissner 2023-02-21 00:35:17 -05:00
parent de355b009a
commit d24e197964
No known key found for this signature in database
GPG key ID: B60957CA074D39A3

View file

@ -206,34 +206,46 @@ Must be run from a magit diff buffer."
(unless (eq major-mode 'magit-diff-mode) (unless (eq major-mode 'magit-diff-mode)
(user-error "Not in a magit diff buffer")) (user-error "Not in a magit diff buffer"))
(goto-char (point-min)) (goto-char (point-min))
(let (targets lines) (letf! (defun read-package ()
(let* ((file (magit-file-at-point))
(visited? (if file (get-file-buffer file))))
(save-window-excursion
(call-interactively #'magit-diff-visit-file)
(unwind-protect
(and (or (looking-at-p "(package!")
(re-search-forward "(package! " (line-end-position) t)
(re-search-backward "(package! " nil t))
(let* ((buffer-file-name file)
(plist (doom--package-at-point)))
(cons (plist-get plist :package)
plist)))
(unless visited?
(kill-current-buffer))))))
(let (targets
before
after
lines
errors)
(save-excursion (save-excursion
(while (re-search-forward "^modified +\\(.+\\)$" nil t) (while (re-search-forward "^modified +\\(.+\\)$" nil t)
(cl-pushnew (doom-module-from-path (match-string 1)) targets (cl-pushnew (doom-module-from-path (match-string 1)) targets
:test #'equal))) :test #'equal)))
(save-excursion
(while (re-search-forward "^-" nil t) (while (re-search-forward "^-" nil t)
(let ((file (magit-file-at-point)) (cl-pushnew (read-package) before :test #'equal)))
before after) (save-excursion
(and (save-window-excursion (while (re-search-forward "^+" nil t)
(call-interactively #'magit-diff-visit-file) (cl-pushnew (read-package) after :test #'equal)))
(when (or (looking-at-p "(package!") (unless (= (length before) (length after))
(re-search-forward "(package! " (line-end-position) t) (user-error "Uneven number of packages being bumped"))
(re-search-backward "(package! " nil t)) (dolist (p1 before)
(let ((buffer-file-name file)) (cl-destructuring-bind (package &key plist _beg _end &allow-other-keys) p1
(cl-destructuring-bind (&key package plist _beg _end) (let ((p2 (cdr (assq package after))))
(doom--package-at-point) (if (null p2)
(setq before (doom--package-to-bump-string package plist)))))) (push package errors)
(re-search-forward "^+" nil t) (let ((bstr1 (doom--package-to-bump-string package plist))
(save-window-excursion (bstr2 (doom--package-to-bump-string package (plist-get p2 :plist))))
(call-interactively #'magit-diff-visit-file) (cl-pushnew (format "%s -> %s" bstr1 bstr2) lines))))))
(or (looking-at-p "(package!")
(re-search-forward "(package! " (line-end-position) t)
(re-search-backward "(package! "))
(let ((buffer-file-name file))
(cl-destructuring-bind (&key package plist _beg _end)
(doom--package-at-point)
(setq after (doom--package-to-bump-string package plist)))))
(cl-pushnew (format "%s -> %s" before after) lines))))
(if (null lines) (if (null lines)
(user-error "No bumps to bumpify") (user-error "No bumps to bumpify")
(prog1 (funcall (if interactive #'kill-new #'identity) (prog1 (funcall (if interactive #'kill-new #'identity)
@ -249,7 +261,7 @@ Must be run from a magit diff buffer."
(string-join (sort (reverse lines) #'string-lessp) (string-join (sort (reverse lines) #'string-lessp)
"\n"))) "\n")))
(when interactive (when interactive
(message "Copied to clipboard"))))))) (message "Copied to clipboard"))))))))
;;;###autoload ;;;###autoload
(defun doom/commit-bumps () (defun doom/commit-bumps ()