From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp10.migadu.com ([2001:41d0:403:4ea1::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id uE0pIXD0zGHHXwAAsNZ9tg (envelope-from ); Wed, 29 Dec 2021 23:51:12 +0000 Received: from out2.migadu.com ([2001:41d0:2:aacc::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp10.migadu.com with LMTPS id uEgnHnD0zGFy0wAAG6o9tA (envelope-from ); Thu, 30 Dec 2021 00:51:12 +0100 X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kyleam.com; s=key1; t=1640821872; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=KfB/ABCk41OqmDxl4uet1xHoqkheeR1ixh6t4te0XqI=; b=OlfU3y4kLys0Rsg49lh64E0vBGNIQzxLxOeHCNz/BI5WZcuICp9ZwbJXVp7Z5igXFM0sdv xvqaM449zAQep2jiJOQDKnqCjpqTsPrsQd51i4PTdyc2RL8P6b0THg+TcbCVWyxH41pN6E ZxiOrIG3f90zyuNxnphMSS3xKxBDXwPouqf5C0+D1Nj1JAhPU7IsApYJQ5Y13qdJEM6Oi/ 8lZ5upQSCwB3mHY2KfCbMM0jNHtmBHnuyZZcwyucSbGWz4q5ePc9oNsR5SOClOS4J93Nbw /4+uHveA3gvRbiAuE3SaUivDntsYqgwXb+mJAAoYX6QNNo/dh464X/e0n/gMkg== From: Kyle Meyer 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 Message-Id: <20211229235036.372313-13-kyle@kyleam.com> In-Reply-To: <20211229235036.372313-1-kyle@kyleam.com> References: <20211229235036.372313-1-kyle@kyleam.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Migadu-Flow: FLOW_OUT X-Migadu-Auth-User: kyleam.com X-TUID: AasDi4ylHg6E 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))) + ;;;;; Patch editing -- 2.34.0