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

[PATCH v2 5/7] t4003, t4005, t4007 & t4008: handle CR/LF in t/README & t/diff-lib/README

From
Johannes Schindelin <johannes.schindelin@gmx.de>
Date
May 4, 2017, 09:50 UTC
Message-ID
<8afbd831b79b5978c1c2f8641a911c02e4175de2.1493891336.git.johannes.schindelin@gmx.de>
In-Reply-To
<cover.1493891336.git.johannes.schindelin@gmx.de>

Seeing as Git originates from the Linux ecosystem, it is understandable that the assumption of Unix line endings is deeply ingrained in Git's source code as well as its test suite.

However, we must not force files that are otherwise unrelated to tests to have Unix line endings just to appease test scripts that may use them. Instead, the test scripts should be indifferent what line endings files outside their corresponding tNNNN/ directories have.

As t4003-diff-rename-1.sh, t4005-diff-rename-2.sh, t4007-rename-3.sh & t4008-diff-break-rewrite.sh make hard-coded assumptions about the SHA-1 of the tested files, and as those files' contents originate from outside this script's sphere of authority, it must handle CR/LF line endings in those files gracefully. We do that by simply stripping out CR bytes.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
---
 t/t4003-diff-rename-1.sh      | 4 ++--
 t/t4005-diff-rename-2.sh      | 4 ++--
 t/t4007-rename-3.sh           | 2 +-
 t/t4008-diff-break-rewrite.sh | 4 ++--
 4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/t/t4003-diff-rename-1.sh b/t/t4003-diff-rename-1.sh
index df2accb6555..c3e0a3c3fc9 100755
--- a/t/t4003-diff-rename-1.sh
+++ b/t/t4003-diff-rename-1.sh
@@ -11,7 +11,7 @@ test_description='More rename detection
 
 test_expect_success \
     'prepare reference tree' \
-    'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
+    'tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
      echo frotz >rezrov &&
     git update-index --add COPYING rezrov &&
     tree=$(git write-tree) &&
@@ -99,7 +99,7 @@ test_expect_success \
 
 test_expect_success \
     'prepare work tree once again' \
-    'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
+    'tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
      git update-index --add --remove COPYING COPYING.1'
 
 # tree has COPYING and rezrov.  work tree has COPYING and COPYING.1,
diff --git a/t/t4005-diff-rename-2.sh b/t/t4005-diff-rename-2.sh
index 135addbfbda..f1641c35ee2 100755
--- a/t/t4005-diff-rename-2.sh
+++ b/t/t4005-diff-rename-2.sh
@@ -11,7 +11,7 @@ test_description='Same rename detection as t4003 but testing diff-raw.
 
 test_expect_success \
     'prepare reference tree' \
-    'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
+    'tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
      echo frotz >rezrov &&
     git update-index --add COPYING rezrov &&
     tree=$(git write-tree) &&
@@ -71,7 +71,7 @@ test_expect_success \
 
 test_expect_success \
     'prepare work tree once again' \
-    'cat "$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
+    'tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/COPYING >COPYING &&
      git update-index --add --remove COPYING COPYING.1'
 
 git diff-index -C --find-copies-harder $tree >current
diff --git a/t/t4007-rename-3.sh b/t/t4007-rename-3.sh
index dae327fabbf..0157fde5503 100755
--- a/t/t4007-rename-3.sh
+++ b/t/t4007-rename-3.sh
@@ -11,7 +11,7 @@ test_description='Rename interaction with pathspec.
 
 test_expect_success 'prepare reference tree' '
 	mkdir path0 path1 &&
-	cp "$TEST_DIRECTORY"/diff-lib/COPYING path0/COPYING &&
+	tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/COPYING >path0/COPYING &&
 	git update-index --add path0/COPYING &&
 	tree=$(git write-tree) &&
 	echo $tree
diff --git a/t/t4008-diff-break-rewrite.sh b/t/t4008-diff-break-rewrite.sh
index 9dd1bc5e162..5af4fa6aadb 100755
--- a/t/t4008-diff-break-rewrite.sh
+++ b/t/t4008-diff-break-rewrite.sh
@@ -25,8 +25,8 @@ Further, with -B and -M together, these should turn into two renames.
 . "$TEST_DIRECTORY"/diff-lib.sh ;# test-lib chdir's into trash
 
 test_expect_success setup '
-	cat "$TEST_DIRECTORY"/diff-lib/README >file0 &&
-	cat "$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
+	tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/README >file0 &&
+	tr -d "\015" <"$TEST_DIRECTORY"/diff-lib/COPYING >file1 &&
 	git update-index --add file0 file1 &&
 	git tag reference $(git write-tree)
 '
-- 
2.12.2.windows.2.800.gede8f145e06
Previous: Johannes SchindelinNext: Junio C Hamano
Message 23 of 39 in “Abide by our own rules regarding line endings”
  1. 0/5 Abide by our own rules regarding line endingsJohannes Schindelin, May 2, 2017
  2. 2/5 git-new-workdir: mark script as LF-onlyJohannes Schindelin, May 2, 2017
  3. 1/5 Fix build with core.autocrlf=trueJohannes Schindelin, May 2, 2017
  4. 3/5 completion: mark bash script as LF-onlyJohannes Schindelin, May 2, 2017
  5. 5/5 t4051: mark supporting files as requiring LF-only line endingsJohannes Schindelin, May 2, 2017
  6. 4/5 Fix the remaining tests that failed with core.autocrlf=trueJohannes Schindelin, May 2, 2017
  7. Jonathan NiederMay 2, 2017
  8. Johannes SchindelinMay 3, 2017
  9. Junio C HamanoMay 4, 2017
  10. Johannes SchindelinMay 4, 2017
  11. Junio C HamanoMay 4, 2017
  12. Johannes SchindelinMay 4, 2017
  13. Junio C HamanoMay 7, 2017
  14. Johannes SchindelinMay 8, 2017
  15. 0/7 Abide by our own rules regarding line endingsJohannes Schindelin, May 4, 2017
  16. 1/7 Fix build with core.autocrlf=trueJohannes Schindelin, May 4, 2017
  17. Junio C HamanoMay 8, 2017
  18. 2/7 git-new-workdir: mark script as LF-onlyJohannes Schindelin, May 4, 2017
  19. Junio C HamanoMay 8, 2017
  20. 4/7 t3901: move supporting files into t/t3901/Johannes Schindelin, May 4, 2017
  21. Junio C HamanoMay 8, 2017
  22. 3/7 completion: mark bash script as LF-onlyJohannes Schindelin, May 4, 2017
  23. 5/7 t4003, t4005, t4007 & t4008: handle CR/LF in t/README & t/diff-lib/READMEJohannes Schindelin, May 4, 2017
  24. Junio C HamanoMay 8, 2017
  25. 6/7 Fix the remaining tests that failed with core.autocrlf=trueJohannes Schindelin, May 4, 2017
  26. Junio C HamanoMay 8, 2017
  27. 7/7 t4051: mark supporting files as requiring LF-only line endingsJohannes Schindelin, May 4, 2017
  28. Junio C HamanoMay 8, 2017
  29. Johannes SchindelinMay 9, 2017
  30. 0/6 Abide by our own rules regarding line endingsJohannes Schindelin, May 9, 2017
  31. 1/6 Fix build with core.autocrlf=trueJohannes Schindelin, May 9, 2017
  32. Jonathan NiederMay 22, 2017
  33. Junio C HamanoMay 23, 2017
  34. Johannes SchindelinMay 23, 2017
  35. 2/6 git-new-workdir: mark script as LF-onlyJohannes Schindelin, May 9, 2017
  36. 3/6 completion: mark bash script as LF-onlyJohannes Schindelin, May 9, 2017
  37. 4/6 t3901: move supporting files into t/t3901/Johannes Schindelin, May 9, 2017
  38. 5/6 Fix the remaining tests that failed with core.autocrlf=trueJohannes Schindelin, May 9, 2017
  39. 6/6 t4051: mark supporting files as requiring LF-only line endingsJohannes Schindelin, May 9, 2017

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.