aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--piem-b4.el15
-rw-r--r--piem.el18
2 files changed, 23 insertions, 10 deletions
diff --git a/piem-b4.el b/piem-b4.el
index 27ecf19..172236f 100644
--- a/piem-b4.el
+++ b/piem-b4.el
@@ -130,15 +130,21 @@ list of arguments specified via ARGS."
(append args (list mid))))
;;;###autoload
-(defun piem-b4-am-from-mid (mid &optional args)
+(defun piem-b4-am-from-mid (mid &optional args toggle-worktree)
"Get the thread for MID, extract an am-ready mbox, and apply it.
+
Try to get a thread for the Message-Id MID with
`piem-mid-to-thread-functions', falling back to letting b4
download it. After calling `b4 am' with ARGS to prepare an
-am-ready mbox, feed the result to `git am'."
+am-ready mbox, feed the result to `git am'.
+
+When prefix argument TOGGLE-WORKTREE is non-nil, invert the
+meaning of `piem-am-create-worktree'. With the default value,
+this triggers the creation of a new worktree."
(interactive (list (or (piem-mid)
(read-string "Message ID: "))
- (transient-args 'piem-b4-am)))
+ (transient-args 'piem-b4-am)
+ current-prefix-arg))
(when-let ((badopt (cl-some
(lambda (arg)
(and (string-match
@@ -158,7 +164,8 @@ am-ready mbox, feed the result to `git am'."
(with-temp-buffer
(insert-file-contents (or cover mbox-file))
(piem-extract-mbox-info))
- coderepo)
+ coderepo
+ toggle-worktree)
(when clean-fn
(funcall clean-fn)))))
diff --git a/piem.el b/piem.el
index 81c5196..784d0b3 100644
--- a/piem.el
+++ b/piem.el
@@ -663,7 +663,7 @@ non-nil, it is used to construct the default completion value."
(replace-regexp-in-string "/" "-" branch))))))
;;;###autoload
-(defun piem-am (mbox &optional format info coderepo)
+(defun piem-am (mbox &optional format info coderepo toggle-worktree)
"Feed an am-ready mbox to `git am'.
MBOX is a buffer whose contents are an am-ready mbox (obtained
@@ -677,7 +677,11 @@ branch name or starting point (see `piem-default-branch-function'
for a list of possible properties).
CODEREPO, if given, indicates the code repository to operate
-within. If not specified, the default directory is used."
+within. If not specified, the default directory is used.
+
+When prefix argument TOGGLE-WORKTREE is non-nil, invert the
+meaning of `piem-am-create-worktree'. With the default value,
+this triggers the creation of a new worktree."
(interactive
(pcase-let ((`(,mbox . ,format)
(or (piem-am-ready-mbox)
@@ -689,10 +693,12 @@ within. If not specified, the default directory is used."
(list (cons :interactive mbox)
format
(piem-extract-mbox-info mbox)
- (piem-inbox-coderepo-maybe-read))))
+ (piem-inbox-coderepo-maybe-read)
+ current-prefix-arg)))
(setq format (or format "mboxrd"))
(let* ((default-directory (or coderepo default-directory))
(am-directory default-directory)
+ (use-worktree (xor piem-am-create-worktree toggle-worktree))
(interactivep (eq (car-safe mbox) :interactive)))
(when interactivep
(setq mbox (cdr mbox)))
@@ -707,7 +713,7 @@ within. If not specified, the default directory is used."
(magit-list-local-branch-names)))
(base (plist-get info :base-commit)))
(if base (cons base cands) cands)))))
- (when piem-am-create-worktree
+ (when use-worktree
(setq am-directory
(expand-file-name
(funcall piem-am-read-worktree-function
@@ -715,11 +721,11 @@ within. If not specified, the default directory is used."
(when (file-exists-p am-directory)
(user-error "Worktree directory already exists")))
(apply #'piem-process-call nil piem-git-executable
- (append (if piem-am-create-worktree
+ (append (if use-worktree
(list "worktree" "add")
(list "checkout"))
(if new-branch (list "-b" new-branch) (list "--detach"))
- (and piem-am-create-worktree (list am-directory))
+ (and use-worktree (list am-directory))
(and (not (string-blank-p base))
(list base)))))
(let ((args (cons (concat "--patch-format=" format)