public inbox for git@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] t3700: avoid suppressing git's exit code
@ 2026-02-27 16:51 Siddharth Shrimali
  2026-02-27 18:19 ` Junio C Hamano
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Siddharth Shrimali @ 2026-02-27 16:51 UTC (permalink / raw)
  To: git; +Cc: peff, r.siddharth.shrimali

When piping the output of git ls-files into grep, the exit code of
git ls-files is suppressed.

Avoid this by redirecting the output of git ls-files to a file and
then running grep on that file. This ensures that any crash in
git ls-files will be caught by the test suite.

Signed-off-by: Siddharth Shrimali <r.siddharth.shrimali@gmail.com>
---
 t/t3700-add.sh | 38 +++++++++++++++++++++++---------------
 1 file changed, 23 insertions(+), 15 deletions(-)

diff --git a/t/t3700-add.sh b/t/t3700-add.sh
index af93e53c12..66c6114b54 100755
--- a/t/t3700-add.sh
+++ b/t/t3700-add.sh
@@ -38,7 +38,8 @@ test_expect_success 'Test with no pathspecs' '
 '
 
 test_expect_success 'Post-check that foo is in the index' '
-	git ls-files foo | grep foo
+	git ls-files foo >actual &&
+	grep foo <actual
 '
 
 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'
 	echo new > file &&
 	echo new > symlink &&
 	git add file symlink &&
-	git ls-files --stage | grep "^100755 .* 0	file$" &&
-	git ls-files --stage | grep "^120000 .* 0	symlink$"
+	git ls-files --stage >actual &&
+	grep "^100755 .* 0	file$" <actual &&
+	grep "^120000 .* 0	symlink$" actual
 '
 
 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
 	echo new > file &&
 	echo new > symlink &&
 	git add file symlink &&
-	git ls-files --stage | grep "^100755 .* 0	file$" &&
-	git ls-files --stage | grep "^120000 .* 0	symlink$"
+	git ls-files --stage >actual &&
+	grep "^100755 .* 0	file$" actual &&
+	grep "^120000 .* 0	symlink$" actual
 '
 
 test_expect_success 'git add --refresh' '
@@ -254,7 +257,8 @@ test_expect_success POSIXPERM,SANITY 'git add should fail atomically upon an unr
 	date >foo2 &&
 	chmod 0 foo2 &&
 	test_must_fail git add --verbose . &&
-	! ( git ls-files foo1 | grep foo1 )
+	git ls-files foo1 >actual &&
+	! grep foo1 actual
 '
 
 rm -f foo2
@@ -265,7 +269,7 @@ test_expect_success POSIXPERM,SANITY 'git add --ignore-errors' '
 	date >foo2 &&
 	chmod 0 foo2 &&
 	test_must_fail git add --verbose --ignore-errors . &&
-	git ls-files foo1 | grep foo1
+	git ls-files foo1 >actual && grep foo1 actual
 '
 
 rm -f foo2
@@ -277,7 +281,7 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors)' '
 	date >foo2 &&
 	chmod 0 foo2 &&
 	test_must_fail git add --verbose . &&
-	git ls-files foo1 | grep foo1
+	git ls-files foo1 >actual && grep foo1 actual
 '
 rm -f foo2
 
@@ -288,7 +292,8 @@ test_expect_success POSIXPERM,SANITY 'git add (add.ignore-errors = false)' '
 	date >foo2 &&
 	chmod 0 foo2 &&
 	test_must_fail git add --verbose . &&
-	! ( git ls-files foo1 | grep foo1 )
+	git ls-files foo1 >actual &&
+	! grep foo1 actual
 '
 rm -f foo2
 
@@ -299,7 +304,8 @@ test_expect_success POSIXPERM,SANITY '--no-ignore-errors overrides config' '
 	date >foo2 &&
 	chmod 0 foo2 &&
 	test_must_fail git add --verbose --no-ignore-errors . &&
-	! ( git ls-files foo1 | grep foo1 ) &&
+	git ls-files foo1 >actual &&
+	! grep foo1 actual &&
 	git config add.ignore-errors 0
 '
 rm -f foo2
@@ -309,7 +315,8 @@ test_expect_success BSLASHPSPEC "git add 'fo\\[ou\\]bar' ignores foobar" '
 	touch fo\[ou\]bar foobar &&
 	git add '\''fo\[ou\]bar'\'' &&
 	git ls-files fo\[ou\]bar | grep -F fo\[ou\]bar &&
-	! ( git ls-files foobar | grep foobar )
+	git ls-files foobar >actual &&
+	! grep foobar actual
 '
 
 test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
@@ -326,7 +333,8 @@ test_expect_success 'git add to resolve conflicts on otherwise ignored path' '
 
 test_expect_success '"add non-existent" should fail' '
 	test_must_fail git add non-existent &&
-	! (git ls-files | grep "non-existent")
+	git ls-files >actual &&
+	! grep "non-existent" actual 
 '
 
 test_expect_success 'git add -A on empty repo does not error out' '
@@ -536,9 +544,9 @@ test_expect_success 'all statuses changed in folder if . is given' '
 		touch x y z sub/a sub/dir/b &&
 		git add -A &&
 		git add --chmod=+x . &&
-		test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 &&
+		test $(git ls-files --stage >actual && grep ^100644 actual | wc -l) -eq 0 &&
 		git add --chmod=-x . &&
-		test $(git ls-files --stage | grep ^100755 | wc -l) -eq 0
+		test $(git ls-files --stage >actual && grep ^100755 actual | wc -l) -eq 0
 	)
 '
 
@@ -574,4 +582,4 @@ test_expect_success CASE_INSENSITIVE_FS 'path is case-insensitive' '
 	git add "$downcased"
 '
 
-test_done
+test_done
\ No newline at end of file
-- 
2.51.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-03-02 21:24 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-02-27 16:51 [PATCH] t3700: avoid suppressing git's exit code Siddharth Shrimali
2026-02-27 18:19 ` Junio C Hamano
2026-02-28  7:00 ` [PATCH v2] t3700: avoid hidden failures and use test_grep helper Siddharth Shrimali
2026-03-02 21:24   ` Junio C Hamano
2026-02-28  8:12 ` [PATCH] t3700: avoid suppressing git's exit code Johannes Sixt
2026-02-28 10:15   ` Siddharth Shrimali

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox