Skip to contentSkip to conversation

t0100: avoid suppressing git exit code

PATCH In review amisha 2 participants 2 messages Jan 13 – Jan 14

lore
Share & tools
lore

amisha

author
#0 lore raw

PATCH 1/1 t0100: avoid suppressing git exit code

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.

---
 t/t0100-previous.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
t/t0100-previous.sh +2 -1
index dd5d9b4e5e..ffe3fda495 100755
@@ -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' '
Signature · 1 line
2.51.0
#1 lore raw

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

Quoted 32 lines · amisha

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.

---
 t/t0100-previous.sh | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
t/t0100-previous.sh +2 -2
index dd5d9b4e5e..ffe3fda495 100755
@@ -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