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

Re: [PATCH] Fix 'No newline...' annotation in rewrite diffs.

From
Junio C Hamano <gitster@pobox.com>
Date
Aug 2, 2012, 22:00 UTC
Message-ID
<7vehnpc5ti.fsf@alter.siamese.dyndns.org>
In-Reply-To
<85f291cec03411c61ddf8808e53621ae@imap.force9.net>
Adam Butcher <dev.lists@jessamine.co.uk> writes:
Show 10 quoted lines
> +# create a file containing numbers with no newline at
> +# the end and modify it such that the starting 10 lines
> +# are unchanged, the next 101 are rewritten and the last
> +# line differs only in that in is terminated by a newline.
> +seq 1 10 > seq
> +seq 100 +1 200 >> seq
> +printf 201 >> seq
> +(git add seq; git commit seq -m seq) >/dev/null
> +seq 1 10 > seq
> +seq 300 -1 200 >> seq

We would prefer to have these set-up steps in test_expect_success. That way, we will have more chance to catch potential and unintended breakage to "git add" and "git commit" when people attempt to update them.

Also, the redirect target sticks to redirect operator in our scripts, i.e. "cmd >seq" not "cmd > seq".

> +test_expect_success 'no newline at eof is on its own line without -B'
> +
> +	(git diff seq; true) > res &&

What is this subshell and true about? A git diff does not exit with non zero to signal differences, and even if it did, the right way to write it would be

	test_might_fail git cmd >res &&

to allow us to make sure that the git command that may or may not exit with zero still does not die an uncontrolled death (e.g. segv).

> +	grep "^\\\\ No newline at end of file$" res &&
> +	grep -v "^.\\+\\\\ No newline at end of file" res &&
> +	grep -v "\\\\ No newline at end of file.\\+$" res
> +'

It is preferrable not to spell "No newline at ..." part out, so that we won't have to worry about future rewords and i18n. There are older tests that predate i18n and they do spell these out, but that is not a good reason to make things worse than they already are.

"git apply" only looks at the backslash-space at the beginning of line anyway.

Show 7 quoted lines
> +test_expect_success 'no newline at eof is on its own line with -B' '
> +
> +	(git diff -B seq; true) > res &&
> +	grep "^\\\\ No newline at end of file$" res &&
> +	grep -v "^.\\+\\\\ No newline at end of file" res &&
> +	grep -v "\\\\ No newline at end of file.\\+$" res
> +'
Likewise.
>  test_done
Thanks.
Previous: Adam ButcherNext: Adam Butcher
Message 30 of 34 in “Fix 'No newline...' annotation in rewrite diffs.”
  1. Fix 'No newline...' annotation in rewrite diffs.Adam Butcher, Aug 2, 2012
  2. Jeff KingAug 2, 2012
  3. Junio C HamanoAug 2, 2012
  4. Jeff KingAug 2, 2012
  5. Michał KiedrowiczAug 3, 2012
  6. Jeff KingAug 3, 2012
  7. Junio C HamanoAug 3, 2012
  8. Jeff KingAug 3, 2012
  9. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  10. Jeff KingAug 3, 2012
  11. Junio C HamanoAug 3, 2012
  12. Jeff KingAug 3, 2012
  13. Michał KiedrowiczAug 3, 2012
  14. Johannes SixtAug 4, 2012
  15. Junio C HamanoAug 4, 2012
  16. Michał KiedrowiczAug 6, 2012
  17. Jeff KingAug 6, 2012
  18. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  19. Junio C HamanoAug 3, 2012
  20. Jeff KingAug 3, 2012
  21. Junio C HamanoAug 3, 2012
  22. Michał KiedrowiczAug 4, 2012
  23. Adam ButcherAug 4, 2012
  24. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  25. Jeff KingAug 3, 2012
  26. Michał KiedrowiczAug 3, 2012
  27. tests: Introduce test_seqMichał Kiedrowicz, Aug 3, 2012
  28. Jeff KingAug 3, 2012
  29. Adam ButcherAug 2, 2012
  30. Junio C HamanoAug 2, 2012
  31. Adam ButcherAug 2, 2012
  32. Adam ButcherAug 4, 2012
  33. Junio C HamanoAug 5, 2012
  34. Fix '\ No newline...' annotation in rewrite diffsAdam Butcher, Aug 5, 2012

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.