diff options
author | Sean Whitton <spwhitton@spwhitton.name> | 2019-11-02 12:06:40 -0700 |
---|---|---|
committer | Sean Whitton <spwhitton@spwhitton.name> | 2019-11-02 12:06:40 -0700 |
commit | 80bf3c2b53d7514b888cec7ca6fdb2f4e579269d (patch) | |
tree | f497f1b44ce18122815d80f4703c55dbb7de65d2 | |
parent | cb53ee3309fb20492bdb2d43c4596ed507140701 (diff) |
mailscripts.el: add notmuch-extract-message-patches{,-projectile}
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
-rw-r--r-- | debian/changelog | 1 | ||||
-rw-r--r-- | mailscripts.el | 29 |
2 files changed, 30 insertions, 0 deletions
diff --git a/debian/changelog b/debian/changelog index 52c4282..06e92e6 100644 --- a/debian/changelog +++ b/debian/changelog @@ -7,6 +7,7 @@ mailscripts (0.12-1) UNRELEASED; urgency=medium Thanks to Daniel Kahn Gillmor for the patch series. * mailscripts.el: add mailscripts-extract-patches-branch-prefix defcustom. * mailscripts.el: add notmuch-extract-thread-patches-projectile command. + * mailscripts.el: add notmuch-extract-message-patches{,-projectile} commands. -- Sean Whitton <spwhitton@spwhitton.name> Fri, 01 Nov 2019 20:38:07 -0700 diff --git a/mailscripts.el b/mailscripts.el index bcdc0ad..09d213d 100644 --- a/mailscripts.el +++ b/mailscripts.el @@ -77,6 +77,35 @@ threads to the notmuch-extract-patch(1) command." (interactive) (mailscripts--projectile-repo-and-branch 'notmuch-extract-thread-patches)) +;;;###autoload +(defun notmuch-extract-message-patches (repo branch) + "Extract patches attached to current message to branch BRANCH in repo REPO. + +The target branch may or may not already exist. + +Patches are applied using git-am(1), so we only consider +attachments with filenames which look like they were generated by +git-format-patch(1)." + (interactive "Dgit repo: \nsnew branch name: ") + (with-current-notmuch-show-message + (let ((default-directory (expand-file-name repo)) + (mm-handle (mm-dissect-buffer))) + (mailscripts--check-out-branch branch) + (notmuch-foreach-mime-part + (lambda (p) + (let* ((disposition (mm-handle-disposition p)) + (filename (cdr (assq 'filename disposition)))) + (and filename + (string-match "^[0-9]+-.+\.\\(patch\\|diff\\|txt\\)$" filename) + (mm-pipe-part p "git am")))) + mm-handle)))) + +;;;###autoload +(defun notmuch-extract-message-patches-projectile () + "Like `notmuch-extract-message-patches', but use projectile to choose the repo." + (interactive) + (mailscripts--projectile-repo-and-branch 'notmuch-extract-message-patches)) + (defun mailscripts--check-out-branch (branch) (call-process-shell-command (format "git checkout -b %s" |