{"thread":{"id":"60717","subject":"[PATCH] t4129: prevent loss of exit code due to the use of pipes","startedAt":"2024-01-10T12:54:20Z","lastAt":"2024-01-10T17:25:12Z","messageCount":2,"participants":["Chandra Pratap via GitGitGadget","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"486525","messageId":"pull.1636.git.1704891257544.gitgitgadget@gmail.com","threadId":"60717","inReplyTo":null,"subject":"[PATCH] t4129: prevent loss of exit code due to the use of pipes","fromName":"Chandra Pratap via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2024-01-10T12:54:17Z","receivedAt":"2024-01-10T12:54:20Z","isPatch":true,"sender":{"key":"chandrapratap3519@gmail.com","avatar":null},"body":"From: Chandra Pratap <chandrapratap3519@gmail.com>\n\nPiping the output of git commands like git-ls-files to another\ncommand (grep in this case) hides the exit code returned by\nthese commands. Prevent this by storing the output of git-ls-files\nto a temporary file and then \"grep-ping\" from that file. Replace\ngrep with test_grep as the latter is more verbose when it fails.\n\nSigned-off-by: Chandra Pratap <chandrapratap3519@gmail.com>\n---\n    t4129: prevent loss of exit code due to the use of pipes\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-1636%2FChand-ra%2Ftest_pipe-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1636/Chand-ra/test_pipe-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/1636\n\n t/t4129-apply-samemode.sh | 6 ++++--\n 1 file changed, 4 insertions(+), 2 deletions(-)\n\ndiff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh\nindex e7a7295f1b6..ffabeafa213 100755\n--- a/t/t4129-apply-samemode.sh\n+++ b/t/t4129-apply-samemode.sh\n@@ -41,7 +41,8 @@ test_expect_success FILEMODE 'same mode (index only)' '\n \tchmod +x file &&\n \tgit add file &&\n \tgit apply --cached patch-0.txt &&\n-\tgit ls-files -s file | grep \"^100755\"\n+\tgit ls-files -s file > ls-files-output &&\n+\ttest_grep \"^100755\" ls-files-output\n '\n \n test_expect_success FILEMODE 'mode update (no index)' '\n@@ -60,7 +61,8 @@ test_expect_success FILEMODE 'mode update (with index)' '\n test_expect_success FILEMODE 'mode update (index only)' '\n \tgit reset --hard &&\n \tgit apply --cached patch-1.txt &&\n-\tgit ls-files -s file | grep \"^100755\"\n+\tgit ls-files -s file > ls-files-output &&\n+\ttest_grep \"^100755\" ls-files-output\n '\n \n test_expect_success FILEMODE 'empty mode is rejected' '\n\nbase-commit: a54a84b333adbecf7bc4483c0e36ed5878cac17b\n-- \ngitgitgadget\n"},{"id":"486541","messageId":"xmqqwmshcd8r.fsf@gitster.g","threadId":"60717","inReplyTo":"pull.1636.git.1704891257544.gitgitgadget@gmail.com","subject":"Re: [PATCH] t4129: prevent loss of exit code due to the use of pipes","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2024-01-10T17:25:08Z","receivedAt":"2024-01-10T17:25:12Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"\"Chandra Pratap via GitGitGadget\" <gitgitgadget@gmail.com> writes:\n\n>  t/t4129-apply-samemode.sh | 6 ++++--\n>  1 file changed, 4 insertions(+), 2 deletions(-)\n\nLooks good.  Will queue with two instances of a minor style fix (see\nbelow).\n\n> diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh\n> index e7a7295f1b6..ffabeafa213 100755\n> --- a/t/t4129-apply-samemode.sh\n> +++ b/t/t4129-apply-samemode.sh\n> @@ -41,7 +41,8 @@ test_expect_success FILEMODE 'same mode (index only)' '\n>  \tchmod +x file &&\n>  \tgit add file &&\n>  \tgit apply --cached patch-0.txt &&\n> -\tgit ls-files -s file | grep \"^100755\"\n> +\tgit ls-files -s file > ls-files-output &&\n\nRedirection operator \">\" and \"<\" sticks to the file in question\n(look for \"> \" and \"< \" in this file and you'd find none), i.e.\n\n\tgit ls-files -s file >ls-files-output &&\n\nThanks.\n"}]}