t2400: refactor "worktree add" opt exclusion tests
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>
Jacob Abel committed
May 17, 2023 at 21:48 UTC
ed6db0e9fff14590f501eba24f91be1867e5e346
1 file changed
+13
-10
t/t2400-worktree-add.sh
+13
-10
@@ -298,17 +298,20 @@ test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
298
test_must_fail git -C mish/mash symbolic-ref HEAD
299
'
300
301
-test_expect_success '"add" -b/-B mutually exclusive' '
302
- test_must_fail git worktree add -b poodle -B poodle bamboo main
303
-'
304
-
305
-test_expect_success '"add" -b/--detach mutually exclusive' '
306
- test_must_fail git worktree add -b poodle --detach bamboo main
307
-'
301
+# Helper function to test mutually exclusive options.
302
+#
303
+# Note: Quoted arguments containing spaces are not supported.
304
+test_wt_add_excl () {
305
+ local opts="$*" &&
306
+ test_expect_success "'worktree add' with '$opts' has mutually exclusive options" '
307
+ test_must_fail git worktree add $opts 2>actual &&
308
+ grep -E "fatal:( options)? .* cannot be used together" actual
309
+ '
310
+}
311
309
-test_expect_success '"add" -B/--detach mutually exclusive' '
310
- test_must_fail git worktree add -B poodle --detach bamboo main
311
-'
312
+test_wt_add_excl -b poodle -B poodle bamboo main
313
+test_wt_add_excl -b poodle --detach bamboo main
314
+test_wt_add_excl -B poodle --detach bamboo main
315
316
test_expect_success '"add -B" fails if the branch is checked out' '
317
git rev-parse newmain >before &&