git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH] t3700: avoid suppressing git's exit code

From
Junio C Hamano <gitster@pobox.com>
Date
Feb 27, 2026, 18:19 UTC
Message-ID
<xmqqv7fiqcaj.fsf@gitster.g>
In-Reply-To
<20260227165143.70188-1-r.siddharth.shrimali@gmail.com>
Siddharth Shrimali <r.siddharth.shrimali@gmail.com> writes:
Show 11 quoted lines
> 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(-)
A few things that I noticed.
 * If "git foo | grep bar" was expecting to hide exit code from
   "git" and check the output (e.g., "git diff --exit-code | grep foo"),
   a mechanical conversion "git diff --exit-code >out && grep foo out"
   would change the meaning of the test and break it.  I did not check
   if this patch has such an unintended breakage, though.
 * Many of them do this:
        > -	git ls-files foo | grep foo
        > +	git ls-files foo >actual &&
        > +	grep foo <actual
   or this
        > -	! ( git ls-files foo1 | grep foo1 )
        > +	git ls-files foo1 >actual &&
        > +	! grep foo1 actual
    in which we might consider using "test_grep" (and "test_grep !")
    to help the developer who wants to debug a breakage in ls-files
    by highlighting what is unexpected in the output in their broken
    version.
 * A rewrite like this may want to be further broken down.
        > -	test $(git ls-files --stage | grep ^100644 | wc -l) -eq 0 &&
        > +	test $(git ls-files --stage >actual && grep ^100644 actual | wc -l) -eq 0 &&
   If "ls-files --stage" segfaults, "grep | wc" would not run, $()
   may exit with non-zero and turn into an empty string, but the
   final error diagnosis would be something unfathonable like
	test: -eq unary operator expected
	test: missing argument after '0'
   
   which would not help the person debugging the test very much.
Previous: Siddharth ShrimaliNext: Siddharth Shrimali
Message 2 of 6 in “t3700: avoid suppressing git's exit code”
  1. t3700: avoid suppressing git's exit codeSiddharth Shrimali, Feb 27, 2026
  2. Junio C HamanoFeb 27, 2026
  3. t3700: avoid hidden failures and use test_grep helperSiddharth Shrimali, Feb 28, 2026
  4. Junio C HamanoMar 2, 2026
  5. Johannes SixtFeb 28, 2026
  6. Siddharth ShrimaliFeb 28, 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.