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

[PATCH 1/2] diff: add test for --no-index executed outside repo

From
Thomas Gummerer <t.gummerer@gmail.com>
Date
Dec 16, 2013, 19:23 UTC
Message-ID
<1387221810-32374-1-git-send-email-t.gummerer@gmail.com>
In-Reply-To
<xmqqtxe8pu05.fsf@gitster.dls.corp.google.com>

470faf9 diff: move no-index detection to builtin/diff.c breaks the error message for "git diff --no-index", when the command is executed outside of a git repository and the wrong number of arguments are given. 6df5762 diff: don't read index when --no-index is given fixes the problem.

Add a test to guard against similar breakages in the future.
Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com>
---
Show 5 quoted lines
>> Thanks, I've missed that one.  It only happens when run outside a git
>> repository, but the same  comments still apply.  Will fix and send a
>> re-roll.
>
> Please don't, as the last round has already been pushed on 'next'.
Sorry about that, should have checked first.
> An incremental change on top would also illustrate more clearly what
> breakage needed to be fixed, which would be another good thing. It
> could even come with a new test that makes sure that the above
> command line is diagnosed correctly as a mistake ;-).

The breakage is actually fixed with the second patch as described in the commit message above, so here is just a test against future breakages. This test only works when the test root is outside of a git repository, as otherwise nongit will not be set. Is there another way to write it?

t/t4053-diff-no-index.sh | 7 +++++++
 1 file changed, 7 insertions(+)
diff --git a/t/t4053-diff-no-index.sh b/t/t4053-diff-no-index.sh
index 077c775..eb4f380 100755
--- a/t/t4053-diff-no-index.sh
+++ b/t/t4053-diff-no-index.sh
@@ -44,4 +44,11 @@ test_expect_success 'git diff outside repo with broken index' '
 	)
 '
 
+test_expect_success 'git diff --no-index executed outside repo gives correct error message' '
+	rm -rf .git &&
+	test_must_fail git diff --no-index a b b 2>actual.err &&
+	echo "usage: git diff --no-index <path> <path>" >expect.err &&
+	test_cmp expect.err actual.err
+'
+
 test_done
-- 
1.8.5.4.g8639e57
Previous: Junio C HamanoNext: Thomas Gummerer
Message 26 of 30 in “diff: don't read index when --no-index is given”
  1. diff: don't read index when --no-index is givenThomas Gummerer, Dec 9, 2013
  2. Jonathan NiederDec 9, 2013
  3. Jens LehmannDec 9, 2013
  4. Jonathan NiederDec 9, 2013
  5. Thomas GummererDec 9, 2013
  6. Jonathan NiederDec 9, 2013
  7. diff: don't read index when --no-index is givenThomas Gummerer, Dec 9, 2013
  8. Torsten BögershausenDec 9, 2013
  9. Eric SunshineDec 9, 2013
  10. Thomas GummererDec 9, 2013
  11. Junio C HamanoDec 9, 2013
  12. Thomas GummererDec 9, 2013
  13. 1/2 diff: move no-index detection to builtin/diff.cThomas Gummerer, Dec 10, 2013
  14. 2/2 diff: don't read index when --no-index is givenThomas Gummerer, Dec 10, 2013
  15. Jonathan NiederDec 10, 2013
  16. Thomas GummererDec 10, 2013
  17. Jonathan NiederDec 10, 2013
  18. Thomas GummererDec 10, 2013
  19. 1/2 diff: move no-index detection to builtin/diff.cThomas Gummerer, Dec 11, 2013
  20. 2/2 diff: don't read index when --no-index is givenThomas Gummerer, Dec 11, 2013
  21. Junio C HamanoDec 12, 2013
  22. Jonathan NiederDec 14, 2013
  23. Jonathan NiederDec 14, 2013
  24. Thomas GummererDec 14, 2013
  25. Junio C HamanoDec 16, 2013
  26. 1/2 diff: add test for --no-index executed outside repoThomas Gummerer, Dec 16, 2013
  27. 2/2 diff: avoid some nestingThomas Gummerer, Dec 16, 2013
  28. Junio C HamanoDec 16, 2013
  29. 1/2 diff: move no-index detection to builtin/diff.cThomas Gummerer, Dec 14, 2013
  30. 2/2 diff: don't read index when --no-index is givenThomas Gummerer, Dec 14, 2013

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.