Skip to content

Commit ed6db0e

Browse files
OneDeuxTriSeiGogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1b28fbd commit ed6db0e

File tree

1 file changed

+13
-10
lines changed

1 file changed

+13
-10
lines changed

t/t2400-worktree-add.sh

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -298,17 +298,20 @@ test_expect_success '"add" no auto-vivify with --detach and <branch> omitted' '
298298
test_must_fail git -C mish/mash symbolic-ref HEAD
299299
'
300300

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+
}
308311

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
312315

313316
test_expect_success '"add -B" fails if the branch is checked out' '
314317
git rev-parse newmain >before &&

0 commit comments

Comments
 (0)