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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 17, 2015 at 19:00 UTC ab0b2c53ed853e34def18e7b84acd7da7e2ddd49
2 files changed +14 -2
builtin/worktree.c
+2 -2
@@ -296,8 +296,8 @@ static int add(int ac, const char **av, const char *prefix)
296
297 memset(&opts, 0, sizeof(opts));
298 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"));
301 if (ac < 1 || ac > 2)
302 usage_with_options(worktree_usage, options);
303
t/t2025-worktree-add.sh
+12
@@ -167,4 +167,16 @@ test_expect_success '"add" auto-vivify does not clobber existing branch' '
167 test_path_is_missing precious
168 '
169
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 +
182 test_done