From: Kyle Meyer <kyle@kyleam.com>
To: piem@inbox.kyleam.com
Subject: [RFC PATCH 12/14] am, b4-am: Add commands that extend an existing branch
Date: Wed, 29 Dec 2021 18:50:34 -0500 [thread overview]
Message-ID: <20211229235036.372313-13-kyle@kyleam.com> (raw)
In-Reply-To: <20211229235036.372313-1-kyle@kyleam.com>
piem-am-create and piem-b4-am-from-mid-create require the caller to
create a new branch or to work on top of a detached head. Sometimes
it's useful to instead apply a patch to an existing branch (e.g.,
because the caller wants a patch to go directly to the mainline or
because a new patch came in that goes on top of a current topic
branch). In these cases, an alternative approach is to apply to a
detached head or a temporary branch and then merge into the target.
Although that approach is fairly straightforward (particularly with
the help of magit-merge-into), it might not be obvious to callers.
Add dedicated commands to expose this mode of operation.
---
piem-b4.el | 14 ++++++++++++++
piem.el | 28 ++++++++++++++++++++++++++++
2 files changed, 42 insertions(+)
diff --git a/piem-b4.el b/piem-b4.el
index 48836eb2..f949f963 100644
--- a/piem-b4.el
+++ b/piem-b4.el
@@ -175,6 +175,20 @@ (defun piem-b4-am-from-mid-create (mid &optional args toggle-worktree)
(when clean-fn
(funcall clean-fn)))))
+(defun piem-b4-am-from-mid-extend (mid &optional args toggle-worktree)
+ "Like `piem-b4-am-from-mid-create', but extend an existing branch."
+ (interactive (list (or (piem-mid)
+ (read-string "Message ID: "))
+ (transient-args 'piem-b4-am)))
+ (piem-b4-am--check-args args)
+ (pcase-let* ((coderepo (piem-inbox-coderepo-maybe-read))
+ (`(,_ ,mbox-file ,clean-fn)
+ (piem-b4--get-am-files mid coderepo args)))
+ (unwind-protect
+ (piem-am-extend mbox-file nil coderepo toggle-worktree)
+ (when clean-fn
+ (funcall clean-fn)))))
+
(transient-define-argument piem-b4-am:--outdir ()
:description "Output directory"
:class 'transient-option
diff --git a/piem.el b/piem.el
index c3c2dfdf..73e331cc 100644
--- a/piem.el
+++ b/piem.el
@@ -1003,6 +1003,34 @@ (defun piem-am-create (mbox &optional format coderepo toggle-worktree info)
(list base)))))
(piem--git-am mbox format am-directory)))
+(defun piem-am-extend (mbox &optional format coderepo toggle-worktree)
+ "Like `piem-am-create', but extend an existing branch."
+ (interactive (piem-am--arguments))
+ (let* ((default-directory (or coderepo default-directory))
+ (am-directory default-directory)
+ (use-worktree (xor piem-am-create-worktree toggle-worktree))
+ (branch (if (and piem-use-magit
+ (fboundp 'magit-get-current-branch)
+ (fboundp 'magit-read-branch-or-commit))
+ (let ((current-branch (magit-get-current-branch))
+ (b (magit-read-branch-or-commit "Branch")))
+ (and (not (equal b current-branch)) b))
+ (read-string "Branch (empty for current): "))))
+ (cond
+ ((and branch (not (string-empty-p branch)))
+ (when use-worktree
+ (setq am-directory
+ (piem-am--read-worktree default-directory branch)))
+ (apply #'piem-process-call nil piem-git-executable
+ (append (if use-worktree
+ (list "worktree" "add")
+ (list "checkout"))
+ (and use-worktree (list am-directory))
+ (list branch))))
+ (use-worktree
+ (user-error "Worktree can't be created with coderepo's current branch")))
+ (piem--git-am mbox format am-directory)))
+
\f
;;;;; Patch editing
--
2.34.0
next prev parent reply other threads:[~2021-12-29 23:51 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-29 23:50 [RFC PATCH 00/14] am, b4-am: Add commands to extend an existing branch Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 01/14] am: Give better name to default piem-am-read-worktree-function value Kyle Meyer
2022-02-05 17:37 ` Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 02/14] am: Add dedicated function for reading worktree Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 03/14] am: Extract git-am logic to dedicated function Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 04/14] am: Add function for reading piem-am's arguments Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 05/14] am: Add comment header for patch editing subsection Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 06/14] edit patch: Inject values via interactive arguments Kyle Meyer
2022-02-05 17:48 ` Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 07/14] am, b4-am: Rename piem-am to piem-am-create Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 08/14] am, b4-am: Rewrite -create docstrings to emphasize branch creation Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 09/14] piem-am-create: Move info argument to the end Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 10/14] piem-am--arguments: Make info extraction optional Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 11/14] b4: Move logic for checking arguments to a dedicated function Kyle Meyer
2021-12-29 23:50 ` Kyle Meyer [this message]
2021-12-29 23:50 ` [RFC PATCH 13/14] am: Move functionality under a dedicated transient Kyle Meyer
2021-12-29 23:50 ` [RFC PATCH 14/14] b4: Add piem-b4-am-from-mid-extend to transient Kyle Meyer
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://git.kyleam.com/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20211229235036.372313-13-kyle@kyleam.com \
--to=kyle@kyleam.com \
--cc=piem@inbox.kyleam.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.kyleam.com/piem/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).