show-branch: avoid segfault with --reflog of unborn branch

When no branch is given to the "--reflog" option, we resolve
HEAD to get the default branch. However, if HEAD points to
an unborn branch, resolve_ref returns NULL, and we later
segfault trying to access it.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Jeff King 2015-09-24 17:02:54 -04:00 коммит произвёл Junio C Hamano
Родитель 8d530c4d64
Коммит 7cd17e8057
1 изменённых файлов: 2 добавлений и 0 удалений

Просмотреть файл

@ -743,6 +743,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
fake_av[1] = NULL;
av = fake_av;
ac = 1;
if (!*av)
die("no branches given, and HEAD is not valid");
}
if (ac != 1)
die("--reflog option needs one branch name");