]> git.ipfire.org Git - thirdparty/git.git/commit - revision.c
log: diagnose empty HEAD more clearly
authorJeff King <peff@peff.net>
Sat, 29 Aug 2015 05:04:18 +0000 (01:04 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 31 Aug 2015 16:34:20 +0000 (09:34 -0700)
commitce113604672fed9b429b1c162b1005794fff6a17
tree21c002a890487c36226e5723666a2c5b363333ca
parentf86f31ab33c3406adebbb9f9f61be550dcc5a472
log: diagnose empty HEAD more clearly

If you init or clone an empty repository, the initial
message from running "git log" is not very friendly:

  $ git init
  Initialized empty Git repository in /home/peff/foo/.git/
  $ git log
  fatal: bad default revision 'HEAD'

Let's detect this situation and write a more friendly
message:

  $ git log
  fatal: your current branch 'master' does not have any commits yet

We also detect the case that 'HEAD' points to a broken ref;
this should be even less common, but is easy to see. Note
that we do not diagnose all possible cases. We rely on
resolve_ref, which means we do not get information about
complex cases. E.g., "--default master" would use dwim_ref
to find "refs/heads/master", but we notice only that
"master" does not exist. Similarly, a complex sha1
expression like "--default HEAD^2" will not resolve as a
ref.

But that's OK. We fall back to a generic error message in
those cases, and they are unlikely to be used anyway.
Catching an empty or broken "HEAD" improves the common case,
and the other cases are not regressed.

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
revision.c
t/t4202-log.sh