Git development
 help / color / mirror / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Mohamed Akram <mohd.akram@outlook.com>
Cc: "git@vger.kernel.org" <git@vger.kernel.org>
Subject: Re: git diff prints long usage help if not run in git repo
Date: Mon, 22 Aug 2022 12:43:54 -0700	[thread overview]
Message-ID: <xmqq5yikcbd1.fsf@gitster.g> (raw)
In-Reply-To: <A2326287-9808-4479-95C5-E54979E21F95@outlook.com> (Mohamed Akram's message of "Mon, 22 Aug 2022 18:22:21 +0000")

Mohamed Akram <mohd.akram@outlook.com> writes:

> When running `git diff` in a directory that’s not a git repo, it
> prints a warning that this is the case, followed by a very long
> help text that, on your average terminal, causes it to scroll so
> much that the warning isn’t even visible. It should only print
> the warning and nothing else like other git commands. This was
> tested with git version 2.37.2 on macOS.

Thanks for a clearly written feature request.  I think it is not
unreasonable to stop after telling the user to use the --no-index
option.

But on the other hand, not using "--no-index" is not what causes
such a "git diff" outside any repository fail.  If the user said

     $ cd / && git diff

it is clear that the user does not know they need to say what they
want to compare against what.  The reason why the command fails is
not because the user did not say

     $ cd / && git diff --no-index

but because the user did not say

     $ cd / && git diff --no-index etc/passwd etc/group

So, I dunno.

Perhaps somebody can try the following patch and tell us if it is an
improvement.  I know it is for the specific case "cd / && git diff"
but it really depends on the reason why (1) the command was run
outside any repository and why (2) the command was run without any
arguments.  A shallow answer to both of them are "by mistake", but
what I am trying to get at is that understanding the reason why such
a mistake was made is probably the key to evaluate if the behaviour
updated by the attached patch is a good idea.

Thanks.


 diff-no-index.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git c/diff-no-index.c w/diff-no-index.c
index 9a8b09346b..c8f2cdce05 100644
--- c/diff-no-index.c
+++ w/diff-no-index.c
@@ -259,9 +259,10 @@ int diff_no_index(struct rev_info *revs,
 			     diff_no_index_usage, 0);
 	if (argc != 2) {
 		if (implicit_no_index)
-			warning(_("Not a git repository. Use --no-index to "
-				  "compare two paths outside a working tree"));
-		usage_with_options(diff_no_index_usage, options);
+			die(_("Not a git repository. Use --no-index to "
+			      "compare two paths outside a working tree"));
+		else
+			usage_with_options(diff_no_index_usage, options);
 	}
 	FREE_AND_NULL(options);
 	for (i = 0; i < 2; i++) {

  reply	other threads:[~2022-08-22 19:44 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-22 18:22 git diff prints long usage help if not run in git repo Mohamed Akram
2022-08-22 19:43 ` Junio C Hamano [this message]
2022-08-23 20:03   ` Mohamed Akram

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq5yikcbd1.fsf@gitster.g \
    --to=gitster@pobox.com \
    --cc=git@vger.kernel.org \
    --cc=mohd.akram@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox