Sync with 2.12.5
[gitweb.git] / builtin / checkout.c
index e079a7dc83b32c781f63fe1a7721c54182894910..b3609434550a5521b63327eeb909b32797215496 100644 (file)
@@ -835,7 +835,8 @@ static int switch_branches(const struct checkout_opts *opts,
        int flag, writeout_error = 0;
        memset(&old, 0, sizeof(old));
        old.path = path_to_free = resolve_refdup("HEAD", 0, rev.hash, &flag);
-       old.commit = lookup_commit_reference_gently(rev.hash, 1);
+       if (old.path)
+               old.commit = lookup_commit_reference_gently(rev.hash, 1);
        if (!(flag & REF_ISSYMREF))
                old.path = NULL;