Second batch for 2.14
[gitweb.git] / builtin / checkout.c
index bfa5419f335dc1db98059869de24f152cffb9aa6..6c3d2e4f4cca135fa0d2562f2bcaa0af8a6aa340 100644 (file)
@@ -833,7 +833,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;