Add doom/bumpify-diff & doom/commit-bumps commands

To make bumping things easier. Use M-x doom/commit-bumps to create a
pre-filled bump commit in magit. Use M-x doom/bumpify-diff to scrape the
current buffer (assuming it's a diff buffer) and copy a bump commit
message to your clipboard.
This commit is contained in:
Henrik Lissner 2021-07-11 13:43:58 -04:00
parent 933dcc4d19
commit 95f40c62ab

View file

@ -197,6 +197,64 @@ each package."
;;
;;; Bump commits
;;;###autoload
(defun doom/bumpify-diff (&optional interactive)
"Copy user/repo@hash -> user/repo@hash's of changed packages to clipboard.
Must be run from a magit diff buffer."
(interactive (list 'interactive))
(save-window-excursion
(magit-diff-staged)
(unless (eq major-mode 'magit-diff-mode)
(user-error "Not in a magit diff buffer"))
(let (targets lines)
(save-excursion
(while (re-search-forward "^modified +\\(.+\\)$" nil t)
(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)
(save-window-excursion
(call-interactively #'magit-diff-visit-file)
(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 before (doom--package-to-bump-string package plist)))))
(re-search-forward "^+")
(save-window-excursion
(call-interactively #'magit-diff-visit-file)
(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)
(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 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
(defun doom/commit-bumps ()
(interactive))
"Create a pre-filled magit commit for currently bumped packages."
(interactive)
(magit-commit-create
(list "-e" "-m" (doom/bumpify-diff))))