]> git.ipfire.org Git - thirdparty/git.git/commitdiff
t2400: refactor "worktree add" opt exclusion tests
authorJacob Abel <jacobabel@nullpo.dev>
Wed, 17 May 2023 21:48:35 +0000 (21:48 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 17 May 2023 22:55:24 +0000 (15:55 -0700)
Pull duplicate test code into a function so that additional opt
combinations can be tested succinctly.

Signed-off-by: Jacob Abel <jacobabel@nullpo.dev>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
t/t2400-worktree-add.sh

index a3f108347a629b4a3b4e0ec0855458e1e1ffa50a..0ca3ec20222b72af86c762c8a6bc69ee1861c5f0 100755 (executable)
@@ -298,17 +298,20 @@ test_expect_success '"add" no auto-vivify with --detach and <branch> 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 &&