t3404: avoid losing exit status with focus on `git show` and `git cat-file`

The exit code of the preceding command in a pipe is disregarded. So if that preceding command is a Git command that fails, the test would not fail. Instead, by saving the output of that Git command to a file, and removing the pipe, we make sure the test will fail if that Git command fails. This particular patch focuses on all `git show` and some instances of `git cat-file`. Signed-off-by: Usman Akinyemi <usmanakinyemi202@gmail.com> Signed-off-by: Taylor Blau <me@ttaylorr.com>

Usman Akinyemi committed Oct 12, 2024 at 23:09 UTC c8fbae25c338b28143e79b253f12567ea48fcbb3
1 file changed +48 -23
t/t3404-rebase-interactive.sh
+48 -23
@@ -319,7 +319,8 @@ test_expect_success 'retain authorship' '
319 GIT_AUTHOR_NAME="Twerp Snog" git commit -m "different author" &&
320 git tag twerp &&
321 git rebase -i --onto primary HEAD^ &&
322 - git show HEAD | grep "^Author: Twerp Snog"
322 + git show HEAD >actual &&
323 + grep "^Author: Twerp Snog" actual
324 '
325
326 test_expect_success 'retain authorship w/ conflicts' '
@@ -360,7 +361,8 @@ test_expect_success 'squash' '
361 '
362
363 test_expect_success 'retain authorship when squashing' '
363 - git show HEAD | grep "^Author: Twerp Snog"
364 + git show HEAD >actual &&
365 + grep "^Author: Twerp Snog" actual
366 '
367
368 test_expect_success '--continue tries to commit' '
@@ -374,7 +376,8 @@ test_expect_success '--continue tries to commit' '
376 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
377 ) &&
378 test_cmp_rev HEAD^ new-branch1 &&
377 - git show HEAD | grep chouette
379 + git show HEAD >actual &&
380 + grep chouette actual
381 '
382
383 test_expect_success 'verbose flag is heeded, even after --continue' '
@@ -397,7 +400,9 @@ test_expect_success 'multi-squash only fires up editor once' '
400 git rebase -i $base
401 ) &&
402 test $base = $(git rev-parse HEAD^) &&
400 - test 1 = $(git show | grep ONCE | wc -l)
403 + git show >output &&
404 + count=$(grep ONCE output | wc -l) &&
405 + test 1 = $count
406 '
407
408 test_expect_success 'multi-fixup does not fire up editor' '
@@ -410,7 +415,9 @@ test_expect_success 'multi-fixup does not fire up editor' '
415 git rebase -i $base
416 ) &&
417 test $base = $(git rev-parse HEAD^) &&
413 - test 0 = $(git show | grep NEVER | wc -l) &&
418 + git show >output &&
419 + count=$(grep NEVER output | wc -l) &&
420 + test 0 = $count &&
421 git checkout @{-1} &&
422 git branch -D multi-fixup
423 '
@@ -428,7 +435,9 @@ test_expect_success 'commit message used after conflict' '
435 git rebase --continue
436 ) &&
437 test $base = $(git rev-parse HEAD^) &&
431 - test 1 = $(git show | grep ONCE | wc -l) &&
438 + git show >output &&
439 + count=$(grep ONCE output | wc -l) &&
440 + test 1 = $count &&
441 git checkout @{-1} &&
442 git branch -D conflict-fixup
443 '
@@ -446,7 +455,9 @@ test_expect_success 'commit message retained after conflict' '
455 git rebase --continue
456 ) &&
457 test $base = $(git rev-parse HEAD^) &&
449 - test 2 = $(git show | grep TWICE | wc -l) &&
458 + git show >output &&
459 + count=$(grep TWICE output | wc -l) &&
460 + test 2 = $count &&
461 git checkout @{-1} &&
462 git branch -D conflict-squash
463 '
@@ -470,10 +481,10 @@ test_expect_success 'squash and fixup generate correct log messages' '
481 ) &&
482 git cat-file commit HEAD | sed -e 1,/^\$/d > actual-squash-fixup &&
483 test_cmp expect-squash-fixup actual-squash-fixup &&
473 - git cat-file commit HEAD@{2} |
474 - grep "^# This is a combination of 3 commits\." &&
475 - git cat-file commit HEAD@{3} |
476 - grep "^# This is a combination of 2 commits\." &&
484 + git cat-file commit HEAD@{2} >actual &&
485 + grep "^# This is a combination of 3 commits\." actual &&
486 + git cat-file commit HEAD@{3} >actual &&
487 + grep "^# This is a combination of 2 commits\." actual &&
488 git checkout @{-1} &&
489 git branch -D squash-fixup
490 '
@@ -489,7 +500,9 @@ test_expect_success 'squash ignores comments' '
500 git rebase -i $base
501 ) &&
502 test $base = $(git rev-parse HEAD^) &&
492 - test 1 = $(git show | grep ONCE | wc -l) &&
503 + git show >output &&
504 + count=$(grep ONCE output | wc -l) &&
505 + test 1 = $count &&
506 git checkout @{-1} &&
507 git branch -D skip-comments
508 '
@@ -505,7 +518,9 @@ test_expect_success 'squash ignores blank lines' '
518 git rebase -i $base
519 ) &&
520 test $base = $(git rev-parse HEAD^) &&
508 - test 1 = $(git show | grep ONCE | wc -l) &&
521 + git show >output &&
522 + count=$(grep ONCE output | wc -l) &&
523 + test 1 = $count &&
524 git checkout @{-1} &&
525 git branch -D skip-blank-lines
526 '
@@ -572,7 +587,8 @@ test_expect_success '--continue tries to commit, even for "edit"' '
587 FAKE_COMMIT_MESSAGE="chouette!" git rebase --continue
588 ) &&
589 test edited = $(git show HEAD:file7) &&
575 - git show HEAD | grep chouette &&
590 + git show HEAD >actual &&
591 + grep chouette actual &&
592 test $parent = $(git rev-parse HEAD^)
593 '
594
@@ -757,19 +773,23 @@ test_expect_success 'reword' '
773 set_fake_editor &&
774 FAKE_LINES="1 2 3 reword 4" FAKE_COMMIT_MESSAGE="E changed" \
775 git rebase -i A &&
760 - git show HEAD | grep "E changed" &&
776 + git show HEAD >actual &&
777 + grep "E changed" actual &&
778 test $(git rev-parse primary) != $(git rev-parse HEAD) &&
779 test_cmp_rev primary^ HEAD^ &&
780 FAKE_LINES="1 2 reword 3 4" FAKE_COMMIT_MESSAGE="D changed" \
781 git rebase -i A &&
765 - git show HEAD^ | grep "D changed" &&
782 + git show HEAD^ >actual &&
783 + grep "D changed" actual &&
784 FAKE_LINES="reword 1 2 3 4" FAKE_COMMIT_MESSAGE="B changed" \
785 git rebase -i A &&
768 - git show HEAD~3 | grep "B changed" &&
786 + git show HEAD~3 >actual &&
787 + grep "B changed" actual &&
788 FAKE_LINES="1 r 2 pick 3 p 4" FAKE_COMMIT_MESSAGE="C changed" \
789 git rebase -i A
790 ) &&
772 - git show HEAD~2 | grep "C changed"
791 + git show HEAD~2 >actual &&
792 + grep "C changed" actual
793 '
794
795 test_expect_success 'no uncommitted changes when rewording and the todo list is reloaded' '
@@ -1003,8 +1023,10 @@ test_expect_success 'rebase -i --root retain root commit author and message' '
1023 set_fake_editor &&
1024 FAKE_LINES="2" git rebase -i --root
1025 ) &&
1006 - git cat-file commit HEAD | grep -q "^author Twerp Snog" &&
1007 - git cat-file commit HEAD | grep -q "^different author$"
1026 + git cat-file commit HEAD >output &&
1027 + grep -q "^author Twerp Snog" output &&
1028 + git cat-file commit HEAD >actual &&
1029 + grep -q "^different author$" actual
1030 '
1031
1032 test_expect_success 'rebase -i --root temporary sentinel commit' '
@@ -1013,7 +1035,8 @@ test_expect_success 'rebase -i --root temporary sentinel commit' '
1035 set_fake_editor &&
1036 test_must_fail env FAKE_LINES="2" git rebase -i --root
1037 ) &&
1016 - git cat-file commit HEAD | grep "^tree $EMPTY_TREE" &&
1038 + git cat-file commit HEAD >actual &&
1039 + grep "^tree $EMPTY_TREE" actual &&
1040 git rebase --abort
1041 '
1042
@@ -1036,7 +1059,8 @@ test_expect_success 'rebase -i --root reword original root commit' '
1059 FAKE_LINES="reword 1 2" FAKE_COMMIT_MESSAGE="A changed" \
1060 git rebase -i --root
1061 ) &&
1039 - git show HEAD^ | grep "A changed" &&
1062 + git show HEAD^ >actual &&
1063 + grep "A changed" actual &&
1064 test -z "$(git show -s --format=%p HEAD^)"
1065 '
1066
@@ -1048,7 +1072,8 @@ test_expect_success 'rebase -i --root reword new root commit' '
1072 FAKE_LINES="reword 3 1" FAKE_COMMIT_MESSAGE="C changed" \
1073 git rebase -i --root
1074 ) &&
1051 - git show HEAD^ | grep "C changed" &&
1075 + git show HEAD^ >actual &&
1076 + grep "C changed" actual &&
1077 test -z "$(git show -s --format=%p HEAD^)"
1078 '
1079