Skip to content

Commit

Permalink
Add doom/bumpify-diff & doom/commit-bumps commands
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
hlissner committed Jul 11, 2021
1 parent 933dcc4 commit 95f40c6
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion core/autoload/packages.el
Original file line number Diff line number Diff line change
Expand Up @@ -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))))

0 comments on commit 95f40c6

Please sign in to comment.