Skip to content

Commit c265c53

Browse files
sunshinecogitster
authored andcommitted
checkout: avoid resolving HEAD unnecessarily
When --ignore-other-worktree is specified, we unconditionally skip the check to see if the requested branch is already checked out in a linked worktree. Since we know that we will be skipping that check, there is no need to resolve HEAD in order to detect other conditions under which we may skip the check. Signed-off-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 114ff88 commit c265c53

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

builtin/checkout.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,13 +1145,13 @@ static int checkout_branch(struct checkout_opts *opts,
11451145
die(_("Cannot switch branch to a non-commit '%s'"),
11461146
new->name);
11471147

1148-
if (new->path && !opts->force_detach && !opts->new_branch) {
1148+
if (new->path && !opts->force_detach && !opts->new_branch &&
1149+
!opts->ignore_other_worktrees) {
11491150
unsigned char sha1[20];
11501151
int flag;
11511152
char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
11521153
if (head_ref &&
1153-
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
1154-
!opts->ignore_other_worktrees)
1154+
(!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
11551155
check_linked_checkouts(new);
11561156
free(head_ref);
11571157
}

0 commit comments

Comments
 (0)