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

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

From
Junio C Hamano <gitster@pobox.com>
Date
May 23, 2011, 03:18 UTC
Message-ID
<7vhb8mw1e6.fsf@alter.siamese.dyndns.org>
In-Reply-To
<BANLkTinKpSP5oEms914TWD7Tsjab1B87QQ@mail.gmail.com>
Anthony Foiani <anthony.foiani@gmail.com> writes:
Show 16 quoted lines
> On Sun, May 22, 2011 at 8:14 PM, Junio C Hamano <gitster@pobox.com> wrote:
>> 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,...
No, it was only your 'I tried to use "git diff"' that was confusing to me.

With pathspecs or any other options, it is understandable that you were confused, for example from an output like this:

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

At that point we are committed to no-index codepath, so probably a good thing to do is to update that confusing usage message a bit better.

It already does change the behaviour when --no-index is not given by the end user, so perhaps it would be sufficient to change this part:

	if (argc != i + 2)
        	usagef("git diff %s <path> <path>",
                	no_index ? "--no-index" : "[--no-index]");
to something like (caution: I am not typing this in my MUA):
	if (argc != i + 2) {
        	if (no_index)
			warning("Assuming '--no-index'; you are in no repository");
        	usagef("git diff %s <path> <path>",
                	no_index ? "--no-index" : "[--no-index]");
	}
without changing anything else.
That would be just a patch with 1 line removed, 4 lines added, no?
Previous: Anthony FoianiNext: Anthony Foiani
Message 3 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.