checkout: avoid resolving HEAD unnecessarily
[gitweb.git] / builtin / checkout.c
index 57545543ebcc46ef28ca4a22d399b5476de7af0b..75f90a9d1e0e37913805a3ecfac35552c61c6070 100644 (file)
@@ -1145,13 +1145,13 @@ static int checkout_branch(struct checkout_opts *opts,
                die(_("Cannot switch branch to a non-commit '%s'"),
                    new->name);
 
-       if (new->path && !opts->force_detach && !opts->new_branch) {
+       if (new->path && !opts->force_detach && !opts->new_branch &&
+           !opts->ignore_other_worktrees) {
                unsigned char sha1[20];
                int flag;
                char *head_ref = resolve_refdup("HEAD", 0, sha1, &flag);
                if (head_ref &&
-                   (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)) &&
-                   !opts->ignore_other_worktrees)
+                   (!(flag & REF_ISSYMREF) || strcmp(head_ref, new->path)))
                        check_linked_checkouts(new);
                free(head_ref);
        }