Skip to content

Commit

Permalink
worktree: make --detach mutually exclusive with -b/-B
Browse files Browse the repository at this point in the history
Be consistent with git-checkout which disallows this (not particularly
meaningful) combination.

Signed-off-by: Eric Sunshine <sunshine@sunshineco.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
  • Loading branch information
Eric Sunshine authored and Junio C Hamano committed Jul 20, 2015
1 parent 5dd6e23 commit ab0b2c5
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
4 changes: 2 additions & 2 deletions builtin/worktree.c
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,8 @@ static int add(int ac, const char **av, const char *prefix)

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

Expand Down
12 changes: 12 additions & 0 deletions t/t2025-worktree-add.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,4 +167,16 @@ test_expect_success '"add" auto-vivify does not clobber existing branch' '
test_path_is_missing precious
'

test_expect_success '"add" -b/-B mutually exclusive' '
test_must_fail git worktree add -b poodle -B poodle bamboo master
'

test_expect_success '"add" -b/--detach mutually exclusive' '
test_must_fail git worktree add -b poodle --detach bamboo master
'

test_expect_success '"add" -B/--detach mutually exclusive' '
test_must_fail git worktree add -B poodle --detach bamboo master
'

test_done

0 comments on commit ab0b2c5

Please sign in to comment.