Skip to content

Commit ab0b2c5

Browse files
sunshinecogitster
authored andcommitted
worktree: make --detach mutually exclusive with -b/-B
Be consistent with git-checkout which disallows this (not particularly meaningful) combination. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 5dd6e23 commit ab0b2c5

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

builtin/worktree.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ static int add(int ac, const char **av, const char *prefix)
296296

297297
memset(&opts, 0, sizeof(opts));
298298
ac = parse_options(ac, av, prefix, options, worktree_usage, 0);
299-
if (opts.new_branch && new_branch_force)
300-
die(_("-b and -B are mutually exclusive"));
299+
if (!!opts.detach + !!opts.new_branch + !!new_branch_force > 1)
300+
die(_("-b, -B, and --detach are mutually exclusive"));
301301
if (ac < 1 || ac > 2)
302302
usage_with_options(worktree_usage, options);
303303

t/t2025-worktree-add.sh

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,4 +167,16 @@ test_expect_success '"add" auto-vivify does not clobber existing branch' '
167167
test_path_is_missing precious
168168
'
169169

170+
test_expect_success '"add" -b/-B mutually exclusive' '
171+
test_must_fail git worktree add -b poodle -B poodle bamboo master
172+
'
173+
174+
test_expect_success '"add" -b/--detach mutually exclusive' '
175+
test_must_fail git worktree add -b poodle --detach bamboo master
176+
'
177+
178+
test_expect_success '"add" -B/--detach mutually exclusive' '
179+
test_must_fail git worktree add -B poodle --detach bamboo master
180+
'
181+
170182
test_done

0 commit comments

Comments
 (0)