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

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

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 7, 2026, 02:16 UTC
Message-ID
<xmqqechf8ryu.fsf@gitster.g>
In-Reply-To
<20260706205036.3453-1-gatlavishweshwarreddy26@gmail.com>
Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:
Show 27 quoted lines
> Piping git commands directly to wc -l suppresses the exit code of
> git, hiding potential failures from the test suite. Capture the
> output to a temporary file first, then count the lines separately
> to preserve the exit code.
>
> Signed-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>
> ---
>  t/t1410-reflog.sh | 29 +++++++++++++++++++++--------
>  1 file changed, 21 insertions(+), 8 deletions(-)
>
> diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh
> index ce71f9a30a..397f94b039 100755
> --- a/t/t1410-reflog.sh
> +++ b/t/t1410-reflog.sh
> @@ -244,8 +244,10 @@ test_expect_success 'delete' '
>  	test_tick &&
>  	git commit -m tiger C &&
>  
> -	HEAD_entry_count=$(git reflog | wc -l) &&
> -	main_entry_count=$(git reflog show main | wc -l) &&
> +	git reflog >reflog_output &&
> +	HEAD_entry_count=$(wc -l <reflog_output) &&
> +	git reflog show main >reflog_main_output &&
> +	main_entry_count=$(wc -l <reflog_main_output) &&
>  
>  	test $HEAD_entry_count = 5 &&
>  	test $main_entry_count = 5 &&

If you _know_ output from certain command must be 5 lines, would it make more sense to use test_stdout_line_count, perhaps like

	test_stdout_line_count = 5 git reflog
or something?
Show 27 quoted lines
> @@ -254,16 +256,23 @@ test_expect_success 'delete' '
>  	git reflog delete main@{1} &&
>  	git reflog show main > output &&
>  	test_line_count = $(($main_entry_count - 1)) output &&
> -	test $HEAD_entry_count = $(git reflog | wc -l) &&
> +	git reflog >reflog_output &&
> +	test $HEAD_entry_count = $(wc -l <reflog_output) &&
>  	! grep ox < output &&
>  
>  	main_entry_count=$(wc -l < output) &&
>  
>  	git reflog delete HEAD@{1} &&
> -	test $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&
> -	test $main_entry_count = $(git reflog show main | wc -l) &&
> +	git reflog >reflog_output &&
> +	test $(($HEAD_entry_count -1)) = $(wc -l <reflog_output) &&
> +	git reflog show main >reflog_main_output &&
> +	test $main_entry_count = $(wc -l <reflog_main_output) &&
> +
> +
> +	git reflog >reflog_output &&
> +	HEAD_entry_count=$(wc -l <reflog_output) &&
> +
>  
> -	HEAD_entry_count=$(git reflog | wc -l) &&
>  
>  	git reflog delete main@{07.04.2005.15:15:00.-0700} &&

Can you explain the addition of these consecutive blank lines? The same question applies to the blank lines at the end of the test in the next hunk. I ask because formatting issues like this often resemble unedited AI-generated code that hasn't been properly cleaned up before submission.

Show 19 quoted lines
>  	git reflog show main > output &&
> @@ -321,11 +330,15 @@ test_expect_success 'git reflog expire unknown reference' '
>  '
>  
>  test_expect_success 'checkout should not delete log for packed ref' '
> -	test $(git reflog main | wc -l) = 4 &&
> +	git reflog main >reflog_output &&
> +	test $(wc -l <reflog_output) = 4 &&
>  	git branch foo &&
>  	git pack-refs --all &&
>  	git checkout foo &&
> -	test $(git reflog main | wc -l) = 4
> +	git reflog main >reflog_output &&
> +	test $(wc -l <reflog_output) = 4
> +
> +
>  '
>  
>  test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '
Previous: Gatla Vishweshwar ReddyNext: Gatla Vishweshwar Reddy
Message 2 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.