Skip to content

Commit c925fe2

Browse files
committed
Revert "checkout: retire --ignore-other-worktrees in favor of --force"
This reverts commit 0d1a151. 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 <[email protected]>
1 parent 0d1a151 commit c925fe2

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Documentation/git-checkout.txt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,6 @@ 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.
117114

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

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

builtin/checkout.c

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

3940
const char *new_branch;
4041
const char *new_branch_force;
@@ -902,8 +903,7 @@ static void check_linked_checkout(struct branch_info *new, const char *id)
902903
strbuf_rtrim(&gitdir);
903904
} else
904905
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);
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->force)
1154+
!opts->ignore_other_worktrees)
11551155
check_linked_checkouts(new);
11561156
free(head_ref);
11571157
}
@@ -1198,6 +1198,8 @@ 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")),
12011203
OPT_END(),
12021204
};
12031205

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, "--force");
306+
argv_array_push(&cmd, "--ignore-other-worktrees");
307307
if (new_branch)
308308
argv_array_pushl(&cmd, "-b", new_branch, NULL);
309309
if (new_branch_force)

0 commit comments

Comments
 (0)