git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] t4129: prevent loss of exit code due to the use of pipes
@ 2024-01-10 12:54 Chandra Pratap via GitGitGadget
  2024-01-10 17:25 ` Junio C Hamano
  0 siblings, 1 reply; 2+ messages in thread
From: Chandra Pratap via GitGitGadget @ 2024-01-10 12:54 UTC (permalink / raw)
  To: git; +Cc: Chandra Pratap, Chandra Pratap

From: Chandra Pratap <chandrapratap3519@gmail.com>

Piping the output of git commands like git-ls-files to another
command (grep in this case) hides the exit code returned by
these commands. Prevent this by storing the output of git-ls-files
to a temporary file and then "grep-ping" from that file. Replace
grep with test_grep as the latter is more verbose when it fails.

Signed-off-by: Chandra Pratap <chandrapratap3519@gmail.com>
---
    t4129: prevent loss of exit code due to the use of pipes

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-1636%2FChand-ra%2Ftest_pipe-v1
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-1636/Chand-ra/test_pipe-v1
Pull-Request: https://github.com/gitgitgadget/git/pull/1636

 t/t4129-apply-samemode.sh | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh
index e7a7295f1b6..ffabeafa213 100755
--- a/t/t4129-apply-samemode.sh
+++ b/t/t4129-apply-samemode.sh
@@ -41,7 +41,8 @@ test_expect_success FILEMODE 'same mode (index only)' '
 	chmod +x file &&
 	git add file &&
 	git apply --cached patch-0.txt &&
-	git ls-files -s file | grep "^100755"
+	git ls-files -s file > ls-files-output &&
+	test_grep "^100755" ls-files-output
 '
 
 test_expect_success FILEMODE 'mode update (no index)' '
@@ -60,7 +61,8 @@ test_expect_success FILEMODE 'mode update (with index)' '
 test_expect_success FILEMODE 'mode update (index only)' '
 	git reset --hard &&
 	git apply --cached patch-1.txt &&
-	git ls-files -s file | grep "^100755"
+	git ls-files -s file > ls-files-output &&
+	test_grep "^100755" ls-files-output
 '
 
 test_expect_success FILEMODE 'empty mode is rejected' '

base-commit: a54a84b333adbecf7bc4483c0e36ed5878cac17b
-- 
gitgitgadget

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] t4129: prevent loss of exit code due to the use of pipes
  2024-01-10 12:54 [PATCH] t4129: prevent loss of exit code due to the use of pipes Chandra Pratap via GitGitGadget
@ 2024-01-10 17:25 ` Junio C Hamano
  0 siblings, 0 replies; 2+ messages in thread
From: Junio C Hamano @ 2024-01-10 17:25 UTC (permalink / raw)
  To: Chandra Pratap via GitGitGadget; +Cc: git, Chandra Pratap, Chandra Pratap

"Chandra Pratap via GitGitGadget" <gitgitgadget@gmail.com> writes:

>  t/t4129-apply-samemode.sh | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)

Looks good.  Will queue with two instances of a minor style fix (see
below).

> diff --git a/t/t4129-apply-samemode.sh b/t/t4129-apply-samemode.sh
> index e7a7295f1b6..ffabeafa213 100755
> --- a/t/t4129-apply-samemode.sh
> +++ b/t/t4129-apply-samemode.sh
> @@ -41,7 +41,8 @@ test_expect_success FILEMODE 'same mode (index only)' '
>  	chmod +x file &&
>  	git add file &&
>  	git apply --cached patch-0.txt &&
> -	git ls-files -s file | grep "^100755"
> +	git ls-files -s file > ls-files-output &&

Redirection operator ">" and "<" sticks to the file in question
(look for "> " and "< " in this file and you'd find none), i.e.

	git ls-files -s file >ls-files-output &&

Thanks.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2024-01-10 17:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-01-10 12:54 [PATCH] t4129: prevent loss of exit code due to the use of pipes Chandra Pratap via GitGitGadget
2024-01-10 17:25 ` Junio C Hamano

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).