t7610-mergetool: use test_cmp instead of test $(cat file) = $txt
Fix that anti-pattern by a sequence of echo and test_cmp. The patch was generated with this command: sed -i -e '/test.*(cat/s/^\(\t*\)test "..cat \(.*\))" = \(".*"\)\(.*\)/\1echo \3 >expect \&\&\n\1test_cmp expect \2\4/' t7610-mergetool.sh This helps on Windows, where test_cmp avoids spawning a process when there is no difference. Signed-off-by: Johannes Sixt <j6t@kdbg.org> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Johannes Sixt committed
Jun 12, 2019 at 18:33 UTC
e10dffd067002ea83c5293c9440adc5f23825110
1 file changed
+90
-45
t/t7610-mergetool.sh
+90
-45
@@ -138,10 +138,14 @@ test_expect_success 'custom mergetool' '
138
yes "d" | git mergetool file11 &&
139
yes "d" | git mergetool file12 &&
140
yes "l" | git mergetool submod &&
141
- test "$(cat file1)" = "master updated" &&
142
- test "$(cat file2)" = "master new" &&
143
- test "$(cat subdir/file3)" = "master new sub" &&
144
- test "$(cat submod/bar)" = "branch1 submodule" &&
141
+ echo "master updated" >expect &&
142
+ test_cmp expect file1 &&
143
+ echo "master new" >expect &&
144
+ test_cmp expect file2 &&
145
+ echo "master new sub" >expect &&
146
+ test_cmp expect subdir/file3 &&
147
+ echo "branch1 submodule" >expect &&
148
+ test_cmp expect submod/bar &&
149
git commit -m "branch1 resolved with mergetool"
150
'
151
@@ -160,10 +164,14 @@ test_expect_success 'gui mergetool' '
164
yes "d" | git mergetool --gui file11 &&
165
yes "d" | git mergetool --gui file12 &&
166
yes "l" | git mergetool --gui submod &&
163
- test "$(cat file1)" = "gui master updated" &&
164
- test "$(cat file2)" = "gui master new" &&
165
- test "$(cat subdir/file3)" = "gui master new sub" &&
166
- test "$(cat submod/bar)" = "branch1 submodule" &&
167
+ echo "gui master updated" >expect &&
168
+ test_cmp expect file1 &&
169
+ echo "gui master new" >expect &&
170
+ test_cmp expect file2 &&
171
+ echo "gui master new sub" >expect &&
172
+ test_cmp expect subdir/file3 &&
173
+ echo "branch1 submodule" >expect &&
174
+ test_cmp expect submod/bar &&
175
git commit -m "branch1 resolved with mergetool"
176
'
177
@@ -179,10 +187,14 @@ test_expect_success 'gui mergetool without merge.guitool set falls back to merge
187
yes "d" | git mergetool --gui file11 &&
188
yes "d" | git mergetool --gui file12 &&
189
yes "l" | git mergetool --gui submod &&
182
- test "$(cat file1)" = "master updated" &&
183
- test "$(cat file2)" = "master new" &&
184
- test "$(cat subdir/file3)" = "master new sub" &&
185
- test "$(cat submod/bar)" = "branch1 submodule" &&
190
+ echo "master updated" >expect &&
191
+ test_cmp expect file1 &&
192
+ echo "master new" >expect &&
193
+ test_cmp expect file2 &&
194
+ echo "master new sub" >expect &&
195
+ test_cmp expect subdir/file3 &&
196
+ echo "branch1 submodule" >expect &&
197
+ test_cmp expect submod/bar &&
198
git commit -m "branch1 resolved with mergetool"
199
'
200
@@ -207,7 +219,8 @@ test_expect_success 'mergetool crlf' '
219
test "$(printf x | cat file2 -)" = "$(printf "master new\r\nx")" &&
220
test "$(printf x | cat subdir/file3 -)" = "$(printf "master new sub\r\nx")" &&
221
git submodule update -N &&
210
- test "$(cat submod/bar)" = "master submodule" &&
222
+ echo "master submodule" >expect &&
223
+ test_cmp expect submod/bar &&
224
git commit -m "branch1 resolved with mergetool - autocrlf"
225
'
226
@@ -219,7 +232,8 @@ test_expect_success 'mergetool in subdir' '
232
cd subdir &&
233
test_must_fail git merge master &&
234
yes "" | git mergetool file3 &&
222
- test "$(cat file3)" = "master new sub"
235
+ echo "master new sub" >expect &&
236
+ test_cmp expect file3
237
)
238
'
239
@@ -237,9 +251,12 @@ test_expect_success 'mergetool on file in parent dir' '
251
yes "d" | git mergetool ../file11 &&
252
yes "d" | git mergetool ../file12 &&
253
yes "l" | git mergetool ../submod &&
240
- test "$(cat ../file1)" = "master updated" &&
241
- test "$(cat ../file2)" = "master new" &&
242
- test "$(cat ../submod/bar)" = "branch1 submodule" &&
254
+ echo "master updated" >expect &&
255
+ test_cmp expect ../file1 &&
256
+ echo "master new" >expect &&
257
+ test_cmp expect ../file2 &&
258
+ echo "branch1 submodule" >expect &&
259
+ test_cmp expect ../submod/bar &&
260
git commit -m "branch1 resolved with mergetool - subdir"
261
)
262
'
@@ -266,11 +283,15 @@ test_expect_success 'mergetool merges all from subdir (rerere disabled)' '
283
test_must_fail git merge master &&
284
yes "r" | git mergetool ../submod &&
285
yes "d" "d" | git mergetool --no-prompt &&
269
- test "$(cat ../file1)" = "master updated" &&
270
- test "$(cat ../file2)" = "master new" &&
271
- test "$(cat file3)" = "master new sub" &&
286
+ echo "master updated" >expect &&
287
+ test_cmp expect ../file1 &&
288
+ echo "master new" >expect &&
289
+ test_cmp expect ../file2 &&
290
+ echo "master new sub" >expect &&
291
+ test_cmp expect file3 &&
292
( cd .. && git submodule update -N ) &&
273
- test "$(cat ../submod/bar)" = "master submodule" &&
293
+ echo "master submodule" >expect &&
294
+ test_cmp expect ../submod/bar &&
295
git commit -m "branch2 resolved by mergetool from subdir"
296
)
297
'
@@ -285,11 +306,15 @@ test_expect_success 'mergetool merges all from subdir (rerere enabled)' '
306
test_must_fail git merge master &&
307
yes "r" | git mergetool ../submod &&
308
yes "d" "d" | git mergetool --no-prompt &&
288
- test "$(cat ../file1)" = "master updated" &&
289
- test "$(cat ../file2)" = "master new" &&
290
- test "$(cat file3)" = "master new sub" &&
309
+ echo "master updated" >expect &&
310
+ test_cmp expect ../file1 &&
311
+ echo "master new" >expect &&
312
+ test_cmp expect ../file2 &&
313
+ echo "master new sub" >expect &&
314
+ test_cmp expect file3 &&
315
( cd .. && git submodule update -N ) &&
292
- test "$(cat ../submod/bar)" = "master submodule" &&
316
+ echo "master submodule" >expect &&
317
+ test_cmp expect ../submod/bar &&
318
git commit -m "branch2 resolved by mergetool from subdir"
319
)
320
'
@@ -345,7 +370,8 @@ test_expect_success 'mergetool takes partial path' '
370
371
yes "" | git mergetool subdir &&
372
348
- test "$(cat subdir/file3)" = "master new sub"
373
+ echo "master new sub" >expect &&
374
+ test_cmp expect subdir/file3
375
'
376
377
test_expect_success 'mergetool delete/delete conflict' '
@@ -415,9 +441,11 @@ test_expect_success 'deleted vs modified submodule' '
441
yes "d" | git mergetool file11 file12 &&
442
yes "r" | git mergetool submod &&
443
rmdir submod && mv submod-movedaside submod &&
418
- test "$(cat submod/bar)" = "branch1 submodule" &&
444
+ echo "branch1 submodule" >expect &&
445
+ test_cmp expect submod/bar &&
446
git submodule update -N &&
420
- test "$(cat submod/bar)" = "master submodule" &&
447
+ echo "master submodule" >expect &&
448
+ test_cmp expect submod/bar &&
449
output="$(git mergetool --no-prompt)" &&
450
test "$output" = "No files need merging" &&
451
git commit -m "Merge resolved by keeping module" &&
@@ -461,9 +489,11 @@ test_expect_success 'deleted vs modified submodule' '
489
yes "" | git mergetool both &&
490
yes "d" | git mergetool file11 file12 &&
491
yes "l" | git mergetool submod &&
464
- test "$(cat submod/bar)" = "master submodule" &&
492
+ echo "master submodule" >expect &&
493
+ test_cmp expect submod/bar &&
494
git submodule update -N &&
466
- test "$(cat submod/bar)" = "master submodule" &&
495
+ echo "master submodule" >expect &&
496
+ test_cmp expect submod/bar &&
497
output="$(git mergetool --no-prompt)" &&
498
test "$output" = "No files need merging" &&
499
git commit -m "Merge resolved by keeping module"
@@ -486,9 +516,11 @@ test_expect_success 'file vs modified submodule' '
516
yes "d" | git mergetool file11 file12 &&
517
yes "r" | git mergetool submod &&
518
rmdir submod && mv submod-movedaside submod &&
489
- test "$(cat submod/bar)" = "branch1 submodule" &&
519
+ echo "branch1 submodule" >expect &&
520
+ test_cmp expect submod/bar &&
521
git submodule update -N &&
491
- test "$(cat submod/bar)" = "master submodule" &&
522
+ echo "master submodule" >expect &&
523
+ test_cmp expect submod/bar &&
524
output="$(git mergetool --no-prompt)" &&
525
test "$output" = "No files need merging" &&
526
git commit -m "Merge resolved by keeping module" &&
@@ -502,7 +534,8 @@ test_expect_success 'file vs modified submodule' '
534
yes "d" | git mergetool file11 file12 &&
535
yes "l" | git mergetool submod &&
536
git submodule update -N &&
505
- test "$(cat submod)" = "not a submodule" &&
537
+ echo "not a submodule" >expect &&
538
+ test_cmp expect submod &&
539
output="$(git mergetool --no-prompt)" &&
540
test "$output" = "No files need merging" &&
541
git commit -m "Merge resolved by keeping file" &&
@@ -519,7 +552,8 @@ test_expect_success 'file vs modified submodule' '
552
yes "r" | git mergetool submod &&
553
test -d submod.orig &&
554
git submodule update -N &&
522
- test "$(cat submod)" = "not a submodule" &&
555
+ echo "not a submodule" >expect &&
556
+ test_cmp expect submod &&
557
output="$(git mergetool --no-prompt)" &&
558
test "$output" = "No files need merging" &&
559
git commit -m "Merge resolved by keeping file" &&
@@ -533,9 +567,11 @@ test_expect_success 'file vs modified submodule' '
567
yes "" | git mergetool both &&
568
yes "d" | git mergetool file11 file12 &&
569
yes "l" | git mergetool submod &&
536
- test "$(cat submod/bar)" = "master submodule" &&
570
+ echo "master submodule" >expect &&
571
+ test_cmp expect submod/bar &&
572
git submodule update -N &&
538
- test "$(cat submod/bar)" = "master submodule" &&
573
+ echo "master submodule" >expect &&
574
+ test_cmp expect submod/bar &&
575
output="$(git mergetool --no-prompt)" &&
576
test "$output" = "No files need merging" &&
577
git commit -m "Merge resolved by keeping module"
@@ -589,17 +625,21 @@ test_expect_success 'submodule in subdirectory' '
625
cd subdir &&
626
yes "l" | git mergetool subdir_module
627
) &&
592
- test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
628
+ echo "test$test_count.b" >expect &&
629
+ test_cmp expect subdir/subdir_module/file15 &&
630
git submodule update -N &&
594
- test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
631
+ echo "test$test_count.b" >expect &&
632
+ test_cmp expect subdir/subdir_module/file15 &&
633
git reset --hard &&
634
git submodule update -N &&
635
636
test_must_fail git merge test$test_count.a &&
637
yes "r" | git mergetool subdir/subdir_module &&
600
- test "$(cat subdir/subdir_module/file15)" = "test$test_count.b" &&
638
+ echo "test$test_count.b" >expect &&
639
+ test_cmp expect subdir/subdir_module/file15 &&
640
git submodule update -N &&
602
- test "$(cat subdir/subdir_module/file15)" = "test$test_count.a" &&
641
+ echo "test$test_count.a" >expect &&
642
+ test_cmp expect subdir/subdir_module/file15 &&
643
git commit -m "branch1 resolved with mergetool"
644
'
645
@@ -616,7 +656,8 @@ test_expect_success 'directory vs modified submodule' '
656
test_must_fail git merge master &&
657
test -n "$(git ls-files -u)" &&
658
yes "l" | git mergetool submod &&
619
- test "$(cat submod/file16)" = "not a submodule" &&
659
+ echo "not a submodule" >expect &&
660
+ test_cmp expect submod/file16 &&
661
rm -rf submod.orig &&
662
663
git reset --hard &&
@@ -625,12 +666,14 @@ test_expect_success 'directory vs modified submodule' '
666
test ! -e submod.orig &&
667
yes "r" | git mergetool submod &&
668
test -d submod.orig &&
628
- test "$(cat submod.orig/file16)" = "not a submodule" &&
669
+ echo "not a submodule" >expect &&
670
+ test_cmp expect submod.orig/file16 &&
671
rm -r submod.orig &&
672
mv submod-movedaside/.git submod &&
673
( cd submod && git clean -f && git reset --hard ) &&
674
git submodule update -N &&
633
- test "$(cat submod/bar)" = "master submodule" &&
675
+ echo "master submodule" >expect &&
676
+ test_cmp expect submod/bar &&
677
git reset --hard &&
678
rm -rf submod-movedaside &&
679
@@ -640,7 +683,8 @@ test_expect_success 'directory vs modified submodule' '
683
test -n "$(git ls-files -u)" &&
684
yes "l" | git mergetool submod &&
685
git submodule update -N &&
643
- test "$(cat submod/bar)" = "master submodule" &&
686
+ echo "master submodule" >expect &&
687
+ test_cmp expect submod/bar &&
688
689
git reset --hard &&
690
git submodule update -N &&
@@ -648,7 +692,8 @@ test_expect_success 'directory vs modified submodule' '
692
test -n "$(git ls-files -u)" &&
693
test ! -e submod.orig &&
694
yes "r" | git mergetool submod &&
651
- test "$(cat submod/file16)" = "not a submodule" &&
695
+ echo "not a submodule" >expect &&
696
+ test_cmp expect submod/file16 &&
697
698
git reset --hard master &&
699
( cd submod && git clean -f && git reset --hard ) &&