{"thread":{"id":"65937","subject":"[PATCH] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","startedAt":"2026-07-06T20:50:47Z","lastAt":"2026-07-09T16:38:08Z","messageCount":8,"participants":["Gatla Vishweshwar Reddy","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"547269","messageId":"20260706205036.3453-1-gatlavishweshwarreddy26@gmail.com","threadId":"65937","inReplyTo":null,"subject":"[PATCH] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Gatla Vishweshwar Reddy","fromEmail":"gatlavishweshwarreddy26@gmail.com","sentAt":"2026-07-06T20:50:36Z","receivedAt":"2026-07-06T20:50:47Z","isPatch":true,"body":"Piping git commands directly to wc -l suppresses the exit code of\ngit, hiding potential failures from the test suite. Capture the\noutput to a temporary file first, then count the lines separately\nto preserve the exit code.\n\nSigned-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n---\n t/t1410-reflog.sh | 29 +++++++++++++++++++++--------\n 1 file changed, 21 insertions(+), 8 deletions(-)\n\ndiff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\nindex ce71f9a30a..397f94b039 100755\n--- a/t/t1410-reflog.sh\n+++ b/t/t1410-reflog.sh\n@@ -244,8 +244,10 @@ test_expect_success 'delete' '\n \ttest_tick &&\n \tgit commit -m tiger C &&\n \n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n-\tmain_entry_count=$(git reflog show main | wc -l) &&\n+\tgit reflog >reflog_output &&\n+\tHEAD_entry_count=$(wc -l <reflog_output) &&\n+\tgit reflog show main >reflog_main_output &&\n+\tmain_entry_count=$(wc -l <reflog_main_output) &&\n \n \ttest $HEAD_entry_count = 5 &&\n \ttest $main_entry_count = 5 &&\n@@ -254,16 +256,23 @@ test_expect_success 'delete' '\n \tgit reflog delete main@{1} &&\n \tgit reflog show main > output &&\n \ttest_line_count = $(($main_entry_count - 1)) output &&\n-\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n+\tgit reflog >reflog_output &&\n+\ttest $HEAD_entry_count = $(wc -l <reflog_output) &&\n \t! grep ox < output &&\n \n \tmain_entry_count=$(wc -l < output) &&\n \n \tgit reflog delete HEAD@{1} &&\n-\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n-\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n+\tgit reflog >reflog_output &&\n+\ttest $(($HEAD_entry_count -1)) = $(wc -l <reflog_output) &&\n+\tgit reflog show main >reflog_main_output &&\n+\ttest $main_entry_count = $(wc -l <reflog_main_output) &&\n+\n+\n+\tgit reflog >reflog_output &&\n+\tHEAD_entry_count=$(wc -l <reflog_output) &&\n+\n \n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n \n \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n \tgit reflog show main > output &&\n@@ -321,11 +330,15 @@ test_expect_success 'git reflog expire unknown reference' '\n '\n \n test_expect_success 'checkout should not delete log for packed ref' '\n-\ttest $(git reflog main | wc -l) = 4 &&\n+\tgit reflog main >reflog_output &&\n+\ttest $(wc -l <reflog_output) = 4 &&\n \tgit branch foo &&\n \tgit pack-refs --all &&\n \tgit checkout foo &&\n-\ttest $(git reflog main | wc -l) = 4\n+\tgit reflog main >reflog_output &&\n+\ttest $(wc -l <reflog_output) = 4\n+\n+\n '\n \n test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n-- \n2.54.0\n\n"},{"id":"547280","messageId":"xmqqechf8ryu.fsf@gitster.g","threadId":"65937","inReplyTo":"20260706205036.3453-1-gatlavishweshwarreddy26@gmail.com","subject":"Re: [PATCH] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-07T02:16:09Z","receivedAt":"2026-07-07T02:16:11Z","isPatch":true,"body":"Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:\n\n> Piping git commands directly to wc -l suppresses the exit code of\n> git, hiding potential failures from the test suite. Capture the\n> output to a temporary file first, then count the lines separately\n> to preserve the exit code.\n>\n> Signed-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n> ---\n>  t/t1410-reflog.sh | 29 +++++++++++++++++++++--------\n>  1 file changed, 21 insertions(+), 8 deletions(-)\n>\n> diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\n> index ce71f9a30a..397f94b039 100755\n> --- a/t/t1410-reflog.sh\n> +++ b/t/t1410-reflog.sh\n> @@ -244,8 +244,10 @@ test_expect_success 'delete' '\n>  \ttest_tick &&\n>  \tgit commit -m tiger C &&\n>  \n> -\tHEAD_entry_count=$(git reflog | wc -l) &&\n> -\tmain_entry_count=$(git reflog show main | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\tHEAD_entry_count=$(wc -l <reflog_output) &&\n> +\tgit reflog show main >reflog_main_output &&\n> +\tmain_entry_count=$(wc -l <reflog_main_output) &&\n>  \n>  \ttest $HEAD_entry_count = 5 &&\n>  \ttest $main_entry_count = 5 &&\n\nIf you _know_ output from certain command must be 5 lines, would it\nmake more sense to use test_stdout_line_count, perhaps like\n\n\ttest_stdout_line_count = 5 git reflog\n\nor something?\n\n> @@ -254,16 +256,23 @@ test_expect_success 'delete' '\n>  \tgit reflog delete main@{1} &&\n>  \tgit reflog show main > output &&\n>  \ttest_line_count = $(($main_entry_count - 1)) output &&\n> -\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\ttest $HEAD_entry_count = $(wc -l <reflog_output) &&\n>  \t! grep ox < output &&\n>  \n>  \tmain_entry_count=$(wc -l < output) &&\n>  \n>  \tgit reflog delete HEAD@{1} &&\n> -\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n> -\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\ttest $(($HEAD_entry_count -1)) = $(wc -l <reflog_output) &&\n> +\tgit reflog show main >reflog_main_output &&\n> +\ttest $main_entry_count = $(wc -l <reflog_main_output) &&\n> +\n> +\n> +\tgit reflog >reflog_output &&\n> +\tHEAD_entry_count=$(wc -l <reflog_output) &&\n> +\n>  \n> -\tHEAD_entry_count=$(git reflog | wc -l) &&\n>  \n>  \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n\nCan you explain the addition of these consecutive blank lines? The\nsame question applies to the blank lines at the end of the test in\nthe next hunk. I ask because formatting issues like this often\nresemble unedited AI-generated code that hasn't been properly\ncleaned up before submission.\n\n>  \tgit reflog show main > output &&\n> @@ -321,11 +330,15 @@ test_expect_success 'git reflog expire unknown reference' '\n>  '\n>  \n>  test_expect_success 'checkout should not delete log for packed ref' '\n> -\ttest $(git reflog main | wc -l) = 4 &&\n> +\tgit reflog main >reflog_output &&\n> +\ttest $(wc -l <reflog_output) = 4 &&\n>  \tgit branch foo &&\n>  \tgit pack-refs --all &&\n>  \tgit checkout foo &&\n> -\ttest $(git reflog main | wc -l) = 4\n> +\tgit reflog main >reflog_output &&\n> +\ttest $(wc -l <reflog_output) = 4\n> +\n> +\n>  '\n>  \n>  test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n"},{"id":"547327","messageId":"20260707135530.17389-1-gatlavishweshwarreddy26@gmail.com","threadId":"65937","inReplyTo":"xmqqechf8ryu.fsf@gitster.g","subject":"[PATCH v2] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Gatla Vishweshwar Reddy","fromEmail":"gatlavishweshwarreddy26@gmail.com","sentAt":"2026-07-07T13:55:30Z","receivedAt":"2026-07-07T13:55:40Z","isPatch":true,"body":"Piping git commands directly to wc -l suppresses the exit code of\ngit, hiding potential failures from the test suite. Capture the\noutput to a temporary file first, then count the lines separately\nto preserve the exit code. Where the expected count is known ahead\nof time, use test_stdout_line_count instead.\n\nSigned-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n---\n t/t1410-reflog.sh | 29 ++++++++++++++++-------------\n 1 file changed, 16 insertions(+), 13 deletions(-)\n\ndiff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\nindex ce71f9a30a..8e018d172b 100755\n--- a/t/t1410-reflog.sh\n+++ b/t/t1410-reflog.sh\n@@ -244,26 +244,30 @@ test_expect_success 'delete' '\n \ttest_tick &&\n \tgit commit -m tiger C &&\n \n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n-\tmain_entry_count=$(git reflog show main | wc -l) &&\n-\n-\ttest $HEAD_entry_count = 5 &&\n-\ttest $main_entry_count = 5 &&\n-\n+\ttest_stdout_line_count = 5 git reflog &&\n+\tgit reflog >reflog_output &&\n+\tHEAD_entry_count=$(wc -l <reflog_output) &&\n+\ttest_stdout_line_count = 5 git reflog show main &&\n+\tgit reflog show main >reflog_main_output &&\n+\tmain_entry_count=$(wc -l <reflog_main_output) &&\n \n \tgit reflog delete main@{1} &&\n \tgit reflog show main > output &&\n \ttest_line_count = $(($main_entry_count - 1)) output &&\n-\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n+\tgit reflog >reflog_output &&\n+\ttest $HEAD_entry_count = $(wc -l <reflog_output) &&\n \t! grep ox < output &&\n \n \tmain_entry_count=$(wc -l < output) &&\n \n \tgit reflog delete HEAD@{1} &&\n-\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n-\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n+\tgit reflog >reflog_output &&\n+\ttest $(($HEAD_entry_count -1)) = $(wc -l <reflog_output) &&\n+\tgit reflog show main >reflog_main_output &&\n+\ttest $main_entry_count = $(wc -l <reflog_main_output) &&\n \n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n+\tgit reflog >reflog_output &&\n+\tHEAD_entry_count=$(wc -l <reflog_output) &&\n \n \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n \tgit reflog show main > output &&\n@@ -319,13 +323,12 @@ test_expect_success 'git reflog expire unknown reference' '\n \ttest_must_fail git reflog expire does-not-exist 2>stderr &&\n \ttest_grep \"error: reflog could not be found: ${SQ}does-not-exist${SQ}\" stderr\n '\n-\n test_expect_success 'checkout should not delete log for packed ref' '\n-\ttest $(git reflog main | wc -l) = 4 &&\n+\ttest_stdout_line_count = 4 git reflog main &&\n \tgit branch foo &&\n \tgit pack-refs --all &&\n \tgit checkout foo &&\n-\ttest $(git reflog main | wc -l) = 4\n+\ttest_stdout_line_count = 4 git reflog main\n '\n \n test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n-- \n2.54.0\n\n"},{"id":"547422","messageId":"xmqqh5maxne6.fsf@gitster.g","threadId":"65937","inReplyTo":"20260707135530.17389-1-gatlavishweshwarreddy26@gmail.com","subject":"Re: [PATCH v2] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-08T01:48:01Z","receivedAt":"2026-07-08T01:48:04Z","isPatch":true,"body":"Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:\n\n> Piping git commands directly to wc -l suppresses the exit code of\n> git, hiding potential failures from the test suite. Capture the\n> output to a temporary file first, then count the lines separately\n> to preserve the exit code. Where the expected count is known ahead\n> of time, use test_stdout_line_count instead.\n>\n> Signed-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n> ---\n>  t/t1410-reflog.sh | 29 ++++++++++++++++-------------\n>  1 file changed, 16 insertions(+), 13 deletions(-)\n\nThe above descripotion looks reasonble.\n\nBy the way, Documentation/SubmittingPatches has this:\n\n    Before sending another version, make sure you have answered\n    meaningful review comments in the existing discussion.  Also\n    give reviewers enough time to comment before sending another\n    version.\n\n> diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\n> index ce71f9a30a..8e018d172b 100755\n> --- a/t/t1410-reflog.sh\n> +++ b/t/t1410-reflog.sh\n> @@ -244,26 +244,30 @@ test_expect_success 'delete' '\n>  \ttest_tick &&\n>  \tgit commit -m tiger C &&\n>  \n> -\tHEAD_entry_count=$(git reflog | wc -l) &&\n> -\tmain_entry_count=$(git reflog show main | wc -l) &&\n> -\n> -\ttest $HEAD_entry_count = 5 &&\n> -\ttest $main_entry_count = 5 &&\n> -\n> +\ttest_stdout_line_count = 5 git reflog &&\n> +\tgit reflog >reflog_output &&\n> +\tHEAD_entry_count=$(wc -l <reflog_output) &&\n> +\ttest_stdout_line_count = 5 git reflog show main &&\n> +\tgit reflog show main >reflog_main_output &&\n> +\tmain_entry_count=$(wc -l <reflog_main_output) &&\n>  \n>  \tgit reflog delete main@{1} &&\n>  \tgit reflog show main > output &&\n>  \ttest_line_count = $(($main_entry_count - 1)) output &&\n> -\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\ttest $HEAD_entry_count = $(wc -l <reflog_output) &&\n>  \t! grep ox < output &&\n\nNow, you no longer have new consecutive blank lines in the above,\nbut the above shares the same \"what did the author meant to convey\nwith this blank line?\" puzzlement.\n\nThe updated code somehow wanders around in many directions like a\ndrunken man.  Let's comment on each line.\n\n> +\ttest_stdout_line_count = 5 git reflog &&\n\nThis is \"Does the reflog for HEAD have exactly 5 entries?\" test.\n\n> +\tgit reflog >reflog_output &&\n> +\tHEAD_entry_count=$(wc -l <reflog_output) &&\n\nAs we already saw that HEAD_entry_count variable is exactly equal to\n5, it is puzzling why we want to perform this computation again and\nassign the result to the variable.\n\n> +\ttest_stdout_line_count = 5 git reflog show main &&\n\nAnd then we check \"Does the reflog for 'main' have exactly 5\nentries?\"\n\n> +\tgit reflog show main >reflog_main_output &&\n> +\tmain_entry_count=$(wc -l <reflog_main_output) &&\n\nAnd recompute what we already know and asssign to main_entry_count\nvariable, which shares the same puzzlement.\n\n>  \n>  \tgit reflog delete main@{1} &&\n>  \tgit reflog show main > output &&\n>  \ttest_line_count = $(($main_entry_count - 1)) output &&\n\nNow, after a blank line, it goes on to test a completely different\nthing, which is \"after deleting an entry in main's reflog, can we\ncount how many there is, and does it match what we expect, which is\nthe previous count minus 1\"?  Why should we even need to do so, when\n\n\tgit reflog delete main@{1} &&\n\ttest_stdout_line_count = 4 git reflog show main &&\n\nwould do just fine?\n\n> -\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\ttest $HEAD_entry_count = $(wc -l <reflog_output) &&\n\nAnd then it comes back to test what we already know, i.e. \"does the\nreflog for HEAD have 5 entries?\".  Which we tested earlier already.\n\nAre we interested in checking that \"reflog delete main@{1}\" does\nnot affect the reflog for HEAD?  If so, doing\n\n\ttest_stdout_line_count = 5 git reflog &&\n\nagain here would be simpler, no?  That way, there is no need to\nrecompute and assign to the {HEAD,main}_entry_count variables in the\nearlier part of the tests.\n\nI guess the same comment applies to the remainder of this test,\nwhere it is checked that a removal from HEAD reflog does not affect\nthe reflog of main.\n\n\n\n>  \tmain_entry_count=$(wc -l < output) &&\n>  \n>  \tgit reflog delete HEAD@{1} &&\n> -\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n> -\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\ttest $(($HEAD_entry_count -1)) = $(wc -l <reflog_output) &&\n> +\tgit reflog show main >reflog_main_output &&\n> +\ttest $main_entry_count = $(wc -l <reflog_main_output) &&\n>  \n> -\tHEAD_entry_count=$(git reflog | wc -l) &&\n> +\tgit reflog >reflog_output &&\n> +\tHEAD_entry_count=$(wc -l <reflog_output) &&\n>  \n>  \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n>  \tgit reflog show main > output &&\n> @@ -319,13 +323,12 @@ test_expect_success 'git reflog expire unknown reference' '\n>  \ttest_must_fail git reflog expire does-not-exist 2>stderr &&\n>  \ttest_grep \"error: reflog could not be found: ${SQ}does-not-exist${SQ}\" stderr\n>  '\n> -\n>  test_expect_success 'checkout should not delete log for packed ref' '\n> -\ttest $(git reflog main | wc -l) = 4 &&\n> +\ttest_stdout_line_count = 4 git reflog main &&\n>  \tgit branch foo &&\n>  \tgit pack-refs --all &&\n>  \tgit checkout foo &&\n> -\ttest $(git reflog main | wc -l) = 4\n> +\ttest_stdout_line_count = 4 git reflog main\n>  '\n>  \n>  test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n"},{"id":"547478","messageId":"20260708092448.35776-1-gatlavishweshwarreddy26@gmail.com","threadId":"65937","inReplyTo":"xmqqechf8ryu.fsf@gitster.g","subject":"[PATCH v3] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Gatla Vishweshwar Reddy","fromEmail":"gatlavishweshwarreddy26@gmail.com","sentAt":"2026-07-08T09:20:05Z","receivedAt":"2026-07-08T09:25:04Z","isPatch":true,"body":"Piping git commands directly to wc -l suppresses the exit code of\ngit, hiding potential failures from the test suite. Capture the\noutput to a temporary file first, then count the lines separately\nto preserve the exit code. Where the expected count is known ahead\nof time, use test_stdout_line_count instead.\n\nSigned-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n---\n\nChanges in v3:\n- Removed all variables (HEAD_entry_count, main_entry_count) entirely\n- Removed all temporary file captures (reflog_output, reflog_main_output)\n- Used test_stdout_line_count with hardcoded counts throughout\n- The counts are known ahead of time: HEAD=5, main=5 initially,decreasing as entries are deleted\n\n t/t1410-reflog.sh | 27 +++++++++------------------\n 1 file changed, 9 insertions(+), 18 deletions(-)\n\ndiff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\nindex ce71f9a30a..3f2e36cf33 100755\n--- a/t/t1410-reflog.sh\n+++ b/t/t1410-reflog.sh\n@@ -244,30 +244,22 @@ test_expect_success 'delete' '\n \ttest_tick &&\n \tgit commit -m tiger C &&\n\n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n-\tmain_entry_count=$(git reflog show main | wc -l) &&\n-\n-\ttest $HEAD_entry_count = 5 &&\n-\ttest $main_entry_count = 5 &&\n-\n+\ttest_stdout_line_count = 5 git reflog &&\n+\ttest_stdout_line_count = 5 git reflog show main &&\n\n \tgit reflog delete main@{1} &&\n+\ttest_stdout_line_count = 4 git reflog show main &&\n+\ttest_stdout_line_count = 5 git reflog &&\n \tgit reflog show main > output &&\n-\ttest_line_count = $(($main_entry_count - 1)) output &&\n-\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n \t! grep ox < output &&\n\n-\tmain_entry_count=$(wc -l < output) &&\n-\n \tgit reflog delete HEAD@{1} &&\n-\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n-\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n-\n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n+\ttest_stdout_line_count = 4 git reflog &&\n+\ttest_stdout_line_count = 4 git reflog show main &&\n\n \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n+\ttest_stdout_line_count = 3 git reflog show main &&\n \tgit reflog show main > output &&\n-\ttest_line_count = $(($main_entry_count - 1)) output &&\n \t! grep dragon < output\n\n '\n@@ -319,13 +311,12 @@ test_expect_success 'git reflog expire unknown reference' '\n \ttest_must_fail git reflog expire does-not-exist 2>stderr &&\n \ttest_grep \"error: reflog could not be found: ${SQ}does-not-exist${SQ}\" stderr\n '\n-\n test_expect_success 'checkout should not delete log for packed ref' '\n-\ttest $(git reflog main | wc -l) = 4 &&\n+\ttest_stdout_line_count = 4 git reflog main &&\n \tgit branch foo &&\n \tgit pack-refs --all &&\n \tgit checkout foo &&\n-\ttest $(git reflog main | wc -l) = 4\n+\ttest_stdout_line_count = 4 git reflog main\n '\n\n test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n--\n2.54.0\n\n"},{"id":"547534","messageId":"xmqqv7aprz8a.fsf@gitster.g","threadId":"65937","inReplyTo":"20260708092448.35776-1-gatlavishweshwarreddy26@gmail.com","subject":"Re: [PATCH v3] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-08T20:41:09Z","receivedAt":"2026-07-08T20:41:12Z","isPatch":true,"body":"Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:\n\n> Piping git commands directly to wc -l suppresses the exit code of\n> git, hiding potential failures from the test suite.\n\nCorrect.\n\n> Capture the\n> output to a temporary file first, then count the lines separately\n> to preserve the exit code. Where the expected count is known ahead\n> of time, use test_stdout_line_count instead.\n\nTechnically, the description is not telling any lies about the\nsolution, but the patch no longer does the caputuring or counting\nitself at all.  Rather, it exclusively uses test_stdout_line_count,\nwhich internally does the saving to a temporary and counting the\nlines ;-)\n\nThe changes in the patch are mostly good, except for the loss of a\nblank line that separates two test pieces in the last hunk (below).\n\n> @@ -319,13 +311,12 @@ test_expect_success 'git reflog expire unknown reference' '\n>  \ttest_must_fail git reflog expire does-not-exist 2>stderr &&\n>  \ttest_grep \"error: reflog could not be found: ${SQ}does-not-exist${SQ}\" stderr\n>  '\n> -\n>  test_expect_success 'checkout should not delete log for packed ref' '\n> -\ttest $(git reflog main | wc -l) = 4 &&\n> +\ttest_stdout_line_count = 4 git reflog main &&\n>  \tgit branch foo &&\n>  \tgit pack-refs --all &&\n>  \tgit checkout foo &&\n> -\ttest $(git reflog main | wc -l) = 4\n> +\ttest_stdout_line_count = 4 git reflog main\n>  '\n>\n>  test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n\nThanks.\n"},{"id":"547562","messageId":"20260709051229.40363-1-gatlavishweshwarreddy26@gmail.com","threadId":"65937","inReplyTo":"xmqqv7aprz8a.fsf@gitster.g","subject":"[PATCH v4] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Gatla Vishweshwar Reddy","fromEmail":"gatlavishweshwarreddy26@gmail.com","sentAt":"2026-07-09T05:09:35Z","receivedAt":"2026-07-09T05:12:45Z","isPatch":true,"body":"Piping git commands directly to wc -l suppresses the exit code of\ngit, hiding potential failures from the test suite. Use\ntest_stdout_line_count instead, which handles exit code preservation\ninternally while keeping the test logic clean and readable.\n\nSigned-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n---\n\nChanges in v4:\n- Restored blank line between test_expect_success blocks that was\n  accidentally removed in v2\n- Updated commit message to accurately describe the solution\n\nThank you for the detailed review!\n\n t/t1410-reflog.sh | 26 +++++++++-----------------\n 1 file changed, 9 insertions(+), 17 deletions(-)\n\ndiff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\nindex ce71f9a30a..5a40a62ba2 100755\n--- a/t/t1410-reflog.sh\n+++ b/t/t1410-reflog.sh\n@@ -244,30 +244,22 @@ test_expect_success 'delete' '\n \ttest_tick &&\n \tgit commit -m tiger C &&\n\n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n-\tmain_entry_count=$(git reflog show main | wc -l) &&\n-\n-\ttest $HEAD_entry_count = 5 &&\n-\ttest $main_entry_count = 5 &&\n-\n+\ttest_stdout_line_count = 5 git reflog &&\n+\ttest_stdout_line_count = 5 git reflog show main &&\n\n \tgit reflog delete main@{1} &&\n+\ttest_stdout_line_count = 4 git reflog show main &&\n+\ttest_stdout_line_count = 5 git reflog &&\n \tgit reflog show main > output &&\n-\ttest_line_count = $(($main_entry_count - 1)) output &&\n-\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n \t! grep ox < output &&\n\n-\tmain_entry_count=$(wc -l < output) &&\n-\n \tgit reflog delete HEAD@{1} &&\n-\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n-\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n-\n-\tHEAD_entry_count=$(git reflog | wc -l) &&\n+\ttest_stdout_line_count = 4 git reflog &&\n+\ttest_stdout_line_count = 4 git reflog show main &&\n\n \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n+\ttest_stdout_line_count = 3 git reflog show main &&\n \tgit reflog show main > output &&\n-\ttest_line_count = $(($main_entry_count - 1)) output &&\n \t! grep dragon < output\n\n '\n@@ -321,11 +313,11 @@ test_expect_success 'git reflog expire unknown reference' '\n '\n\n test_expect_success 'checkout should not delete log for packed ref' '\n-\ttest $(git reflog main | wc -l) = 4 &&\n+\ttest_stdout_line_count = 4 git reflog main &&\n \tgit branch foo &&\n \tgit pack-refs --all &&\n \tgit checkout foo &&\n-\ttest $(git reflog main | wc -l) = 4\n+\ttest_stdout_line_count = 4 git reflog main\n '\n\n test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n--\n2.54.0\n\n"},{"id":"547626","messageId":"xmqqtsq8p18x.fsf@gitster.g","threadId":"65937","inReplyTo":"20260709051229.40363-1-gatlavishweshwarreddy26@gmail.com","subject":"Re: [PATCH v4] t1410-reflog.sh: avoid suppressing git's exit code in pipelines","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-07-09T16:38:06Z","receivedAt":"2026-07-09T16:38:08Z","isPatch":true,"body":"Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com> writes:\n\n> Piping git commands directly to wc -l suppresses the exit code of\n> git, hiding potential failures from the test suite. Use\n> test_stdout_line_count instead, which handles exit code preservation\n> internally while keeping the test logic clean and readable.\n>\n> Signed-off-by: Gatla Vishweshwar Reddy <gatlavishweshwarreddy26@gmail.com>\n> ---\n>\n> Changes in v4:\n> - Restored blank line between test_expect_success blocks that was\n>   accidentally removed in v2\n> - Updated commit message to accurately describe the solution\n\nThis version looks good to me.\n\nWill queue and mark the topic for 'next'.\n\nThanks.\n\n>\n> Thank you for the detailed review!\n>\n>  t/t1410-reflog.sh | 26 +++++++++-----------------\n>  1 file changed, 9 insertions(+), 17 deletions(-)\n>\n> diff --git a/t/t1410-reflog.sh b/t/t1410-reflog.sh\n> index ce71f9a30a..5a40a62ba2 100755\n> --- a/t/t1410-reflog.sh\n> +++ b/t/t1410-reflog.sh\n> @@ -244,30 +244,22 @@ test_expect_success 'delete' '\n>  \ttest_tick &&\n>  \tgit commit -m tiger C &&\n>\n> -\tHEAD_entry_count=$(git reflog | wc -l) &&\n> -\tmain_entry_count=$(git reflog show main | wc -l) &&\n> -\n> -\ttest $HEAD_entry_count = 5 &&\n> -\ttest $main_entry_count = 5 &&\n> -\n> +\ttest_stdout_line_count = 5 git reflog &&\n> +\ttest_stdout_line_count = 5 git reflog show main &&\n>\n>  \tgit reflog delete main@{1} &&\n> +\ttest_stdout_line_count = 4 git reflog show main &&\n> +\ttest_stdout_line_count = 5 git reflog &&\n>  \tgit reflog show main > output &&\n> -\ttest_line_count = $(($main_entry_count - 1)) output &&\n> -\ttest $HEAD_entry_count = $(git reflog | wc -l) &&\n>  \t! grep ox < output &&\n>\n> -\tmain_entry_count=$(wc -l < output) &&\n> -\n>  \tgit reflog delete HEAD@{1} &&\n> -\ttest $(($HEAD_entry_count -1)) = $(git reflog | wc -l) &&\n> -\ttest $main_entry_count = $(git reflog show main | wc -l) &&\n> -\n> -\tHEAD_entry_count=$(git reflog | wc -l) &&\n> +\ttest_stdout_line_count = 4 git reflog &&\n> +\ttest_stdout_line_count = 4 git reflog show main &&\n>\n>  \tgit reflog delete main@{07.04.2005.15:15:00.-0700} &&\n> +\ttest_stdout_line_count = 3 git reflog show main &&\n>  \tgit reflog show main > output &&\n> -\ttest_line_count = $(($main_entry_count - 1)) output &&\n>  \t! grep dragon < output\n>\n>  '\n> @@ -321,11 +313,11 @@ test_expect_success 'git reflog expire unknown reference' '\n>  '\n>\n>  test_expect_success 'checkout should not delete log for packed ref' '\n> -\ttest $(git reflog main | wc -l) = 4 &&\n> +\ttest_stdout_line_count = 4 git reflog main &&\n>  \tgit branch foo &&\n>  \tgit pack-refs --all &&\n>  \tgit checkout foo &&\n> -\ttest $(git reflog main | wc -l) = 4\n> +\ttest_stdout_line_count = 4 git reflog main\n>  '\n>\n>  test_expect_success 'stale dirs do not cause d/f conflicts (reflogs on)' '\n"}]}