worktree: make --detach mutually exclusive with -b/-B
authorEric Sunshine <sunshine@sunshineco.com>
Fri, 17 Jul 2015 23:00:08 +0000 (19:00 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 20 Jul 2015 18:29:24 +0000 (11:29 -0700)
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>
builtin/worktree.c
t/t2025-worktree-add.sh
index 7d70eb682c8d4eeea18c08569649441150ca655c..813e0161302abef6dda0352573fc08d2eee898aa 100644 (file)
@@ -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);
 
index 9e30690692d35f25ebbbe6670a19f1effd9b688e..249e4540dcf1207bf75835d2b6b6ebc8cc8bf685 100755 (executable)
@@ -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