From 95f40c62ab062515b3f947e022271319172f82fb Mon Sep 17 00:00:00 2001 From: Henrik Lissner Date: Sun, 11 Jul 2021 13:43:58 -0400 Subject: [PATCH] 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. --- core/autoload/packages.el | 60 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/core/autoload/packages.el b/core/autoload/packages.el index 10265a14a..b7e799a19 100644 --- a/core/autoload/packages.el +++ b/core/autoload/packages.el @@ -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))))