t6402: preserve git exit status code
In t6402, we're checking number of files in the index and the working tree by piping the output of Git's command to "wc -l", thus losing the exit status code of git. Let's use the new helper test_stdout_line_count in order to preserve Git's exit status code. Signed-off-by: Đoàn Trần Công Danh <congdanhqx@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Đoàn Trần Công Danh committed
Jul 4, 2021 at 12:46 UTC
ba8c2680ec996160ae16750b48e4cc10c537bdd3
1 file changed
+64
-68
t/t6402-merge-rename.sh
+64
-68
@@ -105,10 +105,8 @@ test_expect_success 'pull renaming branch into unrenaming one' \
105
git show-branch &&
106
test_expect_code 1 git pull . white &&
107
git ls-files -s &&
108
- git ls-files -u B >b.stages &&
109
- test_line_count = 3 b.stages &&
110
- git ls-files -s N >n.stages &&
111
- test_line_count = 1 n.stages &&
108
+ test_stdout_line_count = 3 git ls-files -u B &&
109
+ test_stdout_line_count = 1 git ls-files -s N &&
110
sed -ne "/^g/{
111
p
112
q
@@ -122,10 +120,8 @@ test_expect_success 'pull renaming branch into another renaming one' \
120
git reset --hard &&
121
git checkout red &&
122
test_expect_code 1 git pull . white &&
125
- git ls-files -u B >b.stages &&
126
- test_line_count = 3 b.stages &&
127
- git ls-files -s N >n.stages &&
128
- test_line_count = 1 n.stages &&
123
+ test_stdout_line_count = 3 git ls-files -u B &&
124
+ test_stdout_line_count = 1 git ls-files -s N &&
125
sed -ne "/^g/{
126
p
127
q
@@ -138,10 +134,8 @@ test_expect_success 'pull unrenaming branch into renaming one' \
134
git reset --hard &&
135
git show-branch &&
136
test_expect_code 1 git pull . main &&
141
- git ls-files -u B >b.stages &&
142
- test_line_count = 3 b.stages &&
143
- git ls-files -s N >n.stages &&
144
- test_line_count = 1 n.stages &&
137
+ test_stdout_line_count = 3 git ls-files -u B &&
138
+ test_stdout_line_count = 1 git ls-files -s N &&
139
sed -ne "/^g/{
140
p
141
q
@@ -154,14 +148,10 @@ test_expect_success 'pull conflicting renames' \
148
git reset --hard &&
149
git show-branch &&
150
test_expect_code 1 git pull . blue &&
157
- git ls-files -u A >a.stages &&
158
- test_line_count = 1 a.stages &&
159
- git ls-files -u B >b.stages &&
160
- test_line_count = 1 b.stages &&
161
- git ls-files -u C >c.stages &&
162
- test_line_count = 1 c.stages &&
163
- git ls-files -s N >n.stages &&
164
- test_line_count = 1 n.stages &&
151
+ test_stdout_line_count = 1 git ls-files -u A &&
152
+ test_stdout_line_count = 1 git ls-files -u B &&
153
+ test_stdout_line_count = 1 git ls-files -u C &&
154
+ test_stdout_line_count = 1 git ls-files -s N &&
155
sed -ne "/^g/{
156
p
157
q
@@ -330,8 +320,8 @@ test_expect_success 'Rename+D/F conflict; renamed file merges but dir in way' '
320
test_i18ngrep "Adding as dir~HEAD instead" output
321
fi &&
322
333
- test 3 -eq "$(git ls-files -u | wc -l)" &&
334
- test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
323
+ test_stdout_line_count = 3 git ls-files -u &&
324
+ test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
325
326
test_must_fail git diff --quiet &&
327
test_must_fail git diff --cached --quiet &&
@@ -357,8 +347,8 @@ test_expect_success 'Same as previous, but merged other way' '
347
test_i18ngrep "Adding as dir~renamed-file-has-no-conflicts instead" output
348
fi &&
349
360
- test 3 -eq "$(git ls-files -u | wc -l)" &&
361
- test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
350
+ test_stdout_line_count = 3 git ls-files -u &&
351
+ test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
352
353
test_must_fail git diff --quiet &&
354
test_must_fail git diff --cached --quiet &&
@@ -374,8 +364,8 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge, dir not in
364
git checkout -q renamed-file-has-conflicts^0 &&
365
test_must_fail git merge --strategy=recursive dir-not-in-way &&
366
377
- test 3 -eq "$(git ls-files -u | wc -l)" &&
378
- test 3 -eq "$(git ls-files -u dir | wc -l)" &&
367
+ test_stdout_line_count = 3 git ls-files -u &&
368
+ test_stdout_line_count = 3 git ls-files -u dir &&
369
370
test_must_fail git diff --quiet &&
371
test_must_fail git diff --cached --quiet &&
@@ -409,14 +399,16 @@ test_expect_success 'Rename+D/F conflict; renamed file cannot merge and dir in t
399
git checkout -q renamed-file-has-conflicts^0 &&
400
test_must_fail git merge --strategy=recursive dir-in-way &&
401
412
- test 5 -eq "$(git ls-files -u | wc -l)" &&
402
+ test_stdout_line_count = 5 git ls-files -u &&
403
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
404
then
415
- test 3 -eq "$(git ls-files -u dir~HEAD | wc -l)"
405
+ test_stdout_line_count = 3 git ls-files -u dir~HEAD
406
else
417
- test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
407
+ git ls-files -u dir >out &&
408
+ test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
409
+ rm -f out
410
fi &&
419
- test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
411
+ test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
412
413
test_must_fail git diff --quiet &&
414
test_must_fail git diff --cached --quiet &&
@@ -432,14 +424,16 @@ test_expect_success 'Same as previous, but merged other way' '
424
git checkout -q dir-in-way^0 &&
425
test_must_fail git merge --strategy=recursive renamed-file-has-conflicts &&
426
435
- test 5 -eq "$(git ls-files -u | wc -l)" &&
427
+ test_stdout_line_count = 5 git ls-files -u &&
428
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
429
then
438
- test 3 -eq "$(git ls-files -u dir~renamed-file-has-conflicts | wc -l)"
430
+ test_stdout_line_count = 3 git ls-files -u dir~renamed-file-has-conflicts
431
else
440
- test 3 -eq "$(git ls-files -u dir | grep -v file-in-the-way | wc -l)"
432
+ git ls-files -u dir >out &&
433
+ test 3 -eq $(grep -v file-in-the-way out | wc -l) &&
434
+ rm -f out
435
fi &&
442
- test 2 -eq "$(git ls-files -u dir/file-in-the-way | wc -l)" &&
436
+ test_stdout_line_count = 2 git ls-files -u dir/file-in-the-way &&
437
438
test_must_fail git diff --quiet &&
439
test_must_fail git diff --cached --quiet &&
@@ -496,9 +490,9 @@ test_expect_success 'both rename source and destination involved in D/F conflict
490
491
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
492
then
499
- test 2 -eq "$(git ls-files -u | wc -l)"
493
+ test_stdout_line_count = 2 git ls-files -u
494
else
501
- test 1 -eq "$(git ls-files -u | wc -l)"
495
+ test_stdout_line_count = 1 git ls-files -u
496
fi &&
497
498
test_must_fail git diff --quiet &&
@@ -540,9 +534,9 @@ then
534
mkdir one &&
535
test_must_fail git merge --strategy=recursive rename-two &&
536
543
- test 4 -eq "$(git ls-files -u | wc -l)" &&
544
- test 2 -eq "$(git ls-files -u one | wc -l)" &&
545
- test 2 -eq "$(git ls-files -u two | wc -l)" &&
537
+ test_stdout_line_count = 4 git ls-files -u &&
538
+ test_stdout_line_count = 2 git ls-files -u one &&
539
+ test_stdout_line_count = 2 git ls-files -u two &&
540
541
test_must_fail git diff --quiet &&
542
@@ -559,9 +553,9 @@ else
553
mkdir one &&
554
test_must_fail git merge --strategy=recursive rename-two &&
555
562
- test 2 -eq "$(git ls-files -u | wc -l)" &&
563
- test 1 -eq "$(git ls-files -u one | wc -l)" &&
564
- test 1 -eq "$(git ls-files -u two | wc -l)" &&
556
+ test_stdout_line_count = 2 git ls-files -u &&
557
+ test_stdout_line_count = 1 git ls-files -u one &&
558
+ test_stdout_line_count = 1 git ls-files -u two &&
559
560
test_must_fail git diff --quiet &&
561
@@ -582,13 +576,13 @@ test_expect_success 'pair rename to parent of other (D/F conflicts) w/ clean sta
576
577
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
578
then
585
- test 4 -eq "$(git ls-files -u | wc -l)" &&
586
- test 2 -eq "$(git ls-files -u one | wc -l)" &&
587
- test 2 -eq "$(git ls-files -u two | wc -l)"
579
+ test_stdout_line_count = 4 git ls-files -u &&
580
+ test_stdout_line_count = 2 git ls-files -u one &&
581
+ test_stdout_line_count = 2 git ls-files -u two
582
else
589
- test 2 -eq "$(git ls-files -u | wc -l)" &&
590
- test 1 -eq "$(git ls-files -u one | wc -l)" &&
591
- test 1 -eq "$(git ls-files -u two | wc -l)"
583
+ test_stdout_line_count = 2 git ls-files -u &&
584
+ test_stdout_line_count = 1 git ls-files -u one &&
585
+ test_stdout_line_count = 1 git ls-files -u two
586
fi &&
587
588
test_must_fail git diff --quiet &&
@@ -631,19 +625,19 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
625
626
if test "$GIT_TEST_MERGE_ALGORITHM" = ort
627
then
634
- test 5 -eq "$(git ls-files -s | wc -l)" &&
635
- test 3 -eq "$(git ls-files -u | wc -l)" &&
636
- test 1 -eq "$(git ls-files -u one~HEAD | wc -l)" &&
637
- test 1 -eq "$(git ls-files -u two~second-rename | wc -l)" &&
638
- test 1 -eq "$(git ls-files -u original | wc -l)" &&
639
- test 0 -eq "$(git ls-files -o | wc -l)"
628
+ test_stdout_line_count = 5 git ls-files -s &&
629
+ test_stdout_line_count = 3 git ls-files -u &&
630
+ test_stdout_line_count = 1 git ls-files -u one~HEAD &&
631
+ test_stdout_line_count = 1 git ls-files -u two~second-rename &&
632
+ test_stdout_line_count = 1 git ls-files -u original &&
633
+ test_stdout_line_count = 0 git ls-files -o
634
else
641
- test 5 -eq "$(git ls-files -s | wc -l)" &&
642
- test 3 -eq "$(git ls-files -u | wc -l)" &&
643
- test 1 -eq "$(git ls-files -u one | wc -l)" &&
644
- test 1 -eq "$(git ls-files -u two | wc -l)" &&
645
- test 1 -eq "$(git ls-files -u original | wc -l)" &&
646
- test 2 -eq "$(git ls-files -o | wc -l)"
635
+ test_stdout_line_count = 5 git ls-files -s &&
636
+ test_stdout_line_count = 3 git ls-files -u &&
637
+ test_stdout_line_count = 1 git ls-files -u one &&
638
+ test_stdout_line_count = 1 git ls-files -u two &&
639
+ test_stdout_line_count = 1 git ls-files -u original &&
640
+ test_stdout_line_count = 2 git ls-files -o
641
fi &&
642
643
test_path_is_file one/file &&
@@ -679,11 +673,11 @@ test_expect_success 'check handling of differently renamed file with D/F conflic
673
git checkout -q first-rename-redo^0 &&
674
test_must_fail git merge --strategy=recursive second-rename-redo &&
675
682
- test 3 -eq "$(git ls-files -u | wc -l)" &&
683
- test 1 -eq "$(git ls-files -u one | wc -l)" &&
684
- test 1 -eq "$(git ls-files -u two | wc -l)" &&
685
- test 1 -eq "$(git ls-files -u original | wc -l)" &&
686
- test 0 -eq "$(git ls-files -o | wc -l)" &&
676
+ test_stdout_line_count = 3 git ls-files -u &&
677
+ test_stdout_line_count = 1 git ls-files -u one &&
678
+ test_stdout_line_count = 1 git ls-files -u two &&
679
+ test_stdout_line_count = 1 git ls-files -u original &&
680
+ test_stdout_line_count = 0 git ls-files -o &&
681
682
test_path_is_file one &&
683
test_path_is_file two &&
@@ -861,9 +855,11 @@ test_expect_success 'setup merge of rename + small change' '
855
test_expect_success 'merge rename + small change' '
856
git merge rename_branch &&
857
864
- test 1 -eq $(git ls-files -s | wc -l) &&
865
- test 0 -eq $(git ls-files -o | wc -l) &&
866
- test $(git rev-parse HEAD:renamed_file) = $(git rev-parse HEAD~1:file)
858
+ test_stdout_line_count = 1 git ls-files -s &&
859
+ test_stdout_line_count = 0 git ls-files -o &&
860
+ newhash=$(git rev-parse HEAD:renamed_file) &&
861
+ oldhash=$(git rev-parse HEAD~1:file) &&
862
+ test $newhash = $oldhash
863
'
864
865
test_expect_success 'setup for use of extended merge markers' '