git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git diff prints long usage help if not run in git repo
@ 2022-08-22 18:22 Mohamed Akram
  2022-08-22 19:43 ` Junio C Hamano
  0 siblings, 1 reply; 3+ messages in thread
From: Mohamed Akram @ 2022-08-22 18:22 UTC (permalink / raw)
  To: git

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.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: git diff prints long usage help if not run in git repo
  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
  2022-08-23 20:03   ` Mohamed Akram
  0 siblings, 1 reply; 3+ messages in thread
From: Junio C Hamano @ 2022-08-22 19:43 UTC (permalink / raw)
  To: Mohamed Akram; +Cc: git

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++) {

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: git diff prints long usage help if not run in git repo
  2022-08-22 19:43 ` Junio C Hamano
@ 2022-08-23 20:03   ` Mohamed Akram
  0 siblings, 0 replies; 3+ messages in thread
From: Mohamed Akram @ 2022-08-23 20:03 UTC (permalink / raw)
  To: Junio C Hamano; +Cc: git

I haven’t tried it but that patch seems to make sense to me, although I found
another related issue so it might need tweaking. When running `git diff` in a
repo owned by another user, the warning message says that this is not a git
repository, instead of the warning shown by other git commands about
"dubious ownership". To reproduce:

sudo mkdir repo
cd repo
sudo git init
git diff


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-08-23 20:29 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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
2022-08-23 20:03   ` Mohamed Akram

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).