git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] log: diagnose empty HEAD more clearly

From
Junio C Hamano <gitster@pobox.com>
Date
Jun 5, 2015, 20:47 UTC
Message-ID
<xmqqvbf1rifn.fsf@gitster.dls.corp.google.com>
In-Reply-To
<20150604083430.GB5771@peff.net>
Jeff King <peff@peff.net> writes:
Show 33 quoted lines
> But if you are OK to eventually stop dying, I think this line of
> reasoning is OK.
>
>> diff --git a/builtin/log.c b/builtin/log.c
>> index 4c4e6be..3b568a1 100644
>> --- a/builtin/log.c
>> +++ b/builtin/log.c
>> @@ -148,6 +148,9 @@ static void cmd_log_init_finish(int argc, const char **argv, const char *prefix,
>>  		rev->diffopt.output_format |= DIFF_FORMAT_NO_OUTPUT;
>>  	argc = setup_revisions(argc, argv, rev, opt);
>>  
>> +	if (!rev->pending.nr && !opt->def)
>> +		die("you do not have a commit yet on your branch");
>
> Do we want to mention the name of the branch here? I guess it does not
> really matter. Perhaps "the current branch" would be better than "your
> branch", though. Maybe:
>
>   fatal: you do not have any commits yet on the current branch
>
> This message hopefully goes away in the long run, but we'll have it for
> a while.
>
>> +static void default_to_head_if_exists(struct setup_revision_opt *opt)
>> +{
>> +	unsigned char unused[20];
>> +
>> +	if (resolve_ref_unsafe("HEAD", RESOLVE_REF_READING, unused, NULL))
>> +		opt->def = "HEAD";
>> +}
>
> This approach looks sane to me. Want to wrap it up with a commit
> message and a test?

There is an unmerged attempt jc/log-missing-default-HEAD in my "broken-out" repository https://github.com/gitster/git; I do agree that we should spend more cycles after deciding to error out to give a more detailed diagnosis, but I didn't have enough energy to bring myself do that, so I've tentatively merged your version instead of this one.

Previous: Jeff KingNext: Dennis Kaarsemaker
Message 9 of 11 in “Minor bug report”
  1. Tummala DhanviJun 3, 2015
  2. Jeff KingJun 3, 2015
  3. Junio C HamanoJun 3, 2015
  4. log: diagnose empty HEAD more clearlyJeff King, Jun 3, 2015
  5. Junio C HamanoJun 3, 2015
  6. Stefan NäweJun 4, 2015
  7. Jeff KingJun 4, 2015
  8. Jeff KingJun 4, 2015
  9. Junio C HamanoJun 5, 2015
  10. Dennis KaarsemakerJun 3, 2015
  11. Jeff KingJun 4, 2015

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.