Skip to content

Commit

Permalink
checkout: add --ignore-other-wortrees
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Nguyễn Thái Ngọc Duy authored and Junio C Hamano committed Jan 7, 2015
1 parent 10f102b commit 1d0fa89
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
6 changes: 6 additions & 0 deletions Documentation/git-checkout.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion builtin/checkout.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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(),
};

Expand Down
7 changes: 7 additions & 0 deletions t/t2025-checkout-to.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down

0 comments on commit 1d0fa89

Please sign in to comment.