Thread (1 message) 1 message, 1 author, 2016-06-15

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

From: Anthony Foiani <hidden>
Date: 2016-06-15 22:51:18

Junio --

On Sun, May 22, 2011 at 8:14 PM, Junio C Hamano [off-list ref] wrote:
Anthony Foiani [off-list ref] writes:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help