tests: use test_write_lines() to generate line-oriented output

Take advantage of test_write_lines() to generate line-oriented output rather than using for-loops or a series of `echo` commands. Not only is test_write_lines() a natural fit for such a task, but there is less opportunity for a broken &&-chain. Signed-off-by: Eric Sunshine <sunshine@sunshineco.com> Reviewed-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Eric Sunshine committed Dec 9, 2021 at 00:11 UTC 0849541268a3aca9381591aed87b6864a203709b
26 files changed +106 -170
t/t0020-crlf.sh
+14 -14
@@ -22,10 +22,10 @@ test_expect_success setup '
22
23 git config core.autocrlf false &&
24
25 - for w in Hello world how are you; do echo $w; done >one &&
25 + test_write_lines Hello world how are you >one &&
26 mkdir dir &&
27 - for w in I am very very fine thank you; do echo $w; done >dir/two &&
28 - for w in Oh here is NULQin text here; do echo $w; done | q_to_nul >three &&
27 + test_write_lines I am very very fine thank you >dir/two &&
28 + test_write_lines Oh here is NULQin text here | q_to_nul >three &&
29 git add . &&
30
31 git commit -m initial &&
@@ -35,7 +35,7 @@ test_expect_success setup '
35 two=$(git rev-parse HEAD:dir/two) &&
36 three=$(git rev-parse HEAD:three) &&
37
38 - for w in Some extra lines here; do echo $w; done >>one &&
38 + test_write_lines Some extra lines here >>one &&
39 git diff >patch.file &&
40 patched=$(git hash-object --stdin <one) &&
41 git read-tree --reset -u HEAD
@@ -46,7 +46,7 @@ test_expect_success 'safecrlf: autocrlf=input, all CRLF' '
46 git config core.autocrlf input &&
47 git config core.safecrlf true &&
48
49 - for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
49 + test_write_lines I am all CRLF | append_cr >allcrlf &&
50 test_must_fail git add allcrlf
51 '
52
@@ -55,7 +55,7 @@ test_expect_success 'safecrlf: autocrlf=input, mixed LF/CRLF' '
55 git config core.autocrlf input &&
56 git config core.safecrlf true &&
57
58 - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
58 + test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
59 test_must_fail git add mixed
60 '
61
@@ -64,7 +64,7 @@ test_expect_success 'safecrlf: autocrlf=true, all LF' '
64 git config core.autocrlf true &&
65 git config core.safecrlf true &&
66
67 - for w in I am all LF; do echo $w; done >alllf &&
67 + test_write_lines I am all LF >alllf &&
68 test_must_fail git add alllf
69 '
70
@@ -73,7 +73,7 @@ test_expect_success 'safecrlf: autocrlf=true mixed LF/CRLF' '
73 git config core.autocrlf true &&
74 git config core.safecrlf true &&
75
76 - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
76 + test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
77 test_must_fail git add mixed
78 '
79
@@ -82,10 +82,10 @@ test_expect_success 'safecrlf: print warning only once' '
82 git config core.autocrlf input &&
83 git config core.safecrlf warn &&
84
85 - for w in I am all LF; do echo $w; done >doublewarn &&
85 + test_write_lines I am all LF >doublewarn &&
86 git add doublewarn &&
87 git commit -m "nowarn" &&
88 - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >doublewarn &&
88 + test_write_lines Oh here is CRLFQ in text | q_to_cr >doublewarn &&
89 git add doublewarn 2>err &&
90 grep "CRLF will be replaced by LF" err >err.warnings &&
91 test_line_count = 1 err.warnings
@@ -103,7 +103,7 @@ test_expect_success 'safecrlf: no warning with safecrlf=false' '
103 git config core.autocrlf input &&
104 git config core.safecrlf false &&
105
106 - for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
106 + test_write_lines I am all CRLF | append_cr >allcrlf &&
107 git add allcrlf 2>err &&
108 test_must_be_empty err
109 '
@@ -351,9 +351,9 @@ test_expect_success 'setting up for new autocrlf tests' '
351 git config core.autocrlf false &&
352 git config core.safecrlf false &&
353 rm -rf .????* * &&
354 - for w in I am all LF; do echo $w; done >alllf &&
355 - for w in Oh here is CRLFQ in text; do echo $w; done | q_to_cr >mixed &&
356 - for w in I am all CRLF; do echo $w; done | append_cr >allcrlf &&
354 + test_write_lines I am all LF >alllf &&
355 + test_write_lines Oh here is CRLFQ in text | q_to_cr >mixed &&
356 + test_write_lines I am all CRLF | append_cr >allcrlf &&
357 git add -A . &&
358 git commit -m "alllf, allcrlf and mixed only" &&
359 git tag -a -m "message" autocrlf-checkpoint
t/t0026-eol-config.sh
+2 -2
@@ -15,8 +15,8 @@ test_expect_success setup '
15
16 echo "one text" > .gitattributes &&
17
18 - for w in Hello world how are you; do echo $w; done >one &&
19 - for w in I am very very fine thank you; do echo $w; done >two &&
18 + test_write_lines Hello world how are you >one &&
19 + test_write_lines I am very very fine thank you >two &&
20 git add . &&
21
22 git commit -m initial &&
t/t1020-subdirectory.sh
+2 -2
@@ -11,9 +11,9 @@ test_description='Try various core-level commands in subdirectory.
11
12 test_expect_success setup '
13 long="a b c d e f g h i j k l m n o p q r s t u v w x y z" &&
14 - for c in $long; do echo $c; done >one &&
14 + test_write_lines $long >one &&
15 mkdir dir &&
16 - for c in x y z $long a b c; do echo $c; done >dir/two &&
16 + test_write_lines x y z $long a b c >dir/two &&
17 cp one original.one &&
18 cp dir/two original.two
19 '
t/t1512-rev-parse-disambiguation.sh
+2 -8
@@ -34,10 +34,7 @@ fi
34 test_expect_success 'blob and tree' '
35 test_tick &&
36 (
37 - for i in 0 1 2 3 4 5 6 7 8 9
38 - do
39 - echo $i
40 - done &&
37 + test_write_lines 0 1 2 3 4 5 6 7 8 9 &&
38 echo &&
39 echo b1rwzyc3
40 ) >a0blgqsjc &&
@@ -204,10 +201,7 @@ test_expect_success 'more history' '
201 git checkout v1.0.0^0 &&
202 git mv a0blgqsjc f5518nwu &&
203
207 - for i in h62xsjeu j08bekfvt kg7xflhm
208 - do
209 - echo $i
210 - done >>f5518nwu &&
204 + test_write_lines h62xsjeu j08bekfvt kg7xflhm >>f5518nwu &&
205 git add f5518nwu &&
206
207 test_tick &&
t/t2103-update-index-ignore-missing.sh
+1 -1
@@ -23,7 +23,7 @@ test_expect_success basics '
23 test_cmp expect actual &&
24
25 git update-index --add one two three &&
26 - for i in one three two; do echo $i; done >expect &&
26 + test_write_lines one three two >expect &&
27 git ls-files >actual &&
28 test_cmp expect actual &&
29
t/t3417-rebase-whitespace-fix.sh
+1 -3
@@ -115,9 +115,7 @@ test_expect_success 'at beginning of file' '
115 git config core.whitespace "blank-at-eol" &&
116 cp beginning file &&
117 git commit -m beginning file &&
118 - for i in 1 2 3 4 5; do
119 - echo $i
120 - done >> file &&
118 + test_write_lines 1 2 3 4 5 >>file &&
119 git commit -m more file &&
120 git rebase --whitespace=fix HEAD^^ &&
121 test_cmp expect-beginning file
t/t4013-diff-various.sh
+11 -11
@@ -19,8 +19,8 @@ test_expect_success setup '
19
20 mkdir dir &&
21 mkdir dir2 &&
22 - for i in 1 2 3; do echo $i; done >file0 &&
23 - for i in A B; do echo $i; done >dir/sub &&
22 + test_write_lines 1 2 3 >file0 &&
23 + test_write_lines A B >dir/sub &&
24 cat file0 >file2 &&
25 git add file0 file2 dir/sub &&
26 git commit -m Initial &&
@@ -32,8 +32,8 @@ test_expect_success setup '
32 GIT_COMMITTER_DATE="2006-06-26 00:01:00 +0000" &&
33 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
34
35 - for i in 4 5 6; do echo $i; done >>file0 &&
36 - for i in C D; do echo $i; done >>dir/sub &&
35 + test_write_lines 4 5 6 >>file0 &&
36 + test_write_lines C D >>dir/sub &&
37 rm -f file2 &&
38 git update-index --remove file0 file2 dir/sub &&
39 git commit -m "Second${LF}${LF}This is the second commit." &&
@@ -42,9 +42,9 @@ test_expect_success setup '
42 GIT_COMMITTER_DATE="2006-06-26 00:02:00 +0000" &&
43 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
44
45 - for i in A B C; do echo $i; done >file1 &&
45 + test_write_lines A B C >file1 &&
46 git add file1 &&
47 - for i in E F; do echo $i; done >>dir/sub &&
47 + test_write_lines E F >>dir/sub &&
48 git update-index dir/sub &&
49 git commit -m Third &&
50
@@ -53,8 +53,8 @@ test_expect_success setup '
53 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
54
55 git checkout side &&
56 - for i in A B C; do echo $i; done >>file0 &&
57 - for i in 1 2; do echo $i; done >>dir/sub &&
56 + test_write_lines A B C >>file0 &&
57 + test_write_lines 1 2 >>dir/sub &&
58 cat dir/sub >file3 &&
59 git add file3 &&
60 git update-index file0 dir/sub &&
@@ -71,8 +71,8 @@ test_expect_success setup '
71 GIT_COMMITTER_DATE="2006-06-26 00:05:00 +0000" &&
72 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
73
74 - for i in A B C; do echo $i; done >>file0 &&
75 - for i in 1 2; do echo $i; done >>dir/sub &&
74 + test_write_lines A B C >>file0 &&
75 + test_write_lines 1 2 >>dir/sub &&
76 git update-index file0 dir/sub &&
77
78 mkdir dir3 &&
@@ -86,7 +86,7 @@ test_expect_success setup '
86 GIT_COMMITTER_DATE="2006-06-26 00:06:00 +0000" &&
87 export GIT_AUTHOR_DATE GIT_COMMITTER_DATE &&
88 git checkout -b rearrange initial &&
89 - for i in B A; do echo $i; done >dir/sub &&
89 + test_write_lines B A >dir/sub &&
90 git add dir/sub &&
91 git commit -m "Rearranged lines in dir/sub" &&
92 git checkout master &&
t/t4014-format-patch.sh
+13 -13
@@ -12,25 +12,25 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
12 . "$TEST_DIRECTORY"/lib-terminal.sh
13
14 test_expect_success setup '
15 - for i in 1 2 3 4 5 6 7 8 9 10; do echo "$i"; done >file &&
15 + test_write_lines 1 2 3 4 5 6 7 8 9 10 >file &&
16 cat file >elif &&
17 git add file elif &&
18 test_tick &&
19 git commit -m Initial &&
20 git checkout -b side &&
21
22 - for i in 1 2 5 6 A B C 7 8 9 10; do echo "$i"; done >file &&
22 + test_write_lines 1 2 5 6 A B C 7 8 9 10 >file &&
23 test_chmod +x elif &&
24 test_tick &&
25 git commit -m "Side changes #1" &&
26
27 - for i in D E F; do echo "$i"; done >>file &&
27 + test_write_lines D E F >>file &&
28 git update-index file &&
29 test_tick &&
30 git commit -m "Side changes #2" &&
31 git tag C2 &&
32
33 - for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file &&
33 + test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file &&
34 git update-index file &&
35 test_tick &&
36 git commit -m "Side changes #3 with \\n backslash-n in it." &&
@@ -43,18 +43,18 @@ test_expect_success setup '
43
44 git checkout side &&
45 git checkout -b patchid &&
46 - for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >file2 &&
47 - for i in 1 2 3 A 4 B C 7 8 9 10 D E F 5 6; do echo "$i"; done >file3 &&
48 - for i in 8 9 10; do echo "$i"; done >file &&
46 + test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >file2 &&
47 + test_write_lines 1 2 3 A 4 B C 7 8 9 10 D E F 5 6 >file3 &&
48 + test_write_lines 8 9 10 >file &&
49 git add file file2 file3 &&
50 test_tick &&
51 git commit -m "patchid 1" &&
52 - for i in 4 A B 7 8 9 10; do echo "$i"; done >file2 &&
53 - for i in 8 9 10 5 6; do echo "$i"; done >file3 &&
52 + test_write_lines 4 A B 7 8 9 10 >file2 &&
53 + test_write_lines 8 9 10 5 6 >file3 &&
54 git add file2 file3 &&
55 test_tick &&
56 git commit -m "patchid 2" &&
57 - for i in 10 5 6; do echo "$i"; done >file &&
57 + test_write_lines 10 5 6 >file &&
58 git add file &&
59 test_tick &&
60 git commit -m "patchid 3" &&
@@ -653,7 +653,7 @@ test_expect_success 'excessive subject' '
653 git checkout side &&
654 before=$(git hash-object file) &&
655 before=$(git rev-parse --short $before) &&
656 - for i in 5 6 1 2 3 A 4 B C 7 8 9 10 D E F; do echo "$i"; done >>file &&
656 + test_write_lines 5 6 1 2 3 A 4 B C 7 8 9 10 D E F >>file &&
657 after=$(git hash-object file) &&
658 after=$(git rev-parse --short $after) &&
659 git update-index file &&
@@ -1086,7 +1086,7 @@ test_expect_success TTY 'format-patch --stdout paginates' '
1086 test_expect_success 'format-patch handles multi-line subjects' '
1087 rm -rf patches/ &&
1088 echo content >>file &&
1089 - for i in one two three; do echo $i; done >msg &&
1089 + test_write_lines one two three >msg &&
1090 git add file &&
1091 git commit -F msg &&
1092 git format-patch -o patches -1 &&
@@ -1098,7 +1098,7 @@ test_expect_success 'format-patch handles multi-line subjects' '
1098 test_expect_success 'format-patch handles multi-line encoded subjects' '
1099 rm -rf patches/ &&
1100 echo content >>file &&
1101 - for i in en två tre; do echo $i; done >msg &&
1101 + test_write_lines en två tre >msg &&
1102 git add file &&
1103 git commit -F msg &&
1104 git format-patch -o patches -1 &&
t/t4019-diff-wserror.sh
+2 -2
@@ -287,9 +287,9 @@ test_expect_success 'do not color trailing cr in context' '
287 '
288
289 test_expect_success 'color new trailing blank lines' '
290 - { echo a; echo b; echo; echo; } >x &&
290 + test_write_lines a b "" "" >x &&
291 git add x &&
292 - { echo a; echo; echo; echo; echo c; echo; echo; echo; echo; } >x &&
292 + test_write_lines a "" "" "" c "" "" "" "" >x &&
293 git diff --color x >output &&
294 cnt=$($grep_a "${blue_grep}" output | wc -l) &&
295 test $cnt = 2
t/t4105-apply-fuzz.sh
+2 -8
@@ -15,15 +15,9 @@ dotest () {
15
16 test_expect_success setup '
17
18 - for i in 1 2 3 4 5 6 7 8 9 10 11 12
19 - do
20 - echo $i
21 - done >file &&
18 + test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 >file &&
19 git update-index --add file &&
23 - for i in 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12
24 - do
25 - echo $i
26 - done >file &&
20 + test_write_lines 1 2 3 4 5 6 7 a b c d e 8 9 10 11 12 >file &&
21 cat file >expect &&
22 git diff >O0.diff &&
23
t/t4116-apply-reverse.sh
+2 -2
@@ -11,14 +11,14 @@ test_description='git apply in reverse
11
12 test_expect_success setup '
13
14 - for i in a b c d e f g h i j k l m n; do echo $i; done >file1 &&
14 + test_write_lines a b c d e f g h i j k l m n >file1 &&
15 perl -pe "y/ijk/\\000\\001\\002/" <file1 >file2 &&
16
17 git add file1 file2 &&
18 git commit -m initial &&
19 git tag initial &&
20
21 - for i in a b c g h i J K L m o n p q; do echo $i; done >file1 &&
21 + test_write_lines a b c g h i J K L m o n p q >file1 &&
22 perl -pe "y/mon/\\000\\001\\002/" <file1 >file2 &&
23
24 git commit -a -m second &&
t/t4117-apply-reject.sh
+4 -16
@@ -10,25 +10,16 @@ test_description='git apply with rejects
10 . ./test-lib.sh
11
12 test_expect_success setup '
13 - for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
14 - do
15 - echo $i
16 - done >file1 &&
13 + test_write_lines 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 >file1 &&
14 cat file1 >saved.file1 &&
15 git update-index --add file1 &&
16 git commit -m initial &&
17
21 - for i in 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21
22 - do
23 - echo $i
24 - done >file1 &&
18 + test_write_lines 1 2 A B 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 D 21 >file1 &&
19 git diff >patch.1 &&
20 cat file1 >clean &&
21
28 - for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21
29 - do
30 - echo $i
31 - done >expected &&
22 + test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 C 13 14 15 16 17 18 19 20 F 21 >expected &&
23
24 mv file1 file2 &&
25 git update-index --add --remove file1 file2 &&
@@ -38,10 +29,7 @@ test_expect_success setup '
29 mv saved.file1 file1 &&
30 git update-index --add --remove file1 file2 &&
31
41 - for i in 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21
42 - do
43 - echo $i
44 - done >file1 &&
32 + test_write_lines 1 E 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 F 21 >file1 &&
33
34 cat file1 >saved.file1
35 '
t/t4118-apply-empty-context.sh
+1 -5
@@ -10,11 +10,7 @@ test_description='git apply with new style GNU diff with empty context
10 . ./test-lib.sh
11
12 test_expect_success setup '
13 - {
14 - echo; echo;
15 - echo A; echo B; echo C;
16 - echo;
17 - } >file1 &&
13 + test_write_lines "" "" A B C "" >file1 &&
14 cat file1 >file1.orig &&
15 {
16 cat file1 &&
t/t4124-apply-ws-rule.sh
+28 -28
@@ -230,9 +230,9 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' '
230 test_might_fail git config --unset core.whitespace &&
231 rm -f .gitattributes &&
232
233 - { echo a; echo b; echo c; } >one &&
233 + test_write_lines a b c >one &&
234 git add one &&
235 - { echo a; echo b; echo c; } >expect &&
235 + test_write_lines a b c >expect &&
236 { cat expect; echo; } >one &&
237 git diff -- one >patch &&
238
@@ -242,10 +242,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (1)' '
242 '
243
244 test_expect_success 'blank at EOF with --whitespace=fix (2)' '
245 - { echo a; echo b; echo c; } >one &&
245 + test_write_lines a b c >one &&
246 git add one &&
247 - { echo a; echo c; } >expect &&
248 - { cat expect; echo; echo; } >one &&
247 + test_write_lines a b >expect &&
248 + { cat expect && test_write_lines "" ""; } >one &&
249 git diff -- one >patch &&
250
251 git checkout one &&
@@ -254,10 +254,10 @@ test_expect_success 'blank at EOF with --whitespace=fix (2)' '
254 '
255
256 test_expect_success 'blank at EOF with --whitespace=fix (3)' '
257 - { echo a; echo b; echo; } >one &&
257 + test_write_lines a b "" >one &&
258 git add one &&
259 - { echo a; echo c; echo; } >expect &&
260 - { cat expect; echo; echo; } >one &&
259 + test_write_lines a c "" >expect &&
260 + { cat expect && test_write_lines "" ""; } >one &&
261 git diff -- one >patch &&
262
263 git checkout one &&
@@ -266,9 +266,9 @@ test_expect_success 'blank at EOF with --whitespace=fix (3)' '
266 '
267
268 test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' '
269 - { echo a; echo b; echo; echo; echo; echo; echo; echo d; } >one &&
269 + test_write_lines a b "" "" "" "" "" d >one &&
270 git add one &&
271 - { echo a; echo c; echo; echo; echo; echo; echo; echo; echo d; } >expect &&
271 + test_write_lines a b "" "" "" "" "" "" d >expect &&
272 cp expect one &&
273 git diff -- one >patch &&
274
@@ -278,7 +278,7 @@ test_expect_success 'blank at end of hunk, not at EOF with --whitespace=fix' '
278 '
279
280 test_expect_success 'blank at EOF with --whitespace=warn' '
281 - { echo a; echo b; echo c; } >one &&
281 + test_write_lines a b c >one &&
282 git add one &&
283 echo >>one &&
284 cat one >expect &&
@@ -291,7 +291,7 @@ test_expect_success 'blank at EOF with --whitespace=warn' '
291 '
292
293 test_expect_success 'blank at EOF with --whitespace=error' '
294 - { echo a; echo b; echo c; } >one &&
294 + test_write_lines a b c >one &&
295 git add one &&
296 cat one >expect &&
297 echo >>one &&
@@ -304,7 +304,7 @@ test_expect_success 'blank at EOF with --whitespace=error' '
304 '
305
306 test_expect_success 'blank but not empty at EOF' '
307 - { echo a; echo b; echo c; } >one &&
307 + test_write_lines a b c >one &&
308 git add one &&
309 echo " " >>one &&
310 cat one >expect &&
@@ -317,13 +317,13 @@ test_expect_success 'blank but not empty at EOF' '
317 '
318
319 test_expect_success 'applying beyond EOF requires one non-blank context line' '
320 - { echo; echo; echo; echo; } >one &&
320 + test_write_lines "" "" "" "" >one &&
321 git add one &&
322 - { echo b; } >>one &&
322 + echo b >>one &&
323 git diff -- one >patch &&
324
325 git checkout one &&
326 - { echo a; echo; } >one &&
326 + test_write_lines a "" >one &&
327 cp one expect &&
328 test_must_fail git apply --whitespace=fix patch &&
329 test_cmp expect one &&
@@ -333,7 +333,7 @@ test_expect_success 'applying beyond EOF requires one non-blank context line' '
333
334 test_expect_success 'tons of blanks at EOF should not apply' '
335 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
336 - echo; echo; echo; echo;
336 + test_write_lines "" "" "" ""
337 done >one &&
338 git add one &&
339 echo a >>one &&
@@ -362,9 +362,9 @@ test_expect_success 'missing blank line at end with --whitespace=fix' '
362 '
363
364 test_expect_success 'two missing blank lines at end with --whitespace=fix' '
365 - { echo a; echo; echo b; echo c; } >one &&
365 + test_write_lines a "" b c >one &&
366 cp one no-blank-lines &&
367 - { echo; echo; } >>one &&
367 + test_write_lines "" "" >>one &&
368 git add one &&
369 echo d >>one &&
370 cp one expect &&
@@ -381,9 +381,9 @@ test_expect_success 'two missing blank lines at end with --whitespace=fix' '
381 '
382
383 test_expect_success 'missing blank line at end, insert before end, --whitespace=fix' '
384 - { echo a; echo; } >one &&
384 + test_write_lines a "" >one &&
385 git add one &&
386 - { echo b; echo a; echo; } >one &&
386 + test_write_lines b a "" >one &&
387 cp one expect &&
388 git diff -- one >patch &&
389 echo a >one &&
@@ -393,10 +393,10 @@ test_expect_success 'missing blank line at end, insert before end, --whitespace=
393 '
394
395 test_expect_success 'shrink file with tons of missing blanks at end of file' '
396 - { echo a; echo b; echo c; } >one &&
396 + test_write_lines a b c >one &&
397 cp one no-blank-lines &&
398 for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16; do
399 - echo; echo; echo; echo;
399 + test_write_lines "" "" "" ""
400 done >>one &&
401 git add one &&
402 echo a >one &&
@@ -412,9 +412,9 @@ test_expect_success 'shrink file with tons of missing blanks at end of file' '
412 '
413
414 test_expect_success 'missing blanks at EOF must only match blank lines' '
415 - { echo a; echo b; } >one &&
415 + test_write_lines a b >one &&
416 git add one &&
417 - { echo c; echo d; } >>one &&
417 + test_write_lines c d >>one &&
418 git diff -- one >patch &&
419
420 echo a >one &&
@@ -434,9 +434,9 @@ test_expect_success 'missing blank line should match context line with spaces' '
434 git add one &&
435 echo d >>one &&
436 git diff -- one >patch &&
437 - { echo a; echo b; echo c; } >one &&
437 + test_write_lines a b c >one &&
438 cp one expect &&
439 - { echo; echo d; } >>expect &&
439 + test_write_lines "" d >>expect &&
440 git add one &&
441
442 git apply --whitespace=fix patch &&
@@ -455,7 +455,7 @@ test_expect_success 'same, but with the --ignore-space-option' '
455 echo d >>one &&
456 cp one expect &&
457 git diff -- one >patch &&
458 - { echo a; echo b; echo c; } >one &&
458 + test_write_lines a b c >one &&
459 git add one &&
460
461 git checkout-index -f one &&
t/t4126-apply-empty.sh
+1 -4
@@ -9,10 +9,7 @@ test_expect_success setup '
9 git add empty &&
10 test_tick &&
11 git commit -m initial &&
12 - for i in a b c d e
13 - do
14 - echo $i
15 - done >empty &&
12 + test_write_lines a b c d e >empty &&
13 cat empty >expect &&
14 git diff |
15 sed -e "/^diff --git/d" \
t/t4127-apply-same-fn.sh
+1 -4
@@ -10,10 +10,7 @@ modify () {
10 }
11
12 test_expect_success setup '
13 - for i in a b c d e f g h i j k l m
14 - do
15 - echo $i
16 - done >same_fn &&
13 + test_write_lines a b c d e f g h i j k l m >same_fn &&
14 cp same_fn other_fn &&
15 git add same_fn other_fn &&
16 git commit -m initial
t/t4151-am-abort.sh
+2 -8
@@ -5,10 +5,7 @@ test_description='am --abort'
5 . ./test-lib.sh
6
7 test_expect_success setup '
8 - for i in a b c d e f g
9 - do
10 - echo $i
11 - done >file-1 &&
8 + test_write_lines a b c d e f g >file-1 &&
9 cp file-1 file-2 &&
10 test_tick &&
11 git add file-1 file-2 &&
@@ -43,10 +40,7 @@ do
40
41 test_must_fail git am$with3 000[1245]-*.patch &&
42 git log --pretty=tformat:%s >actual &&
46 - for i in 3 2 initial
47 - do
48 - echo $i
49 - done >expect &&
43 + test_write_lines 3 2 initial >expect &&
44 test_cmp expect actual
45 '
46
t/t5300-pack-object.sh
+2 -10
@@ -361,11 +361,7 @@ test_expect_success 'unpacking with --strict' '
361 ST=$(git write-tree) &&
362 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
363 PACK5=$( git pack-objects test-5 <actual ) &&
364 - PACK6=$( (
365 - echo "$LIST"
366 - echo "$LI"
367 - echo "$ST"
368 - ) | git pack-objects test-6 ) &&
364 + PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
365 test_create_repo test-5 &&
366 (
367 cd test-5 &&
@@ -408,11 +404,7 @@ test_expect_success 'index-pack with --strict' '
404 ST=$(git write-tree) &&
405 git rev-list --objects "$LIST" "$LI" "$ST" >actual &&
406 PACK5=$( git pack-objects test-5 <actual ) &&
411 - PACK6=$( (
412 - echo "$LIST"
413 - echo "$LI"
414 - echo "$ST"
415 - ) | git pack-objects test-6 ) &&
407 + PACK6=$( test_write_lines "$LIST" "$LI" "$ST" | git pack-objects test-6 ) &&
408 test_create_repo test-7 &&
409 (
410 cd test-7 &&
t/t5306-pack-nobase.sh
+1 -1
@@ -12,7 +12,7 @@ test_description='git-pack-object with missing base
12 #
13 test_expect_success \
14 'setup base' \
15 - 'for a in a b c d e f g h i; do echo $a >>text; done &&
15 + 'test_write_lines a b c d e f g h i >text &&
16 echo side >side &&
17 git update-index --add text side &&
18 A=$(echo A | git commit-tree $(git write-tree)) &&
t/t5611-clone-config.sh
+1 -1
@@ -17,7 +17,7 @@ test_expect_success 'clone -c sets config in cloned repo' '
17 test_expect_success 'clone -c can set multi-keys' '
18 rm -rf child &&
19 git clone -c core.foo=bar -c core.foo=baz . child &&
20 - { echo bar; echo baz; } >expect &&
20 + test_write_lines bar baz >expect &&
21 git --git-dir=child/.git config --get-all core.foo >actual &&
22 test_cmp expect actual
23 '
t/t6019-rev-list-ancestry-path.sh
+5 -5
@@ -51,7 +51,7 @@ test_expect_success setup '
51 '
52
53 test_expect_success 'rev-list D..M' '
54 - for c in E F G H I J K L M; do echo $c; done >expect &&
54 + test_write_lines E F G H I J K L M >expect &&
55 git rev-list --format=%s D..M |
56 sed -e "/^commit /d" |
57 sort >actual &&
@@ -59,7 +59,7 @@ test_expect_success 'rev-list D..M' '
59 '
60
61 test_expect_success 'rev-list --ancestry-path D..M' '
62 - for c in E F H I J L M; do echo $c; done >expect &&
62 + test_write_lines E F H I J L M >expect &&
63 git rev-list --ancestry-path --format=%s D..M |
64 sed -e "/^commit /d" |
65 sort >actual &&
@@ -81,7 +81,7 @@ test_expect_success 'rev-list --ancestry-path D..M -- M.t' '
81 '
82
83 test_expect_success 'rev-list F...I' '
84 - for c in F G H I; do echo $c; done >expect &&
84 + test_write_lines F G H I >expect &&
85 git rev-list --format=%s F...I |
86 sed -e "/^commit /d" |
87 sort >actual &&
@@ -89,7 +89,7 @@ test_expect_success 'rev-list F...I' '
89 '
90
91 test_expect_success 'rev-list --ancestry-path F...I' '
92 - for c in F H I; do echo $c; done >expect &&
92 + test_write_lines F H I >expect &&
93 git rev-list --ancestry-path --format=%s F...I |
94 sed -e "/^commit /d" |
95 sort >actual &&
@@ -111,7 +111,7 @@ test_expect_success 'rev-list --ancestry-path G..M -- G.t' '
111 '
112
113 test_expect_success 'rev-list --ancestry-path --simplify-merges G^..M -- G.t' '
114 - for c in G L; do echo $c; done >expect &&
114 + test_write_lines G L >expect &&
115 git rev-list --ancestry-path --simplify-merges --format=%s G^..M -- G.t |
116 sed -e "/^commit /d" |
117 sort >actual &&
t/t6060-merge-index.sh
+1 -3
@@ -4,9 +4,7 @@ test_description='basic git merge-index / git-merge-one-file tests'
4 . ./test-lib.sh
5
6 test_expect_success 'setup diverging branches' '
7 - for i in 1 2 3 4 5 6 7 8 9 10; do
8 - echo $i
9 - done >file &&
7 + test_write_lines 1 2 3 4 5 6 7 8 9 10 >file &&
8 git add file &&
9 git commit -m base &&
10 git tag base &&
t/t6409-merge-subtree.sh
+3 -3
@@ -10,7 +10,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
10 test_expect_success setup '
11
12 s="1 2 3 4 5 6 7 8" &&
13 - for i in $s; do echo $i; done >hello &&
13 + test_write_lines $s >hello &&
14 git add hello &&
15 git commit -m initial &&
16 git checkout -b side &&
@@ -18,7 +18,7 @@ test_expect_success setup '
18 git add hello &&
19 git commit -m second &&
20 git checkout main &&
21 - for i in mundo $s; do echo $i; done >hello &&
21 + test_write_lines mundo $s >hello &&
22 git add hello &&
23 git commit -m main
24
@@ -27,7 +27,7 @@ test_expect_success setup '
27 test_expect_success 'subtree available and works like recursive' '
28
29 git merge -s subtree side &&
30 - for i in mundo $s world; do echo $i; done >expect &&
30 + test_write_lines mundo $s world >expect &&
31 test_cmp expect hello
32
33 '
t/t6417-merge-ours-theirs.sh
+1 -4
@@ -7,10 +7,7 @@ export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7 . ./test-lib.sh
8
9 test_expect_success setup '
10 - for i in 1 2 3 4 5 6 7 8 9
11 - do
12 - echo "$i"
13 - done >file &&
10 + test_write_lines 1 2 3 4 5 6 7 8 9 >file &&
11 git add file &&
12 cp file elif &&
13 git commit -m initial &&
t/t7501-commit-basic-functionality.sh
+1 -4
@@ -667,10 +667,7 @@ test_expect_success 'amend can copy notes' '
667
668 test_expect_success 'commit a file whose name is a dash' '
669 git reset --hard &&
670 - for i in 1 2 3 4 5
671 - do
672 - echo $i
673 - done >./- &&
670 + test_write_lines 1 2 3 4 5 >./- &&
671 git add ./- &&
672 test_tick &&
673 git commit -m "add dash" >output </dev/null &&
t/t8003-blame-corner-cases.sh
+2 -8
@@ -13,14 +13,8 @@ test_expect_success setup '
13 echo B B B B B >two &&
14 echo C C C C C >tres &&
15 echo ABC >mouse &&
16 - for i in 1 2 3 4 5 6 7 8 9
17 - do
18 - echo $i
19 - done >nine_lines &&
20 - for i in 1 2 3 4 5 6 7 8 9 a
21 - do
22 - echo $i
23 - done >ten_lines &&
16 + test_write_lines 1 2 3 4 5 6 7 8 9 >nine_lines &&
17 + test_write_lines 1 2 3 4 5 6 7 8 9 a >ten_lines &&
18 git add one two tres mouse nine_lines ten_lines &&
19 test_tick &&
20 GIT_AUTHOR_NAME=Initial git commit -m Initial &&