summaryrefslogtreecommitdiff
path: root/builtin/checkout.c
diff options
context:
space:
mode:
authorLibravatar Eric Sunshine <sunshine@sunshineco.com>2015-07-17 18:59:56 -0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2015-07-20 11:29:24 -0700
commitc265c533cfbced87d56ad6d3d4ae3d62475c29ce (patch)
treebaa9700fd11a99d11c204bc66d56cb86373f2e92 /builtin/checkout.c
parentconfig: rename "gc.pruneWorktreesExpire" to "gc.worktreePruneExpire" (diff)
downloadtgif-c265c533cfbced87d56ad6d3d4ae3d62475c29ce.tar.xz
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 <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'builtin/checkout.c')
-rw-r--r--builtin/checkout.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/builtin/checkout.c b/builtin/checkout.c
index 57545543eb..75f90a9d1e 100644
--- a/builtin/checkout.c
+++ b/builtin/checkout.c
@@ -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);
}