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,50 +206,62 @@ 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 ()
(save-excursion (let* ((file (magit-file-at-point))
(while (re-search-forward "^modified +\\(.+\\)$" nil t) (visited? (if file (get-file-buffer file))))
(cl-pushnew (doom-module-from-path (match-string 1)) targets
:test #'equal)))
(while (re-search-forward "^-" nil t)
(let ((file (magit-file-at-point))
before after)
(and (save-window-excursion
(call-interactively #'magit-diff-visit-file)
(when (or (looking-at-p "(package!")
(re-search-forward "(package! " (line-end-position) t)
(re-search-backward "(package! " nil t))
(let ((buffer-file-name file))
(cl-destructuring-bind (&key package plist _beg _end)
(doom--package-at-point)
(setq before (doom--package-to-bump-string package plist))))))
(re-search-forward "^+" nil t)
(save-window-excursion (save-window-excursion
(call-interactively #'magit-diff-visit-file) (call-interactively #'magit-diff-visit-file)
(or (looking-at-p "(package!") (unwind-protect
(re-search-forward "(package! " (line-end-position) t) (and (or (looking-at-p "(package!")
(re-search-backward "(package! ")) (re-search-forward "(package! " (line-end-position) t)
(let ((buffer-file-name file)) (re-search-backward "(package! " nil t))
(cl-destructuring-bind (&key package plist _beg _end) (let* ((buffer-file-name file)
(doom--package-at-point) (plist (doom--package-at-point)))
(setq after (doom--package-to-bump-string package plist))))) (cons (plist-get plist :package)
(cl-pushnew (format "%s -> %s" before after) lines)))) plist)))
(if (null lines) (unless visited?
(user-error "No bumps to bumpify") (kill-current-buffer))))))
(prog1 (funcall (if interactive #'kill-new #'identity) (let (targets
(format "bump: %s\n\n%s" before
(mapconcat (lambda (x) after
(mapconcat #'symbol-name x " ")) lines
(cl-loop with alist = () errors)
for (category . module) in (reverse targets) (save-excursion
do (setf (alist-get category alist) (while (re-search-forward "^modified +\\(.+\\)$" nil t)
(append (alist-get category alist) (list module))) (cl-pushnew (doom-module-from-path (match-string 1)) targets
finally return alist) :test #'equal)))
" ") (save-excursion
(string-join (sort (reverse lines) #'string-lessp) (while (re-search-forward "^-" nil t)
"\n"))) (cl-pushnew (read-package) before :test #'equal)))
(when interactive (save-excursion
(message "Copied to clipboard"))))))) (while (re-search-forward "^+" nil t)
(cl-pushnew (read-package) after :test #'equal)))
(unless (= (length before) (length after))
(user-error "Uneven number of packages being bumped"))
(dolist (p1 before)
(cl-destructuring-bind (package &key plist _beg _end &allow-other-keys) p1
(let ((p2 (cdr (assq package after))))
(if (null p2)
(push package errors)
(let ((bstr1 (doom--package-to-bump-string package plist))
(bstr2 (doom--package-to-bump-string package (plist-get p2 :plist))))
(cl-pushnew (format "%s -> %s" bstr1 bstr2) lines))))))
(if (null lines)
(user-error "No bumps to bumpify")
(prog1 (funcall (if interactive #'kill-new #'identity)
(format "bump: %s\n\n%s"
(mapconcat (lambda (x)
(mapconcat #'symbol-name x " "))
(cl-loop with alist = ()
for (category . module) in (reverse targets)
do (setf (alist-get category alist)
(append (alist-get category alist) (list module)))
finally return alist)
" ")
(string-join (sort (reverse lines) #'string-lessp)
"\n")))
(when interactive
(message "Copied to clipboard"))))))))
;;;###autoload ;;;###autoload
(defun doom/commit-bumps () (defun doom/commit-bumps ()