t2400: avoid losing exit status to pipes

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. Signed-off-by: Achu Luma <ach.lumap@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Achu Luma committed Jan 20, 2024 at 03:15 UTC 425ae8a3df3d2378e8da5a96b995f8fc0fac32e8
1 file changed +4 -2
t/t2400-worktree-add.sh
+4 -2
@@ -490,7 +490,8 @@ test_expect_success 'put a worktree under rebase' '
490 cd under-rebase &&
491 set_fake_editor &&
492 FAKE_LINES="edit 1" git rebase -i HEAD^ &&
493 - git worktree list | grep "under-rebase.*detached HEAD"
493 + git worktree list >actual &&
494 + grep "under-rebase.*detached HEAD" actual
495 )
496 '
497
@@ -531,7 +532,8 @@ test_expect_success 'checkout a branch under bisect' '
532 git bisect start &&
533 git bisect bad &&
534 git bisect good HEAD~2 &&
534 - git worktree list | grep "under-bisect.*detached HEAD" &&
535 + git worktree list >actual &&
536 + grep "under-bisect.*detached HEAD" actual &&
537 test_must_fail git worktree add new-bisect under-bisect &&
538 ! test -d new-bisect
539 )