commit: check result of resolve_ref_unsafe

Add check of the resolved HEAD reference while printing of a commit summary.
resolve_ref_unsafe() may return NULL pointer if underlying calls of lstat() or
open() fail in files_read_raw_ref().
Such situation can be caused by race: file becomes inaccessible to this moment.

Signed-off-by: Andrey Okoshkin <a.okoshkin@samsung.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Andrey Okoshkin 2017-10-20 14:03:28 +03:00 committed by Junio C Hamano
parent 4c2224e839
commit c26de08370

View file

@ -1483,6 +1483,8 @@ static void print_summary(const char *prefix, const struct object_id *oid,
diff_setup_done(&rev.diffopt);
head = resolve_ref_unsafe("HEAD", 0, junk_oid.hash, NULL);
if (!head)
die_errno(_("unable to resolve HEAD after creating commit"));
if (!strcmp(head, "HEAD"))
head = _("detached HEAD");
else