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

Re: [PATCH] Improve errors from 'git diff --no-index'.

From
Anthony Foiani <anthony.foiani@gmail.com>
Date
May 23, 2011, 02:35 UTC
Message-ID
<BANLkTinKpSP5oEms914TWD7Tsjab1B87QQ@mail.gmail.com>
In-Reply-To
<7vlixyw4cx.fsf@alter.siamese.dyndns.org>
Junio --
On Sun, May 22, 2011 at 8:14 PM, Junio C Hamano <gitster@pobox.com> wrote:
Show 13 quoted lines
> Anthony Foiani <anthony.foiani@gmail.com> writes:
>
>> I accidentally tried to use "git diff" when I wasn't within a git
>> repository, only to be confused by getting a usage message with no
>> particular error output.
>
> I do not understand this at all.
>
>    $ cd /
>    $ git diff
>    usage: git diff [--no-index] <path> <path>
>
> What's unclear about it?

It's hard for me to explain right now, as I just spent a few hours figuring out exactly what "git diff" assumed would happen. And now that I have done that study, I would not need anything beyond the original error message, either.

But when I screwed up earlier today, I was somewhat taken aback by the fact that I kept on getting the same usage message with no indication of what the heck I was doing wrong:

$ git diff -b main.c usage: git diff [--no-index] <path> <path> $ git diff --cached -b main.c usage: git diff [--no-index] <path> <path> $ git diff -b HEAD -- main.c usage: git diff [--no-index] <path> <path> $ git diff -b -- main.c usage: git diff [--no-index] <path> <path>

It would have saved me a chunk of time to have one of my diagnostics (in this case, "not in a git repo") to knock some sense into me earlier.

*shrug* Toss it in the bit-bucket if you like, but the work's already been done. And I happen to find the new code more readable than the previous triple-negative and de Morgan's-expanded conditionals, but that's of course personal taste.

For that matter, the existing code was already doing many of these checks, but not communicating the results back in any way other than presenting a usage string. I apparently interpreted that as "you're calling me wrong", not "you're using me wrong".

There might be a bug even in the previous code, though: there's an odd early exit from 'path_outside_repo' for absolute pathnames, but I got lost in the multiple negations and could never quite convince myself of its correctness (or lack thereof).

Either way, thanks for all your work on git!

Best regards, Tony

Previous: Anthony FoianiNext: Junio C Hamano
Message 2 of 7 in “Improve errors from 'git diff --no-index'.”
  1. Improve errors from 'git diff --no-index'.Anthony Foiani, May 22, 2011
  2. Anthony FoianiMay 23, 2011
  3. Junio C HamanoMay 23, 2011
  4. Anthony FoianiMay 23, 2011
  5. Junio C HamanoMay 23, 2011
  6. Jeff KingMay 23, 2011
  7. Anthony FoianiMay 23, 2011

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.