checkout: check return value of resolve_refdup before using hash
[gitweb.git] / builtin / checkout.c
index 81f07c3ef271db08e36ee7a89b1d128d099ecb96..5744499098e6c2a4c92879af9118ff3a2c6ba0ae 100644 (file)
@@ -814,7 +814,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;