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>

Jeff King committed Sep 24, 2015 at 17:02 UTC 7cd17e80579c2bffd6245837175a6e1b12a78045
1 file changed +2
builtin/show-branch.c
+2
@@ -743,6 +743,8 @@ int cmd_show_branch(int ac, const char **av, const char *prefix)
743 fake_av[1] = NULL;
744 av = fake_av;
745 ac = 1;
746 + if (!*av)
747 + die("no branches given, and HEAD is not valid");
748 }
749 if (ac != 1)
750 die("--reflog option needs one branch name");