Skip to content

Commit 0d1a151

Browse files
sunshinecogitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 1eb07d8 commit 0d1a151

File tree

3 files changed

+7
-12
lines changed

3 files changed

+7
-12
lines changed

Documentation/git-checkout.txt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ OPTIONS
111111
+
112112
When checking out paths from the index, do not fail upon unmerged
113113
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.
114117

115118
--ours::
116119
--theirs::
@@ -225,12 +228,6 @@ This means that you can use `git checkout -p` to selectively discard
225228
edits from your current working tree. See the ``Interactive Mode''
226229
section of linkgit:git-add[1] to learn how to operate the `--patch` mode.
227230

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-
234231
<branch>::
235232
Branch to checkout; if it refers to a branch (i.e., a name that,
236233
when prepended with "refs/heads/", is a valid ref), then that

builtin/checkout.c

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ struct checkout_opts {
3535
int writeout_stage;
3636
int overwrite_ignore;
3737
int ignore_skipworktree;
38-
int ignore_other_worktrees;
3938

4039
const char *new_branch;
4140
const char *new_branch_force;
@@ -903,7 +902,8 @@ static void check_linked_checkout(struct branch_info *new, const char *id)
903902
strbuf_rtrim(&gitdir);
904903
} else
905904
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);
907907
done:
908908
strbuf_release(&path);
909909
strbuf_release(&sb);
@@ -1151,7 +1151,7 @@ static int checkout_branch(struct checkout_opts *opts,
11511151
char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
11521152
if (head_ref &&
11531153
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
1154-
!opts->ignore_other_worktrees)
1154+
!opts->force)
11551155
check_linked_checkouts(new);
11561156
free(head_ref);
11571157
}
@@ -1198,8 +1198,6 @@ int cmd_checkout(int argc, const char **argv, const char *prefix)
11981198
N_("do not limit pathspecs to sparse entries only")),
11991199
OPT_HIDDEN_BOOL(0, "guess", &dwim_new_local_branch,
12001200
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")),
12031201
OPT_END(),
12041202
};
12051203

builtin/worktree.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ static int add(int ac, const char **av, const char *prefix)
303303

304304
argv_array_push(&cmd, "checkout");
305305
if (force)
306-
argv_array_push(&cmd, "--ignore-other-worktrees");
306+
argv_array_push(&cmd, "--force");
307307
if (new_branch)
308308
argv_array_pushl(&cmd, "-b", new_branch, NULL);
309309
if (new_branch_force)

0 commit comments

Comments
 (0)