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

Re: [PATCH v3] t1410-reflog.sh: avoid suppressing git's exit code in pipelines

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 8, 2026, 20:41 UTC
Message-ID
<xmqqv7aprz8a.fsf@gitster.g>
In-Reply-To
<20260708092448.35776-1-gatlavishweshwarreddy26@gmail.com>
Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:
> Piping git commands directly to wc -l suppresses the exit code of
> git, hiding potential failures from the test suite.
Correct.
> Capture the
> output to a temporary file first, then count the lines separately
> to preserve the exit code. Where the expected count is known ahead
> of time, use test_stdout_line_count instead.

Technically, the description is not telling any lies about the solution, but the patch no longer does the caputuring or counting itself at all. Rather, it exclusively uses test_stdout_line_count, which internally does the saving to a temporary and counting the lines ;-)

The changes in the patch are mostly good, except for the loss of a blank line that separates two test pieces in the last hunk (below).

Show 16 quoted lines
> @@ -319,13 +311,12 @@ test_expect_success 'git reflog expire unknown reference' '
>  	test_must_fail git reflog expire does-not-exist 2>stderr &&
>  	test_grep "error: reflog could not be found: ${SQ}does-not-exist${SQ}" stderr
>  '
> -
>  test_expect_success 'checkout should not delete log for packed ref' '
> -	test $(git reflog main | wc -l) = 4 &&
> +	test_stdout_line_count = 4 git reflog main &&
>  	git branch foo &&
>  	git pack-refs --all &&
>  	git checkout foo &&
> -	test $(git reflog main | wc -l) = 4
> +	test_stdout_line_count = 4 git reflog main
>  '
>
>  test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '
Thanks.
Previous: Gatla Vishweshwar ReddyNext: Gatla Vishweshwar Reddy
Message 6 of 8 in “t1410-reflog.sh: avoid suppressing git's exit code in pipelines”
  1. t1410-reflog.sh: avoid suppressing git's exit code in pipelinesGatla Vishweshwar Reddy, Jul 6, 2026
  2. Junio C HamanoJul 7, 2026
  3. t1410-reflog.sh: avoid suppressing git's exit code in pipelinesGatla Vishweshwar Reddy, Jul 7, 2026
  4. Junio C HamanoJul 8, 2026
  5. t1410-reflog.sh: avoid suppressing git's exit code in pipelinesGatla Vishweshwar Reddy, Jul 8, 2026
  6. Junio C HamanoJul 8, 2026
  7. t1410-reflog.sh: avoid suppressing git's exit code in pipelinesGatla Vishweshwar Reddy, Jul 9, 2026
  8. Junio C HamanoJul 9, 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.