t3700: avoid suppressing git's exit code

Replace pipelines involving git commands with temporary files (actual) to ensure that any crashes or unexpected exit codes from the git commands are properly caught by the test suite. A simple pipeline like 'git foo | grep bar' ignores the exit code of 'git', which can hide regressions. In cases where we were counting lines with 'wc -l' to ensure a pattern was absent, simplify the logic to use '! grep' to avoid subshells entirely. Suggested-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Siddharth Shrimali committed Mar 4, 2026 at 02:10 UTC fc2ead0053d31735ac4a02c370c5c2b6dbaf2bbe
1 file changed +28 -15
t/t3700-add.sh
+28 -15
@@ -38,7 +38,8 @@ test_expect_success 'Test with no pathspecs' '
38 '
39
40 test_expect_success 'Post-check that foo is in the index' '
41 - git ls-files foo | grep foo
41 + git ls-files foo >actual &&
42 + grep foo actual
43 '
44
45 test_expect_success 'Test that "git add -- -q" works' '
@@ -195,8 +196,9 @@ test_expect_success 'git add with filemode=0, symlinks=0, and unmerged entries'
196 echo new > file &&
197 echo new > symlink &&
198 git add file symlink &&
198 - git ls-files --stage | grep "^100755 .* 0 file$" &&
199 - git ls-files --stage | grep "^120000 .* 0 symlink$"
199 + git ls-files --stage >actual &&
200 + grep "^100755 .* 0 file$" actual &&
201 + grep "^120000 .* 0 symlink$" actual
202 '
203
204 test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over stage 1' '
@@ -212,8 +214,9 @@ test_expect_success 'git add with filemode=0, symlinks=0 prefers stage 2 over st
214 echo new > file &&
215 echo new > symlink &&
216 git add file symlink &&
215 - git ls-files --stage | grep "^100755 .* 0 file$" &&
216 - git ls-files --stage | grep "^120000 .* 0 symlink$"
217 + git ls-files --stage >actual &&
218 + grep "^100755 .* 0 file$" actual &&
219 + grep "^120000 .* 0 symlink$" actual
220 '
221
222 test_expect_success 'git add --refresh' '
@@ -254,7 +257,8 @@ test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unr
257 date >foo2 &&
258 chmod 0 foo2 &&
259 test_must_fail git add --verbose . &&
257 - ! ( git ls-files foo1 | grep foo1 )
260 + git ls-files foo1 >actual &&
261 + ! grep foo1 actual
262 '
263
264 rm -f foo2
@@ -265,7 +269,8 @@ test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
269 date >foo2 &&
270 chmod 0 foo2 &&
271 test_must_fail git add --verbose --ignore-errors . &&
268 - git ls-files foo1 | grep foo1
272 + git ls-files foo1 >actual &&
273 + grep foo1 actual
274 '
275
276 rm -f foo2
@@ -277,7 +282,8 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
282 date >foo2 &&
283 chmod 0 foo2 &&
284 test_must_fail git add --verbose . &&
280 - git ls-files foo1 | grep foo1
285 + git ls-files foo1 >actual &&
286 + grep foo1 actual
287 '
288 rm -f foo2
289
@@ -288,7 +294,8 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
294 date >foo2 &&
295 chmod 0 foo2 &&
296 test_must_fail git add --verbose . &&
291 - ! ( git ls-files foo1 | grep foo1 )
297 + git ls-files foo1 >actual &&
298 + ! grep foo1 actual
299 '
300 rm -f foo2
301
@@ -299,7 +306,8 @@ test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
306 date >foo2 &&
307 chmod 0 foo2 &&
308 test_must_fail git add --verbose --no-ignore-errors . &&
302 - ! ( git ls-files foo1 | grep foo1 ) &&
309 + git ls-files foo1 >actual &&
310 + ! grep foo1 actual &&
311 git config add.ignore-errors 0
312 '
313 rm -f foo2
@@ -308,8 +316,10 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
316 git reset --hard &&
317 touch fo\[ou\]bar foobar &&
318 git add '\''fo\[ou\]bar'\'' &&
311 - git ls-files fo\[ou\]bar | grep -F fo\[ou\]bar &&
312 - ! ( git ls-files foobar | grep foobar )
319 + git ls-files fo\[ou\]bar >actual &&
320 + grep -F fo\[ou\]bar actual &&
321 + git ls-files foobar >actual &&
322 + ! grep foobar actual
323 '
324
325 test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
@@ -326,7 +336,8 @@ test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
336
337 test_expect_success '"add non-existent" should fail' '
338 test_must_fail git add non-existent &&
329 - ! (git ls-files | grep "non-existent")
339 + git ls-files >actual &&
340 + ! grep "non-existent" actual
341 '
342
343 test_expect_success 'git add -A on empty repo does not error out' '
@@ -536,9 +547,11 @@ test_expect_success 'all statuses changed in folder if . is given' '
547 touch x y z sub/a sub/dir/b &&
548 git add -A &&
549 git add --chmod=+x . &&
539 - test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 &&
550 + git ls-files --stage >actual &&
551 + ! grep ^100644 actual &&
552 git add --chmod=-x . &&
541 - test $(git ls-files --stage | grep ^100755 | wc -l) -eq 0
553 + git ls-files --stage >actual &&
554 + ! grep ^100755 actual
555 )
556 '
557