From patchwork Mon Jan 9 17:33:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacob Abel X-Patchwork-Id: 13093932 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 02796C54EBD for ; Mon, 9 Jan 2023 17:33:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234463AbjAIRdt (ORCPT ); Mon, 9 Jan 2023 12:33:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54628 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235264AbjAIRdR (ORCPT ); Mon, 9 Jan 2023 12:33:17 -0500 Received: from mail-4317.proton.ch (mail-4317.proton.ch [185.70.43.17]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC0A3A47E for ; Mon, 9 Jan 2023 09:33:16 -0800 (PST) Date: Mon, 09 Jan 2023 17:33:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nullpo.dev; s=protonmail3; t=1673285595; x=1673544795; bh=4Wbg/xGke/1LGsGQfvzt2T80PxZTJ/MnH/m3koInb+Q=; h=Date:To:From:Cc:Subject:Message-ID:In-Reply-To:References: Feedback-ID:From:To:Cc:Date:Subject:Reply-To:Feedback-ID: Message-ID:BIMI-Selector; b=kX+YENiQukv2RzpbSXqQCFDpTPAY7toF42MoWRyxhhnOweK1CZ/aPI7Tki9kLX1L/ 2h9RTBSm5Ud5TxXFzCTZqtG0nejk/dPH/X+AEHXy9O+n5sGkUkNpLnRDNdfVLrFT3l RDjkRUQaqqotEYExrF41vsOHvZLFvumopbXAuyKaxLZea6NzY/ATL+1GWJyFZlcd21 rCZIdzRMmASTJXyCfY9eRt49HBvFUyK30n9PvFomAnXEyBUBG52UUufnmbRCNF8UWg 3z+GVoAwIFthE1D2RNjurUbjnOZoHiOYoBAzziTmm85MOczFp/8stAip4sSVcMQ+lk kxbpl+kJaWqWw== To: git@vger.kernel.org From: Jacob Abel Cc: Jacob Abel , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBC?= =?utf-8?b?amFybWFzb24=?= , Eric Sunshine , Junio C Hamano , Phillip Wood , =?utf-8?q?Rub=C3=A9n_Justo?= , Taylor Blau , rsbecker@nexbridge.com Subject: [PATCH v8 2/4] worktree add: refactor opt exclusion tests Message-ID: <20230109173227.29264-3-jacobabel@nullpo.dev> In-Reply-To: <20230109173227.29264-1-jacobabel@nullpo.dev> References: <20221104010242.11555-1-jacobabel@nullpo.dev> <20221104213401.17393-1-jacobabel@nullpo.dev> <20221110233137.10414-1-jacobabel@nullpo.dev> <20221212014003.20290-1-jacobabel@nullpo.dev> <20221220023637.29042-1-jacobabel@nullpo.dev> <20221228061539.13740-1-jacobabel@nullpo.dev> <20230107045757.30037-1-jacobabel@nullpo.dev> <20230109173227.29264-1-jacobabel@nullpo.dev> Feedback-ID: 21506737:user:proton MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Pull duplicate test code into a function so that additional opt combinations can be tested succinctly. Signed-off-by: Jacob Abel --- t/t2400-worktree-add.sh | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) -- 2.38.2 diff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh index d587e0b20d..dd729a00d8 100755 --- a/t/t2400-worktree-add.sh +++ b/t/t2400-worktree-add.sh @@ -298,17 +298,20 @@ test_expect_success '"add" no auto-vivify with --detach and omitted' ' test_must_fail git -C mish/mash symbolic-ref HEAD ' -test_expect_success '"add" -b/-B mutually exclusive' ' - test_must_fail git worktree add -b poodle -B poodle bamboo main -' - -test_expect_success '"add" -b/--detach mutually exclusive' ' - test_must_fail git worktree add -b poodle --detach bamboo main -' +# Helper function to test mutually exclusive options. +# +# Note: Quoted arguments containing spaces are not supported. +test_wt_add_excl () { + local opts="$*" && + test_expect_success "'worktree add' with '$opts' has mutually exclusive options" ' + test_must_fail git worktree add $opts 2>actual && + grep -E "fatal:( options)? .* cannot be used together" actual + ' +} -test_expect_success '"add" -B/--detach mutually exclusive' ' - test_must_fail git worktree add -B poodle --detach bamboo main -' +test_wt_add_excl -b poodle -B poodle bamboo main +test_wt_add_excl -b poodle --detach bamboo main +test_wt_add_excl -B poodle --detach bamboo main test_expect_success '"add -B" fails if the branch is checked out' ' git rev-parse newmain >before &&