{"thread":{"id":"59706","subject":"[PATCH v10 3/8] t2400: refactor \"worktree add\" opt exclusion tests","startedAt":"2023-05-07T12:06:49Z","lastAt":"2023-05-07T12:06:49Z","messageCount":1,"participants":["Jacob Abel"],"isPatch":true,"patchVersion":10,"patchTotal":8},"messages":[{"id":"476720","messageId":"20230507120530.14669-4-jacobabel@nullpo.dev","threadId":"59706","inReplyTo":null,"subject":"[PATCH v10 3/8] t2400: refactor \"worktree add\" opt exclusion tests","fromName":"Jacob Abel","fromEmail":"jacobabel@nullpo.dev","sentAt":"2023-05-07T12:06:24Z","receivedAt":"2023-05-07T12:06:49Z","isPatch":true,"sender":{"key":"jacobabel@nullpo.dev","avatar":"https://avatars.githubusercontent.com/u/9424043?v=4"},"body":"Pull duplicate test code into a function so that additional opt\ncombinations can be tested succinctly.\n\nSigned-off-by: Jacob Abel <jacobabel@nullpo.dev>\n---\n t/t2400-worktree-add.sh | 23 +++++++++++++----------\n 1 file changed, 13 insertions(+), 10 deletions(-)\n\ndiff --git a/t/t2400-worktree-add.sh b/t/t2400-worktree-add.sh\nindex a3f108347a..0ca3ec2022 100755\n--- a/t/t2400-worktree-add.sh\n+++ b/t/t2400-worktree-add.sh\n@@ -298,17 +298,20 @@ test_expect_success '\"add\" no auto-vivify with --detach and <branch> omitted' '\n \ttest_must_fail git -C mish/mash symbolic-ref HEAD\n '\n\n-test_expect_success '\"add\" -b/-B mutually exclusive' '\n-\ttest_must_fail git worktree add -b poodle -B poodle bamboo main\n-'\n-\n-test_expect_success '\"add\" -b/--detach mutually exclusive' '\n-\ttest_must_fail git worktree add -b poodle --detach bamboo main\n-'\n+# Helper function to test mutually exclusive options.\n+#\n+# Note: Quoted arguments containing spaces are not supported.\n+test_wt_add_excl () {\n+\tlocal opts=\"$*\" &&\n+\ttest_expect_success \"'worktree add' with '$opts' has mutually exclusive options\" '\n+\t\ttest_must_fail git worktree add $opts 2>actual &&\n+\t\tgrep -E \"fatal:( options)? .* cannot be used together\" actual\n+\t'\n+}\n\n-test_expect_success '\"add\" -B/--detach mutually exclusive' '\n-\ttest_must_fail git worktree add -B poodle --detach bamboo main\n-'\n+test_wt_add_excl -b poodle -B poodle bamboo main\n+test_wt_add_excl -b poodle --detach bamboo main\n+test_wt_add_excl -B poodle --detach bamboo main\n\n test_expect_success '\"add -B\" fails if the branch is checked out' '\n \tgit rev-parse newmain >before &&\n--\n2.39.3\n\n\n"}]}