# [PATCH] t0100: avoid suppressing git exit code

2 messages from 2026-01-13 to 2026-01-14. Participants: amisha, Pushkar Singh.
Thread: https://gitlist.dev/t/64794

## amisha, 2026-01-13 18:04

Subject: [PATCH] t0100: avoid suppressing git exit code
Message-ID: <20260113180409.36683-1-amishhhaaaa@gmail.com>
URL: https://gitlist.dev/e/20260113180409.36683-1-amishhhaaaa%40gmail.com

```
In t0100-previous.sh, the exit code of 'git cat-file' is suppressed by
piping it directly into grep. If git crashes, the test might not
notice.

Redirect the output of git to a temporary file 'actual' and grep
from that file instead. This ensures that the exit code of the
git command is properly checked.

Signed-off-by: amisha <amishhhaaaa@gmail.com>
---
 t/t0100-previous.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/t/t0100-previous.sh b/t/t0100-previous.sh
index dd5d9b4e5e..ffe3fda495 100755
--- a/t/t0100-previous.sh
+++ b/t/t0100-previous.sh
@@ -40,7 +40,8 @@ test_expect_success 'merge @{-1}' '
 	git checkout other &&
 	git checkout main &&
 	git merge @{-1} &&
-	git cat-file commit HEAD | grep "Merge branch '\''other'\''"
+	git cat-file commit HEAD >actual &&
+	grep "Merge branch '\''other'\''" actual
 '
 
 test_expect_success 'merge @{-1}~1' '
-- 
2.51.0


```

## Pushkar Singh, 2026-01-14 14:23

Subject: Re: [PATCH] t0100: avoid suppressing git exit code
Message-ID: <CALE2CrQFZngj6_NDuf0S=_-nDrrf6b6r=C9jMyEVjwMqvh6J2w@mail.gmail.com>
URL: https://gitlist.dev/e/CALE2CrQFZngj6_NDuf0S%3D_-nDrrf6b6r%3DC9jMyEVjwMqvh6J2w%40mail.gmail.com
In-Reply-To: <20260113180409.36683-1-amishhhaaaa@gmail.com>

```
Hi Amisha,

Thanks for the patch. This makes sense, since piping into grep was indeed
suppressing the exit status of git cat-file.

One small style suggestion. Most Git tests use the helper instead of raw
grep, so this could be written as:

    git cat-file commit HEAD >actual &&
    test_grep "Merge branch 'other'" actual

This gives nicer diagnostics on failure and is consistent with other
tests.

Other than that, the approach looks good to me.

Thanks,
Pushkar

On Tue, Jan 13, 2026 at 11:34 PM amisha <amishhhaaaa@gmail.com> wrote:
>
> In t0100-previous.sh, the exit code of 'git cat-file' is suppressed by
> piping it directly into grep. If git crashes, the test might not
> notice.
>
> Redirect the output of git to a temporary file 'actual' and grep
> from that file instead. This ensures that the exit code of the
> git command is properly checked.
>
> Signed-off-by: amisha <amishhhaaaa@gmail.com>
> ---
>  t/t0100-previous.sh | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/t/t0100-previous.sh b/t/t0100-previous.sh
> index dd5d9b4e5e..ffe3fda495 100755
> --- a/t/t0100-previous.sh
> +++ b/t/t0100-previous.sh
> @@ -40,7 +40,8 @@ test_expect_success 'merge @{-1}' '
>         git checkout other &&
>         git checkout main &&
>         git merge @{-1} &&
> -       git cat-file commit HEAD | grep "Merge branch '\''other'\''"
> +       git cat-file commit HEAD >actual &&
> +       grep "Merge branch '\''other'\''" actual
>  '
>
>  test_expect_success 'merge @{-1}~1' '
> --
> 2.51.0
>
>

```
