{"thread":{"id":"58344","subject":"git diff prints long usage help if not run in git repo","startedAt":"2022-08-22T18:22:27Z","lastAt":"2022-08-23T20:29:22Z","messageCount":3,"participants":["Mohamed Akram","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"461786","messageId":"A2326287-9808-4479-95C5-E54979E21F95@outlook.com","threadId":"58344","inReplyTo":null,"subject":"git diff prints long usage help if not run in git repo","fromName":"Mohamed Akram","fromEmail":"mohd.akram@outlook.com","sentAt":"2022-08-22T18:22:21Z","receivedAt":"2022-08-22T18:22:27Z","isPatch":false,"sender":{"key":"mohd.akram@outlook.com","avatar":null},"body":"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."},{"id":"461797","messageId":"xmqq5yikcbd1.fsf@gitster.g","threadId":"58344","inReplyTo":"A2326287-9808-4479-95C5-E54979E21F95@outlook.com","subject":"Re: git diff prints long usage help if not run in git repo","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2022-08-22T19:43:54Z","receivedAt":"2022-08-22T19:44:04Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Mohamed Akram <mohd.akram@outlook.com> writes:\n\n> When running `git diff` in a directory that’s not a git repo, it\n> prints a warning that this is the case, followed by a very long\n> help text that, on your average terminal, causes it to scroll so\n> much that the warning isn’t even visible. It should only print\n> the warning and nothing else like other git commands. This was\n> tested with git version 2.37.2 on macOS.\n\nThanks for a clearly written feature request.  I think it is not\nunreasonable to stop after telling the user to use the --no-index\noption.\n\nBut on the other hand, not using \"--no-index\" is not what causes\nsuch a \"git diff\" outside any repository fail.  If the user said\n\n     $ cd / && git diff\n\nit is clear that the user does not know they need to say what they\nwant to compare against what.  The reason why the command fails is\nnot because the user did not say\n\n     $ cd / && git diff --no-index\n\nbut because the user did not say\n\n     $ cd / && git diff --no-index etc/passwd etc/group\n\nSo, I dunno.\n\nPerhaps somebody can try the following patch and tell us if it is an\nimprovement.  I know it is for the specific case \"cd / && git diff\"\nbut it really depends on the reason why (1) the command was run\noutside any repository and why (2) the command was run without any\narguments.  A shallow answer to both of them are \"by mistake\", but\nwhat I am trying to get at is that understanding the reason why such\na mistake was made is probably the key to evaluate if the behaviour\nupdated by the attached patch is a good idea.\n\nThanks.\n\n\n diff-no-index.c | 7 ++++---\n 1 file changed, 4 insertions(+), 3 deletions(-)\n\ndiff --git c/diff-no-index.c w/diff-no-index.c\nindex 9a8b09346b..c8f2cdce05 100644\n--- c/diff-no-index.c\n+++ w/diff-no-index.c\n@@ -259,9 +259,10 @@ int diff_no_index(struct rev_info *revs,\n \t\t\t     diff_no_index_usage, 0);\n \tif (argc != 2) {\n \t\tif (implicit_no_index)\n-\t\t\twarning(_(\"Not a git repository. Use --no-index to \"\n-\t\t\t\t  \"compare two paths outside a working tree\"));\n-\t\tusage_with_options(diff_no_index_usage, options);\n+\t\t\tdie(_(\"Not a git repository. Use --no-index to \"\n+\t\t\t      \"compare two paths outside a working tree\"));\n+\t\telse\n+\t\t\tusage_with_options(diff_no_index_usage, options);\n \t}\n \tFREE_AND_NULL(options);\n \tfor (i = 0; i < 2; i++) {\n"},{"id":"461877","messageId":"A01F00AA-B96E-40EF-9017-9005A8AC1E14@outlook.com","threadId":"58344","inReplyTo":"xmqq5yikcbd1.fsf@gitster.g","subject":"Re: git diff prints long usage help if not run in git repo","fromName":"Mohamed Akram","fromEmail":"mohd.akram@outlook.com","sentAt":"2022-08-23T20:03:42Z","receivedAt":"2022-08-23T20:29:22Z","isPatch":false,"sender":{"key":"mohd.akram@outlook.com","avatar":null},"body":"I haven’t tried it but that patch seems to make sense to me, although I found\nanother related issue so it might need tweaking. When running `git diff` in a\nrepo owned by another user, the warning message says that this is not a git\nrepository, instead of the warning shown by other git commands about\n\"dubious ownership\". To reproduce:\n\nsudo mkdir repo\ncd repo\nsudo git init\ngit diff\n\n"}]}