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

As a safeguard, checking out a branch already checked out by a different worktree is disallowed. This behavior can be overridden with --ignore-other-worktrees, however, this option is neither obvious nor particularly discoverable. As a common safeguard override, --force is more likely to come to mind. Therefore, overload it to also suppress the check for a branch already checked out elsewhere. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Jul 6, 2015 at 13:31 UTC 0d1a1517835a10818f2d40d8780a268dbb5e20ce
3 files changed +7 -12
Documentation/git-checkout.txt
+3 -6
@@ -111,6 +111,9 @@ 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.
117
118 --ours::
119 --theirs::
@@ -225,12 +228,6 @@ This means that you can use `git checkout -p` to selectively discard
228 edits from your current working tree. See the ``Interactive Mode''
229 section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
230
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 -
231 <branch>::
232 Branch to checkout; if it refers to a branch (i.e., a name that,
233 when prepended with "refs/heads/", is a valid ref), then that
builtin/checkout.c
+3 -5
@@ -35,7 +35,6 @@ struct checkout_opts {
35 int writeout_stage;
36 int overwrite_ignore;
37 int ignore_skipworktree;
38 - int ignore_other_worktrees;
38
39 const char *new_branch;
40 const char *new_branch_force;
@@ -903,7 +902,8 @@ static void check_linked_checkout(struct branch_info *new, const char *id)
902 strbuf_rtrim(&gitdir);
903 } else
904 strbuf_addstr(&gitdir, get_git_common_dir());
906 - die(_("'%s' is already checked out at '%s'"), new->name, gitdir.buf);
905 + die(_("'%s' is already checked out at '%s'; use --force to override"),
906 + 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->ignore_other_worktrees)
1154 + !opts->force)
1155 check_linked_checkouts(new);
1156 free(head_ref);
1157 }
@@ -1198,8 +1198,6 @@ 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")),
1201 OPT_END(),
1202 };
1203
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, "--ignore-other-worktrees");
306 + argv_array_push(&cmd, "--force");
307 if (new_branch)
308 argv_array_pushl(&cmd, "-b", new_branch, NULL);
309 if (new_branch_force)