From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:306:f42::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms12 with LMTPS id GN9CB2H0zGHHXwAAsNZ9tg (envelope-from ); Wed, 29 Dec 2021 23:50:57 +0000 Received: from out0.migadu.com ([2001:41d0:2:267::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id 8I/2BmH0zGHofwEAauVa8A (envelope-from ); Thu, 30 Dec 2021 00:50:57 +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=1640821857; 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=senDG9uITGnv6S+lUBWLxxE3Yq9Nr2Ydaso2ntCs6ns=; b=I08OGvskGXRT5X5VXW8cgvY+xrIgjzqgJRTmtEiCtpsbiG9822gvYF2mS2xS2mQwptC+yA xs0pXpitbLmdUAUsniNe/Tu0iN5v4T5Ov/ilGrEeKHHerFo087J6QRk4jRhiNZYqyOnUPq VfP2JL8ZAC8xFIHBk2nqlkVGgQBqCjs/3bTg1OY5DOj/YMt7DETiACk2ZPiHmgyF5iqUFa 6f3/RL2DWZ1paxR4W/SduyZaBRLq4G7LkdFCiL6i4nPsPjzQBmIygYqtqi/ji8oz5FLILc JOXhaVLx2O/U4RiMn51S0gxnVrHQx8jtub+wjgPdSafIQEaluxwHRjVktSzzAw== From: Kyle Meyer To: piem@inbox.kyleam.com Subject: [RFC PATCH 02/14] am: Add dedicated function for reading worktree Date: Wed, 29 Dec 2021 18:50:24 -0500 Message-Id: <20211229235036.372313-3-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: FHXmI6prWkIF piem-am calls the value of the variable piem-am-read-worktree-function and does a bit of error handling outside. Another command will need to do the same, so extract the logic to a dedicated function. --- piem.el | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/piem.el b/piem.el index 9e5b0622..ac81c217 100644 --- a/piem.el +++ b/piem.el @@ -905,6 +905,14 @@ (defun piem-am-read-worktree-sibling-named-by-branch (coderepo branch) (concat (file-name-nondirectory fname) "-" (replace-regexp-in-string "/" "-" branch)))))) +(defun piem-am--read-worktree (coderepo branch) + (let ((dir (expand-file-name + (funcall piem-am-read-worktree-function + coderepo branch)))) + (when (file-exists-p dir) + (user-error "Worktree directory already exists")) + dir)) + ;;;###autoload (defun piem-am (mbox &optional format info coderepo toggle-worktree) "Feed an am-ready mbox to `git am'. @@ -958,11 +966,7 @@ (defun piem-am (mbox &optional format info coderepo toggle-worktree) (if base (cons base cands) cands))))) (when use-worktree (setq am-directory - (expand-file-name - (funcall piem-am-read-worktree-function - default-directory new-branch))) - (when (file-exists-p am-directory) - (user-error "Worktree directory already exists"))) + (piem-am--read-worktree default-directory new-branch))) (apply #'piem-process-call nil piem-git-executable (append (if use-worktree (list "worktree" "add") -- 2.34.0