Revert "checkout: retire --ignore-other-worktrees in favor of --force"

This reverts commit 0d1a1517835a10818f2d40d8780a268dbb5e20ce. When trying to switch to a different branch, that happens to be checked out in another working tree, the user shouldn't have to give up the other safety measures (like protecting the local changes that overlap the difference between the branches) while defeating the "no two checkouts of the same branch" safety. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Junio C Hamano committed Jul 12, 2015 at 09:38 UTC c925fe23684455735c3bb1903803643a24a58d8f
3 files changed +12 -7
Documentation/git-checkout.txt
+6 -3
@@ -111,9 +111,6 @@ OPTIONS
111 +
112 When checking out paths from the index, do not fail upon unmerged
113 entries; instead, unmerged entries are ignored.
114 -+
115 -By default, checking out a branch already checked out in another worktree
116 -is disallowed. This overrides that safeguard.
114
115 --ours::
116 --theirs::
@@ -228,6 +225,12 @@ This means that you can use `git checkout -p` to selectively discard
225 edits from your current working tree. See the ``Interactive Mode''
226 section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
227
228 +--ignore-other-worktrees::
229 + `git checkout` refuses when the wanted ref is already checked
230 + out by another worktree. This option makes it check the ref
231 + out anyway. In other words, the ref can be held by more than one
232 + worktree.
233 +
234 <branch>::
235 Branch to checkout; if it refers to a branch (i.e., a name that,
236 when prepended with "refs/heads/", is a valid ref), then that
builtin/checkout.c
+5 -3
@@ -35,6 +35,7 @@ struct checkout_opts {
35 int writeout_stage;
36 int overwrite_ignore;
37 int ignore_skipworktree;
38 + int ignore_other_worktrees;
39
40 const char *new_branch;
41 const char *new_branch_force;
@@ -902,8 +903,7 @@ static void check_linked_checkout(struct branch_info *new, const char *id)
903 strbuf_rtrim(&gitdir);
904 } else
905 strbuf_addstr(&gitdir, get_git_common_dir());
905 - die(_("'%s' is already checked out at '%s'; use --force to override"),
906 - new->name, gitdir.buf);
906 + die(_("'%s' is already checked out at '%s'"), new->name, gitdir.buf);
907 done:
908 strbuf_release(&path);
909 strbuf_release(&sb);
@@ -1151,7 +1151,7 @@ static int checkout_branch(struct checkout_opts *opts,
1151 char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
1152 if (head_ref &&
1153 (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
1154 - !opts->force)
1154 + !opts->ignore_other_worktrees)
1155 check_linked_checkouts(new);
1156 free(head_ref);
1157 }
@@ -1198,6 +1198,8 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
1198 N_("do not limit pathspecs to sparse entries only")),
1199 OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch,
1200 N_("second guess 'git checkout no-such-branch'")),
1201 + OPT_BOOL(0, "ignore-other-worktrees", &opts.ignore_other_worktrees,
1202 + N_("do not check if another worktree is holding the given ref")),
1203 OPT_END(),
1204 };
1205
builtin/worktree.c
+1 -1
@@ -303,7 +303,7 @@ static int add(int ac, const char **av, const char *prefix)
303
304 argv_array_push(&cmd, "checkout");
305 if (force)
306 - argv_array_push(&cmd, "--force");
306 + argv_array_push(&cmd, "--ignore-other-worktrees");
307 if (new_branch)
308 argv_array_pushl(&cmd, "-b", new_branch, NULL);
309 if (new_branch_force)