git/list[1] front-page[2] threads[3] people[4] search[5] about
wed 2026-10-07 16:25 UTC

[GSoC PATCH 16/16] t2206: avoid suppressing git's exit code

From
Trieu Huynh <vikingtc4@gmail.com>
Date
Mar 28, 2026, 20:02 UTC
Message-ID
<20260328200255.247759-17-vikingtc4@gmail.com>
In-Reply-To
<20260328200255.247759-1-vikingtc4@gmail.com>

Update t2206-add-submodule-ignored.sh to redirect git-cmds output to a temporary file instead of piping it directly to not hide the exit code of git commands behind pipes, as a crash in git might go unnoticed.

Some tests run inside a subdirectory that is itself a git repo and use 'git add .' on the whole working tree, so the temporary file is written as '../actual' to keep it outside the inner repo and prevent it from being accidentally staged.

Signed-off-by: Trieu Huynh <vikingtc4@gmail.com>
---
 t/t2206-add-submodule-ignored.sh | 45 +++++++++++++++++++++-----------
 1 file changed, 30 insertions(+), 15 deletions(-)
diff --git a/t/t2206-add-submodule-ignored.sh b/t/t2206-add-submodule-ignored.sh
index e581e87ab2..7141012e50 100755
--- a/t/t2206-add-submodule-ignored.sh
+++ b/t/t2206-add-submodule-ignored.sh
@@ -45,9 +45,11 @@ test_expect_success 'main: add submodule with default config'  '
 	cd main &&
 	git submodule add ../sub &&
 	git commit -m "add submodule" &&
-	git log --oneline --name-only | grep "^sub$" &&
+	git log --oneline --name-only >actual &&
+	test_grep "^sub$" actual &&
 	git -C sub reset --hard v2.0 &&
-	git status --porcelain | grep "^ M sub$" &&
+	git status --porcelain >actual &&
+	test_grep "^ M sub$" actual &&
 	echo
 '
 #3
@@ -58,8 +60,10 @@ test_expect_success 'main: submodule config ignore=all'  '
 	git config -f .gitmodules submodule.sub.ignore all &&
 	GIT_TRACE=1 git add . &&
 	git commit -m "update submodule config sub.ignore all" &&
-	! git status --porcelain | grep "^.*$" &&
-	! git log --oneline --name-only | grep "^sub$" &&
+	git status --porcelain >../actual &&
+	test_must_be_empty ../actual &&
+	git log --oneline --name-only >../actual &&
+	test_grep ! "^sub$" ../actual &&
 	echo
 '
 #4
@@ -69,8 +73,10 @@ test_expect_success 'sub: change to different sha1 and check status in main'  '
 	cd "${base_path}" &&
 	cd main &&
 	git -C sub reset --hard v1.0 &&
-	! git status --porcelain | grep "^ M sub$" &&
-	git status --ignore-submodules=none --porcelain | grep "^ M sub$" &&
+	git status --porcelain >../actual &&
+	test_grep ! "^ M sub$" ../actual &&
+	git status --ignore-submodules=none --porcelain >../actual &&
+	test_grep "^ M sub$" ../actual &&
 	echo
 '
 
@@ -80,7 +86,8 @@ test_expect_success 'main: check normal add and status'  '
 	cd "${base_path}" &&
 	cd main &&
 	GIT_TRACE=1 git add . &&
-	! git status --porcelain | grep "^ M sub$" &&
+	git status --porcelain >../actual &&
+	test_grep ! "^ M sub$" ../actual &&
 	echo
 '
 
@@ -91,7 +98,8 @@ test_expect_success 'main: check --force add . and status'  '
 	cd "${base_path}" &&
 	cd main &&
 	GIT_TRACE=1 git add --force . &&
-	! git status --porcelain | grep "^M  sub$" &&
+	git status --porcelain >../actual &&
+	test_grep ! "^M  sub$" ../actual &&
 	echo
 '
 
@@ -101,8 +109,10 @@ test_expect_success 'main: check --force add . and status'  '
 test_expect_success 'main: check _add sub_ and status'  '
 	cd "${base_path}" &&
 	cd main &&
-	GIT_TRACE=1 git add sub 2>&1 | grep "Skipping submodule due to ignore=all: sub" &&
-	! git status --porcelain | grep "^M  sub$" &&
+	GIT_TRACE=1 git add sub >../actual 2>&1 &&
+	test_grep "Skipping submodule due to ignore=all: sub" ../actual &&
+	git status --porcelain >../actual &&
+	test_grep ! "^M  sub$" ../actual &&
 	echo
 '
 
@@ -118,15 +128,20 @@ test_expect_success 'main: check force add sub and ./sub/ and status'  '
 	cd main &&
 	echo "Adding with --force should work: git add --force sub" &&
 	GIT_TRACE=1 git add --force sub &&
-	git status --porcelain | grep "^M  sub$" &&
+	git status --porcelain >../actual &&
+	test_grep "^M  sub$" ../actual &&
 	git restore --staged sub &&
-	! git status --porcelain | grep "^M  sub$" &&
+	git status --porcelain >../actual &&
+	test_grep ! "^M  sub$" ../actual &&
 	echo "Adding with --force should work: git add --force ./sub/" &&
 	GIT_TRACE=1 git add --force ./sub/ &&
-	git status --porcelain | grep "^M  sub$" &&
+	git status --porcelain >../actual &&
+	test_grep "^M  sub$" ../actual &&
 	git commit -m "update submodule pointer" &&
-	! git status --porcelain | grep "^ M sub$" &&
-	git log --ignore-submodules=none --name-only --oneline | grep "^sub$" &&
+	git status --porcelain >../actual &&
+	test_grep ! "^ M sub$" ../actual &&
+	git log --ignore-submodules=none --name-only --oneline >../actual &&
+	test_grep "^sub$" ../actual &&
 	echo
 '
 
-- 
2.43.0
Previous: Trieu HuynhNext: Junio C Hamano
Message 17 of 24 in “Microproject: avoid suppressing git's exit code”
  1. 00/16 Microproject: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  2. 01/16 t7004: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  3. 02/16 t6423: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  4. 03/16 t6411: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  5. 04/16 t6101: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  6. 05/16 t6006: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  7. 06/16 t5304: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  8. 07/16 t4153: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  9. 08/16 t4150: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  10. 09/16 t4140: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  11. 10/16 t4039: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  12. 11/16 t3903: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  13. 12/16 t3701: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  14. 13/16 t3412: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  15. 14/16 t1400: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  16. 15/16 t0100: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  17. 16/16 t2206: avoid suppressing git's exit codeTrieu Huynh, Mar 28, 2026
  18. Junio C HamanoMar 29, 2026
  19. Trieu HuynhMar 29, 2026
  20. Tian YuchenMar 29, 2026
  21. Tian YuchenMar 29, 2026
  22. Karthik NayakMar 30, 2026
  23. Junio C HamanoMar 30, 2026
  24. Trieu HuynhMar 30, 2026

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.