]> git.ipfire.org Git - thirdparty/git.git/commitdiff
checkout: add --ignore-other-wortrees
authorNguyễn Thái Ngọc Duy <pclouds@gmail.com>
Sat, 3 Jan 2015 09:41:26 +0000 (16:41 +0700)
committerJunio C Hamano <gitster@pobox.com>
Wed, 7 Jan 2015 18:23:08 +0000 (10:23 -0800)
Noticed-by: Mark Levedahl <mlevedahl@gmail.com>
Signed-off-by: Nguyễn Thái Ngọc Duy <pclouds@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-checkout.txt
builtin/checkout.c
t/t2025-checkout-to.sh

index 0c13825e61d8c653d9643933789aeca7acdedeaf..52eaa484c84724ec3b25ee6248ed507d432d360d 100644 (file)
@@ -232,6 +232,12 @@ section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
        specific files such as HEAD, index... See "MULTIPLE WORKING
        TREES" section for more information.
 
+--ignore-other-worktrees::
+       `git checkout` refuses when the wanted ref is already checked
+       out by another worktree. This option makes it check the ref
+       out anyway. In other words, the ref can be held by more than one
+       worktree.
+
 <branch>::
        Branch to checkout; if it refers to a branch (i.e., a name that,
        when prepended with "refs/heads/", is a valid ref), then that
index d8717efb0709a22466bab7e97ea8ebfdd91b6a54..8b2bf2093bfe3ce1dbae7d5d7c50886386be6f7b 100644 (file)
@@ -37,6 +37,7 @@ struct checkout_opts {
        int writeout_stage;
        int overwrite_ignore;
        int ignore_skipworktree;
+       int ignore_other_worktrees;
 
        const char *new_branch;
        const char *new_branch_force;
@@ -1210,7 +1211,8 @@ static int parse_branchname_arg(int argc, const char **argv,
                int flag;
                char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
                if (head_ref &&
-                   (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
+                   (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
+                   !opts->ignore_other_worktrees)
                        check_linked_checkouts(new);
                free(head_ref);
        }
@@ -1341,6 +1343,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
                                N_("second guess 'git checkout no-such-branch'")),
                OPT_FILENAME(0, "to", &opts.new_worktree,
                           N_("check a branch out in a separate working directory")),
+               OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
+                        N_("do not check if another worktree is holding the given ref")),
                OPT_END(),
        };
 
index 915b506b6c91066ebf4217aad66e38a2b0298125..f8e4df4818523de74ff7330f015415bfb9cc8227 100755 (executable)
@@ -79,6 +79,13 @@ test_expect_success 'die the same branch is already checked out' '
        )
 '
 
+test_expect_success 'not die the same branch is already checked out' '
+       (
+               cd here &&
+               git checkout --ignore-other-worktrees --to anothernewmaster newmaster
+       )
+'
+
 test_expect_success 'not die on re-checking out current branch' '
        (
                cd there &&