Subject: [PATCH 0/2] [GSoC][PATCH 0/2] t0000-t0050: avoid pipes with Git on LHS
cover Subject: [PATCH 0/2] [GSoC][PATCH 0/2] t0000-t0050: avoid pipes with Git on LHS
As a microproject, I remove all pipes with GIT on LHS from files t0000 to t0050.
Shubham Mishra (2):
t0001-t0028: avoid pipes with Git on LHS
t0030-t0050: avoid pipes with Git on LHS
t/t0000-basic.sh | 10 +++-- t/t0022-crlf-rename.sh | 4 +- t/t0025-crlf-renormalize.sh | 4 +- t/t0027-auto-crlf.sh | 12 +++--- t/t0030-stripspace.sh | 81 ++++++++++++++++++++++++------------- t/t0050-filesystem.sh | 3 +- 6 files changed, 72 insertions(+), 42 deletions(-)
base-commit: e6ebfd0e8cbbd10878070c8a356b5ad1b3ca464e
Signature · 1 line
2.25.1
PATCH 1/2 t0001-t0028: avoid pipes with Git on LHS
Pipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
--- t/t0000-basic.sh | 10 ++++++---- t/t0022-crlf-rename.sh | 4 ++-- t/t0025-crlf-renormalize.sh | 4 ++-- t/t0027-auto-crlf.sh | 12 ++++++------ 4 files changed, 16 insertions(+), 14 deletions(-)
t/t0000-basic.sh +6 -4
@@ -1089,7 +1089,8 @@ test_expect_success 'update-index D/F conflict' ' mv path2 path0 && mv tmp path2 && git update-index --add --replace path2 path0/file2 && - numpath0=$(git ls-files path0 | wc -l) && + git ls-files path0 >tmp && + numpath0=$(wc -l <tmp) && test $numpath0 = 1 '
@@ -1104,12 +1105,13 @@ test_expect_success 'very long name in the index handled sanely' ' >path4 && git update-index --add path4 && ( - git ls-files -s path4 | - sed -e "s/ .*/ /" | + git ls-files -s path4 >tmp && + sed -e "s/ .*/ /" tmp | tr -d "\012" && echo "$a" ) | git update-index --index-info && - len=$(git ls-files "a*" | wc -c) && + git ls-files "a*" >tmp && + len=$(wc -c <tmp) && test $len = 4098 '
t/t0022-crlf-rename.sh +2 -2
@@ -24,8 +24,8 @@ test_expect_success setup ' test_expect_success 'diff -M' ' - git diff-tree -M -r --name-status HEAD^ HEAD | - sed -e "s/R[0-9]*/RNUM/" >actual && + git diff-tree -M -r --name-status HEAD^ HEAD >tmp && + sed -e "s/R[0-9]*/RNUM/" tmp >actual && echo "RNUM sample elpmas" >expect && test_cmp expect actual
t/t0025-crlf-renormalize.sh +2 -2
@@ -22,8 +22,8 @@ test_expect_success 'renormalize CRLF in repo' ' i/lf w/lf attr/text=auto LF.txt i/lf w/mixed attr/text=auto CRLF_mix_LF.txt EOF - git ls-files --eol | - sed -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol >tmp && + sed -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
t/t0027-auto-crlf.sh +6 -6
@@ -311,8 +311,8 @@ checkout_files () { i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt EOF - git ls-files --eol crlf_false_attr__* | - sed -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol crlf_false_attr__* >tmp && + sed -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
@@ -359,12 +359,12 @@ test_expect_success 'ls-files --eol -o Text/Binary' ' i/ w/crlf TeBi_126_CL i/ w/-text TeBi_126_CLC EOF - git ls-files --eol -o | + git ls-files --eol -o >tmp && sed -n -e "/TeBi_/{s!attr/[ ]*!!g s! ! !g s! *! !g p - }" | sort >actual && + }" tmp | sort >actual && test_cmp expect actual '
@@ -617,8 +617,8 @@ test_expect_success 'ls-files --eol -d -z' ' i/lf w/ crlf_false_attr__LF.txt i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt EOF - git ls-files --eol -d | - sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol -d >tmp && + sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
Signature · 1 line
2.25.1
PATCH 2/2 t0030-t0050: avoid pipes with Git on LHS
In reply to Shubham MishraPipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
--- t/t0030-stripspace.sh | 81 ++++++++++++++++++++++++++++--------------- t/t0050-filesystem.sh | 3 +- 2 files changed, 56 insertions(+), 28 deletions(-)
t/t0030-stripspace.sh +54 -27
@@ -225,32 +225,48 @@ test_expect_success \ test_expect_success \ 'text without newline at end should end with newline' ' - test $(printf "$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 + printf "$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$ttt$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 ' # text plus spaces at the end: test_expect_success \ 'text plus spaces without newline at end should end with newline' ' - test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0 + printf "$ttt$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$ttt$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$sss$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$sss$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$sss$sss$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 ' test_expect_success \ 'text plus spaces without newline at end should not show spaces' ' - ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "$ttt$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + printf "$ttt$ttt$sss" | git stripspace && + ! (grep " " tmp >/dev/null) && + printf "$ttt$ttt$ttt$sss" | git stripspace && + ! (grep " " tmp >/dev/nul) && + printf "$ttt$sss$sss" | git stripspace && + ! (grep " " tmp >/dev/null) && + printf "$ttt$ttt$sss$sss" | git stripspace && + ! (grep " " tmp >/dev/null) && + printf "$ttt$sss$sss$sss" | git stripspace && + ! (grep " " tmp >/dev/null) ' test_expect_success \
@@ -282,12 +298,18 @@ test_expect_success \ test_expect_success \ 'text plus spaces at end should not show spaces' ' - ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + echo "$ttt$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + echo "$ttt$ttt$sss" | git stripspace >tmp && + ! (grep " " tmp>/dev/null) && + echo "$ttt$ttt$ttt$sss" && + ! (grep " " tmp >/dev/null) && + echo "$ttt$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + echo "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + echo "$ttt$sss$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) ' test_expect_success \
@@ -339,11 +361,16 @@ test_expect_success \ test_expect_success \ 'spaces without newline at end should not show spaces' ' - ! (printf "" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "" | git stripspace >tmp && + ! ( grep " " tmp >/dev/null) && + printf "$sss" | git stripspace >tmp && + ! ( grep " " tmp >/dev/null) && + printf "$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + printf "$sss$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + printf "$sss$sss$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) ' test_expect_success \
t/t0050-filesystem.sh +2 -1
@@ -104,7 +104,8 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' ' rm camelcase && echo 1 >CamelCase && git add CamelCase && - camel=$(git ls-files | grep -i camelcase) && + git ls-files >tmp && + camel=$(grep -i camelcase tmp) && test $(echo "$camel" | wc -l) = 1 && test "z$(git cat-file blob :$camel)" = z1 '
Signature · 1 line
2.25.1
Re: [PATCH 2/2] t0030-t0050: avoid pipes with Git on LHS
Quoted 21 lines · Shubham Mishra
Pipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
Signed-off-by Shubham Mishra <[email protected]>--- t/t0030-stripspace.sh | 81 ++++++++++++++++++++++++++++--------------- t/t0050-filesystem.sh | 3 +- 2 files changed, 56 insertions(+), 28 deletions(-)t/t0030-stripspace.sh +0
-3@@ -225,32 +225,48 @@ test_expect_success \ test_expect_success \ 'text without newline at end should end with newline' ' - test $(printf "$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
t/t0030-stripspace.sh test_expect_success \ · line 236
Quoted 10 lines
t/t0030-stripspace.sh +8
-1- test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 + printf "$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$ttt$ttt" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 '
You're modifying some tests here that are using some old coding style, so maybe it's better to adjust it while we're at it?
Also I think this would be a lot nicer with test_stdout_line_count and a helper to deal with that pritnf, e.g.:
diff --git a/t/t0030-stripspace.sh b/t/t0030-stripspace.sh
index ae1ca380c1a..d48a3579511 100755
--- a/t/t0030-stripspace.sh
+++ b/t/t0030-stripspace.sh
@@ -223,12 +223,15 @@ test_expect_success \
test_cmp expect actual
'
-test_expect_success \
- 'text without newline at end should end with newline' '
- test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
+printf_git_stripspace () {
+ printf "$1" | git stripspace
+}
+
+test_expect_success 'text without newline at end should end with newline' '
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" &&
+ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt"
'
# text plus spaces at the end:Quoted 13 lines
t/t0030-stripspace.sh +3
-6# text plus spaces at the end: test_expect_success \ 'text plus spaces without newline at end should end with newline' ' - test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0 + printf "$ttt$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$sss" | git stripspace >tmp &&
t/t0030-stripspace.sh test_expect_success \ · line 254
Quoted 10 lines
t/t0030-stripspace.sh +9
-0+ test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$ttt$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$sss$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$ttt$sss$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 && + printf "$ttt$sss$sss$sss" | git stripspace >tmp && + test $(wc -l <tmp) -gt 0 '
ditto.
Quoted 11 lines
t/t0030-stripspace.sh +3
-6test_expect_success \ 'text plus spaces without newline at end should not show spaces' ' - ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "$ttt$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + printf "$ttt$ttt$sss" | git stripspace &&
t/t0030-stripspace.sh test_expect_success \ · line 270
Quoted 10 lines
t/t0030-stripspace.sh +9
-0+ ! (grep " " tmp >/dev/null) && + printf "$ttt$ttt$ttt$sss" | git stripspace && + ! (grep " " tmp >/dev/nul) && + printf "$ttt$sss$sss" | git stripspace && + ! (grep " " tmp >/dev/null) && + printf "$ttt$ttt$sss$sss" | git stripspace && + ! (grep " " tmp >/dev/null) && + printf "$ttt$sss$sss$sss" | git stripspace && + ! (grep " " tmp >/dev/null) '
This is not on you, but generally we don't pipe "grep" to >/dev/null, and just let the --verbose option do its work.
With/without that change you no longer need the () subshell here.
Quoted 36 lines
t/t0030-stripspace.sh +13
-11test_expect_success \@@ -282,12 +298,18 @@ test_expect_success \ test_expect_success \ 'text plus spaces at end should not show spaces' ' - ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + echo "$ttt$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + echo "$ttt$ttt$sss" | git stripspace >tmp && + ! (grep " " tmp>/dev/null) && + echo "$ttt$ttt$ttt$sss" && + ! (grep " " tmp >/dev/null) && + echo "$ttt$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + echo "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + echo "$ttt$sss$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) ' test_expect_success \@@ -339,11 +361,16 @@ test_expect_success \ test_expect_success \ 'spaces without newline at end should not show spaces' ' - ! (printf "" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "" | git stripspace >tmp &&
t/t0030-stripspace.sh test_expect_success \ · line 374
Quoted 10 lines
t/t0030-stripspace.sh +9
-0+ ! ( grep " " tmp >/dev/null) && + printf "$sss" | git stripspace >tmp && + ! ( grep " " tmp >/dev/null) && + printf "$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + printf "$sss$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) && + printf "$sss$sss$sss$sss" | git stripspace >tmp && + ! (grep " " tmp >/dev/null) '
ditto for these.
Quoted 15 lines
t/t0030-stripspace.sh +0
-0test_expect_success \t/t0050-filesystem.sh +2
-1@@ -104,7 +104,8 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' ' rm camelcase && echo 1 >CamelCase && git add CamelCase && - camel=$(git ls-files | grep -i camelcase) && + git ls-files >tmp && + camel=$(grep -i camelcase tmp) && test $(echo "$camel" | wc -l) = 1 && test "z$(git cat-file blob :$camel)" = z1 '
Re: [PATCH 2/2] t0030-t0050: avoid pipes with Git on LHS
Hi,
Thanks for Reviewing.
Quoted 31 lines
You're modifying some tests here that are using some old coding style, so maybe it's better to adjust it while we're at it?
Also I think this would be a lot nicer with
test_stdout_line_countand a helper to deal with that pritnf, e.g.:diff --git
a/t/t0030-stripspace.shb/t/t0030-stripspace.shindexae1ca380c1a..d48a3579511100755
---a/t/t0030-stripspace.sh
+++b/t/t0030-stripspace.sh
@@ -223,12 +223,15 @@test_expect_success\
test_cmpexpect actual
'-test_expect_success \
- 'text without newline at end should end with newline' '
- test $(printf "$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
+printf_git_stripspace () {
+ printf "$1" | git stripspace
+}
+
+test_expect_success 'text without newline at end should end with newline' '
+test_stdout_line_count-gt 0printf_git_stripspace"$ttt" &&
+test_stdout_line_count-gt 0printf_git_stripspace"$ttt$ttt" &&
+test_stdout_line_count-gt 0printf_git_stripspace"$ttt$ttt$ttt" &&
+test_stdout_line_count-gt 0printf_git_stripspace"$ttt$ttt$ttt$ttt"
'
Quoted 2 lines
# text plus spaces at the end:
it makes sense to improve this code as we are touching it, this way looks much better. I will implement it.
Quoted 2 lines
This is not on you, but generally we don't pipe "grep" to >/dev/null, and just let the --verbose option do its work.
I don't think I understood this, I guess you are talking about the "-v" flag that stands for invert match? I didn't find "--verbose" with grep.
Please correct me if I am wrong.
Quoted 1 line
With/without that change you no longer need the () subshell here.
sure.
Thanks,
Shubham
Re: [PATCH 2/2] t0030-t0050: avoid pipes with Git on LHS
In reply to Ævar Arnfjörð BjarmasonQuoted 5 lines · Ævar Arnfjörð Bjarmason
You're modifying some tests here that are using some old coding style, so maybe it's better to adjust it while we're at it?
Also I think this would be a lot nicer with
test_stdout_line_countand a helper to deal with that pritnf, e.g.:
Thanks, Ævar for the quality review. I have nothing to add here.
Thanks,
Taylor
v2 cover avoid pipes with Git on LHS
In reply to Ævar Arnfjörð Bjarmasonchanges since v1:
* replaced "wc -l" with test_stdout_line_count
* removed unnecessary "()" subshells
Shubham Mishra (2):
t0001-t0028: avoid pipes with Git on LHS
t0030-t0050: avoid pipes with Git on LHS
t/t0000-basic.sh | 10 +++-- t/t0022-crlf-rename.sh | 4 +- t/t0025-crlf-renormalize.sh | 4 +- t/t0027-auto-crlf.sh | 12 +++--- t/t0030-stripspace.sh | 75 ++++++++++++++++++++++++------------- t/t0050-filesystem.sh | 3 +- 6 files changed, 66 insertions(+), 42 deletions(-)
Range-diff against v1:
1: 2a219ace42 = 1: 2a219ace42 t0001-t0028: avoid pipes with Git on LHS
2: d08c144476 ! 2: c90fc271d9 t0030-t0050: avoid pipes with Git on LHS
@@ Commit message
Signed-off-by: Shubham Mishra <[email protected]>
## t/t0030-stripspace.sh ##
+@@ t/t0030-stripspace.sh: s40=' '
+ sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400
+ ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400
+
++printf_git_stripspace () {
++ printf "$1" | git stripspace
++}
++
+ test_expect_success \
+ 'long lines without spaces should be unchanged' '
+ echo "$ttt" >expect &&
@@ t/t0030-stripspace.sh: test_expect_success \
test_expect_success \
@@ t/t0030-stripspace.sh: test_expect_success \
- test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0
-+ printf "$ttt" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$ttt" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$ttt$ttt" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$ttt$ttt$ttt" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt"
'
# text plus spaces at the end:
@@ t/t0030-stripspace.sh: test_expect_success \
- test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 &&
- test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0
-+ printf "$ttt$sss" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$ttt$sss" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$sss$sss" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$ttt$sss$sss" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0 &&
-+ printf "$ttt$sss$sss$sss" | git stripspace >tmp &&
-+ test $(wc -l <tmp) -gt 0
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" &&
++ test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss"
'
test_expect_success \
@@ t/t0030-stripspace.sh: test_expect_success \
- ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
- ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
+ printf "$ttt$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$ttt$ttt$sss" | git stripspace &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$ttt$ttt$ttt$sss" | git stripspace &&
-+ ! (grep " " tmp >/dev/nul) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$ttt$sss$sss" | git stripspace &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$ttt$ttt$sss$sss" | git stripspace &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$ttt$sss$sss$sss" | git stripspace &&
-+ ! (grep " " tmp >/dev/null)
++ ! grep " " tmp >/dev/null
'
test_expect_success \
@@ t/t0030-stripspace.sh: test_expect_success \
- ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) &&
- ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
+ echo "$ttt$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ echo "$ttt$ttt$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp>/dev/null) &&
++ ! grep " " tmp>/dev/null &&
+ echo "$ttt$ttt$ttt$sss" &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ echo "$ttt$sss$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ echo "$ttt$ttt$sss$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ echo "$ttt$sss$sss$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null)
++ ! grep " " tmp >/dev/null
'
test_expect_success \
@@ t/t0030-stripspace.sh: test_expect_success \
- ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) &&
- ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null)
+ printf "" | git stripspace >tmp &&
-+ ! ( grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$sss" | git stripspace >tmp &&
-+ ! ( grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$sss$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$sss$sss$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null) &&
++ ! grep " " tmp >/dev/null &&
+ printf "$sss$sss$sss$sss" | git stripspace >tmp &&
-+ ! (grep " " tmp >/dev/null)
++ ! grep " " tmp >/dev/null
'
test_expect_success \Signature · 1 line
2.25.1
PATCH v2 1/2 t0001-t0028: avoid pipes with Git on LHS
Pipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
--- t/t0000-basic.sh | 10 ++++++---- t/t0022-crlf-rename.sh | 4 ++-- t/t0025-crlf-renormalize.sh | 4 ++-- t/t0027-auto-crlf.sh | 12 ++++++------ 4 files changed, 16 insertions(+), 14 deletions(-)
t/t0000-basic.sh +6 -4
@@ -1089,7 +1089,8 @@ test_expect_success 'update-index D/F conflict' ' mv path2 path0 && mv tmp path2 && git update-index --add --replace path2 path0/file2 && - numpath0=$(git ls-files path0 | wc -l) && + git ls-files path0 >tmp && + numpath0=$(wc -l <tmp) && test $numpath0 = 1 '
@@ -1104,12 +1105,13 @@ test_expect_success 'very long name in the index handled sanely' ' >path4 && git update-index --add path4 && ( - git ls-files -s path4 | - sed -e "s/ .*/ /" | + git ls-files -s path4 >tmp && + sed -e "s/ .*/ /" tmp | tr -d "\012" && echo "$a" ) | git update-index --index-info && - len=$(git ls-files "a*" | wc -c) && + git ls-files "a*" >tmp && + len=$(wc -c <tmp) && test $len = 4098 '
t/t0022-crlf-rename.sh +2 -2
@@ -24,8 +24,8 @@ test_expect_success setup ' test_expect_success 'diff -M' ' - git diff-tree -M -r --name-status HEAD^ HEAD | - sed -e "s/R[0-9]*/RNUM/" >actual && + git diff-tree -M -r --name-status HEAD^ HEAD >tmp && + sed -e "s/R[0-9]*/RNUM/" tmp >actual && echo "RNUM sample elpmas" >expect && test_cmp expect actual
t/t0025-crlf-renormalize.sh +2 -2
@@ -22,8 +22,8 @@ test_expect_success 'renormalize CRLF in repo' ' i/lf w/lf attr/text=auto LF.txt i/lf w/mixed attr/text=auto CRLF_mix_LF.txt EOF - git ls-files --eol | - sed -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol >tmp && + sed -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
t/t0027-auto-crlf.sh +6 -6
@@ -311,8 +311,8 @@ checkout_files () { i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt EOF - git ls-files --eol crlf_false_attr__* | - sed -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol crlf_false_attr__* >tmp && + sed -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
@@ -359,12 +359,12 @@ test_expect_success 'ls-files --eol -o Text/Binary' ' i/ w/crlf TeBi_126_CL i/ w/-text TeBi_126_CLC EOF - git ls-files --eol -o | + git ls-files --eol -o >tmp && sed -n -e "/TeBi_/{s!attr/[ ]*!!g s! ! !g s! *! !g p - }" | sort >actual && + }" tmp | sort >actual && test_cmp expect actual '
@@ -617,8 +617,8 @@ test_expect_success 'ls-files --eol -d -z' ' i/lf w/ crlf_false_attr__LF.txt i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt EOF - git ls-files --eol -d | - sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol -d >tmp && + sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
Signature · 1 line
2.25.1
Re: [PATCH v2 1/2] t0001-t0028: avoid pipes with Git on LHS
Am 27.02.22 um 13:24 schrieb Shubham Mishra:
Quoted 6 lines
t/t0000-basic.sh +0
-0
t/t0000-basic.sh test_expect_success 'very long name in the index handled sanely' ' · line 1112
Quoted 10 lines
t/t0000-basic.sh +2
-2@@ -1104,12 +1105,13 @@ test_expect_success 'very long name in the index handled sanely' ' >path4 && git update-index --add path4 && ( - git ls-files -s path4 | - sed -e "s/ .*/ /" | + git ls-files -s path4 >tmp && + sed -e "s/ .*/ /" tmp | tr -d "\012" && echo "$a" ) | git update-index --index-info &&
We see a pipe here, and in the upstream of that pipe is a git invocation. That should be fixed, too. After the rewrite that you already did here, it should be sufficient to move the git invocation before the parentheses.
t/t0000-basic.sh test_expect_success 'very long name in the index handled sanely' ' · line 1116
Quoted 5 lines
t/t0000-basic.sh +2
-1- len=$(git ls-files "a*" | wc -c) && + git ls-files "a*" >tmp && + len=$(wc -c <tmp) && test $len = 4098 '
-- Hannes
Re: [PATCH v2 1/2] t0001-t0028: avoid pipes with Git on LHS
Quoted 4 lines · Johannes Sixt
We see a pipe here, and in the upstream of that pipe is a git invocation. That should be fixed, too. After the rewrite that you already did here, it should be sufficient to move the git invocation before the parentheses.
I missed that pipe, Thanks for pointing it out and reviewing.
Sorry for responding late, I am in the middle of my exams, so I am hardly checking mails.
Thanks,
Shubham
PATCH v2 2/2 t0030-t0050: avoid pipes with Git on LHS
In reply to Shubham MishraPipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
--- t/t0030-stripspace.sh | 75 +++++++++++++++++++++++++++---------------- t/t0050-filesystem.sh | 3 +- 2 files changed, 50 insertions(+), 28 deletions(-)
t/t0030-stripspace.sh +48 -27
@@ -13,6 +13,10 @@ s40=' ' sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400 ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400 +printf_git_stripspace () { + printf "$1" | git stripspace +} + test_expect_success \ 'long lines without spaces should be unchanged' ' echo "$ttt" >expect &&
@@ -225,32 +229,38 @@ test_expect_success \ test_expect_success \ 'text without newline at end should end with newline' ' - test $(printf "$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt" ' # text plus spaces at the end: test_expect_success \ 'text plus spaces without newline at end should end with newline' ' - test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0 + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss" ' test_expect_success \ 'text plus spaces without newline at end should not show spaces' ' - ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$ttt$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$sss$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$sss$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$sss$sss$sss" | git stripspace && + ! grep " " tmp >/dev/null ' test_expect_success \
@@ -282,12 +292,18 @@ test_expect_success \ test_expect_success \ 'text plus spaces at end should not show spaces' ' - ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + echo "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp>/dev/null && + echo "$ttt$ttt$ttt$sss" && + ! grep " " tmp >/dev/null && + echo "$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null ' test_expect_success \
@@ -339,11 +355,16 @@ test_expect_success \ test_expect_success \ 'spaces without newline at end should not show spaces' ' - ! (printf "" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null ' test_expect_success \
t/t0050-filesystem.sh +2 -1
@@ -104,7 +104,8 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' ' rm camelcase && echo 1 >CamelCase && git add CamelCase && - camel=$(git ls-files | grep -i camelcase) && + git ls-files >tmp && + camel=$(grep -i camelcase tmp) && test $(echo "$camel" | wc -l) = 1 && test "z$(git cat-file blob :$camel)" = z1 '
Signature · 1 line
2.25.1
Re: [PATCH v2 2/2] t0030-t0050: avoid pipes with Git on LHS
Am 27.02.22 um 13:24 schrieb Shubham Mishra:
Quoted 11 lines
test_expect_success\
'text plus spaces without newline at end should not show spaces' 't/t0030-stripspace.sh +3
-6- ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$sss" | git stripspace &&
t/t0030-stripspace.sh test_expect_success \ · line 264
Quoted 10 lines
t/t0030-stripspace.sh +9
-0+ ! grep " " tmp >/dev/null && + printf "$ttt$ttt$ttt$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$sss$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$sss$sss" | git stripspace && + ! grep " " tmp >/dev/null && + printf "$ttt$sss$sss$sss" | git stripspace && + ! grep " " tmp >/dev/null '
You forgot to redirect all but the first git stripspace.
Quoted 15 lines
test_expect_success\t/t0030-stripspace.sh +3
-6@@ -282,12 +292,18 @@ test_expect_success \ test_expect_success \ 'text plus spaces at end should not show spaces' ' - ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + echo "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$sss" | git stripspace >tmp &&
t/t0030-stripspace.sh test_expect_success \ · line 307
Quoted 10 lines
t/t0030-stripspace.sh +9
-0+ ! grep " " tmp>/dev/null && + echo "$ttt$ttt$ttt$sss" && + ! grep " " tmp >/dev/null && + echo "$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null '
A superficial glance at the visual pattern formed by the new lines reveals immediately that there is something foul. And indeed, one of the rewritten cases misses | git stripspace >tmp.
-- Hannes
for further reference, you can follow the discussion on my last patchset - https://lore.kernel.org/git/[email protected]/
Quoted 21 lines · Shubham Mishra
As a microproject, I remove all pipes with GIT on LHS from files t0000 to t0050.
Shubham Mishra (2):
t0001-t0028: avoid pipes with Git on LHS
t0030-t0050: avoid pipes with Git on LHSt/t0000-basic.sh | 10 +++-- t/t0022-crlf-rename.sh | 4 +- t/t0025-crlf-renormalize.sh | 4 +- t/t0027-auto-crlf.sh | 12 +++--- t/t0030-stripspace.sh | 81 ++++++++++++++++++++++++------------- t/t0050-filesystem.sh | 3 +- 6 files changed, 72 insertions(+), 42 deletions(-)base-commit:
e6ebfd0e8cbbd10878070c8a356b5ad1b3ca464e--
2.25.1
Quoted 2 lines · Shubham Mishra
for further reference, you can follow the discussion on my last patchset - https://lore.kernel.org/git/[email protected]/
In the future, you can use --in-reply-to to make sure that subsequent versions are attached to the previous version's thread.
Thanks,
Taylor
v3 cover avoid pipes with Git on LHS
In reply to Shubham Mishrachanges since v2:
* t0000: remove git command out of subshell
* t0030: fix missing redirections to "tmp" file
Shubham Mishra (2):
t0001-t0028: avoid pipes with Git on LHS
t0030-t0050: avoid pipes with Git on LHS
t/t0000-basic.sh | 10 +++-- t/t0022-crlf-rename.sh | 4 +- t/t0025-crlf-renormalize.sh | 4 +- t/t0027-auto-crlf.sh | 12 +++--- t/t0030-stripspace.sh | 75 ++++++++++++++++++++++++------------- t/t0050-filesystem.sh | 3 +- 6 files changed, 66 insertions(+), 42 deletions(-)
Range-diff against v2:
1: 2a219ace42 ! 1: 5e122c0acf t0001-t0028: avoid pipes with Git on LHS
@@ t/t0000-basic.sh: test_expect_success 'update-index D/F conflict' '
'
@@ t/t0000-basic.sh: test_expect_success 'very long name in the index handled sanely' '
+
>path4 &&
git update-index --add path4 &&
++ git ls-files -s path4 >tmp &&
(
- git ls-files -s path4 |
- sed -e "s/ .*/ /" |
-+ git ls-files -s path4 >tmp &&
+ sed -e "s/ .*/ /" tmp |
tr -d "\012" &&
echo "$a"
2: c90fc271d9 ! 2: c412380af3 t0030-t0050: avoid pipes with Git on LHS
@@ t/t0030-stripspace.sh: test_expect_success \
- ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null)
+ printf "$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
-+ printf "$ttt$ttt$sss" | git stripspace &&
++ printf "$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
-+ printf "$ttt$ttt$ttt$sss" | git stripspace &&
++ printf "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
-+ printf "$ttt$sss$sss" | git stripspace &&
++ printf "$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
-+ printf "$ttt$ttt$sss$sss" | git stripspace &&
++ printf "$ttt$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
-+ printf "$ttt$sss$sss$sss" | git stripspace &&
++ printf "$ttt$sss$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null
'
@@ t/t0030-stripspace.sh: test_expect_success \
+ echo "$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$ttt$sss" | git stripspace >tmp &&
-+ ! grep " " tmp>/dev/null &&
-+ echo "$ttt$ttt$ttt$sss" &&
++ ! grep " " tmp >/dev/null &&
++ echo "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&Signature · 1 line
2.25.1
PATCH v3 1/2 t0001-t0028: avoid pipes with Git on LHS
Pipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
--- t/t0000-basic.sh | 10 ++++++---- t/t0022-crlf-rename.sh | 4 ++-- t/t0025-crlf-renormalize.sh | 4 ++-- t/t0027-auto-crlf.sh | 12 ++++++------ 4 files changed, 16 insertions(+), 14 deletions(-)
t/t0000-basic.sh +6 -4
@@ -1089,7 +1089,8 @@ test_expect_success 'update-index D/F conflict' ' mv path2 path0 && mv tmp path2 && git update-index --add --replace path2 path0/file2 && - numpath0=$(git ls-files path0 | wc -l) && + git ls-files path0 >tmp && + numpath0=$(wc -l <tmp) && test $numpath0 = 1 '
@@ -1103,13 +1104,14 @@ test_expect_success 'very long name in the index handled sanely' ' >path4 && git update-index --add path4 && + git ls-files -s path4 >tmp && ( - git ls-files -s path4 | - sed -e "s/ .*/ /" | + sed -e "s/ .*/ /" tmp | tr -d "\012" && echo "$a" ) | git update-index --index-info && - len=$(git ls-files "a*" | wc -c) && + git ls-files "a*" >tmp && + len=$(wc -c <tmp) && test $len = 4098 '
t/t0022-crlf-rename.sh +2 -2
@@ -24,8 +24,8 @@ test_expect_success setup ' test_expect_success 'diff -M' ' - git diff-tree -M -r --name-status HEAD^ HEAD | - sed -e "s/R[0-9]*/RNUM/" >actual && + git diff-tree -M -r --name-status HEAD^ HEAD >tmp && + sed -e "s/R[0-9]*/RNUM/" tmp >actual && echo "RNUM sample elpmas" >expect && test_cmp expect actual
t/t0025-crlf-renormalize.sh +2 -2
@@ -22,8 +22,8 @@ test_expect_success 'renormalize CRLF in repo' ' i/lf w/lf attr/text=auto LF.txt i/lf w/mixed attr/text=auto CRLF_mix_LF.txt EOF - git ls-files --eol | - sed -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol >tmp && + sed -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
t/t0027-auto-crlf.sh +6 -6
@@ -311,8 +311,8 @@ checkout_files () { i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__CRLF_nul.txt i/-text w/$(stats_ascii $crlfnul) attr/$(attr_ascii $attr $aeol) crlf_false_attr__LF_nul.txt EOF - git ls-files --eol crlf_false_attr__* | - sed -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol crlf_false_attr__* >tmp && + sed -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
@@ -359,12 +359,12 @@ test_expect_success 'ls-files --eol -o Text/Binary' ' i/ w/crlf TeBi_126_CL i/ w/-text TeBi_126_CLC EOF - git ls-files --eol -o | + git ls-files --eol -o >tmp && sed -n -e "/TeBi_/{s!attr/[ ]*!!g s! ! !g s! *! !g p - }" | sort >actual && + }" tmp | sort >actual && test_cmp expect actual '
@@ -617,8 +617,8 @@ test_expect_success 'ls-files --eol -d -z' ' i/lf w/ crlf_false_attr__LF.txt i/mixed w/ crlf_false_attr__CRLF_mix_LF.txt EOF - git ls-files --eol -d | - sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" | + git ls-files --eol -d >tmp && + sed -e "s!attr/[^ ]*!!g" -e "s/ / /g" -e "s/ */ /g" tmp | sort >actual && test_cmp expect actual '
Signature · 1 line
2.25.1
PATCH v3 2/2 t0030-t0050: avoid pipes with Git on LHS
In reply to Shubham MishraPipes ignore error codes of LHS command and thus we should not use them with Git in tests. As an alternative, use a 'tmp' file to write the Git output so we can test the exit code.
--- t/t0030-stripspace.sh | 75 +++++++++++++++++++++++++++---------------- t/t0050-filesystem.sh | 3 +- 2 files changed, 50 insertions(+), 28 deletions(-)
t/t0030-stripspace.sh +48 -27
@@ -13,6 +13,10 @@ s40=' ' sss="$s40$s40$s40$s40$s40$s40$s40$s40$s40$s40" # 400 ttt="$t40$t40$t40$t40$t40$t40$t40$t40$t40$t40" # 400 +printf_git_stripspace () { + printf "$1" | git stripspace +} + test_expect_success \ 'long lines without spaces should be unchanged' ' echo "$ttt" >expect &&
@@ -225,32 +229,38 @@ test_expect_success \ test_expect_success \ 'text without newline at end should end with newline' ' - test $(printf "$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$ttt" | git stripspace | wc -l) -gt 0 + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$ttt" ' # text plus spaces at the end: test_expect_success \ 'text plus spaces without newline at end should end with newline' ' - test $(printf "$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$ttt$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$ttt$sss$sss" | git stripspace | wc -l) -gt 0 && - test $(printf "$ttt$sss$sss$sss" | git stripspace | wc -l) -gt 0 + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$ttt$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$ttt$sss$sss" && + test_stdout_line_count -gt 0 printf_git_stripspace "$ttt$sss$sss$sss" ' test_expect_success \ 'text plus spaces without newline at end should not show spaces' ' - ! (printf "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$ttt$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null ' test_expect_success \
@@ -282,12 +292,18 @@ test_expect_success \ test_expect_success \ 'text plus spaces at end should not show spaces' ' - ! (echo "$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$ttt$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$ttt$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (echo "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + echo "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + echo "$ttt$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null ' test_expect_success \
@@ -339,11 +355,16 @@ test_expect_success \ test_expect_success \ 'spaces without newline at end should not show spaces' ' - ! (printf "" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss" | git stripspace | grep " " >/dev/null) && - ! (printf "$sss$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && + printf "$sss$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null ' test_expect_success \
t/t0050-filesystem.sh +2 -1
@@ -104,7 +104,8 @@ test_expect_failure CASE_INSENSITIVE_FS 'add (with different case)' ' rm camelcase && echo 1 >CamelCase && git add CamelCase && - camel=$(git ls-files | grep -i camelcase) && + git ls-files >tmp && + camel=$(grep -i camelcase tmp) && test $(echo "$camel" | wc -l) = 1 && test "z$(git cat-file blob :$camel)" = z1 '
Signature · 1 line
2.25.1
Re: [GSoC] [PATCH v3 0/2] avoid pipes with Git on LHS
In reply to Shubham MishraAm 12.03.22 um 07:21 schrieb Shubham Mishra:
Quoted 57 lines
changes since v2:
* t0000: remove git command out of subshell
* t0030: fix missing redirections to "tmp" file
Shubham Mishra (2):
t0001-t0028: avoid pipes with Git on LHS
t0030-t0050: avoid pipes with Git on LHSt/t0000-basic.sh | 10 +++-- t/t0022-crlf-rename.sh | 4 +- t/t0025-crlf-renormalize.sh | 4 +- t/t0027-auto-crlf.sh | 12 +++--- t/t0030-stripspace.sh | 75 ++++++++++++++++++++++++------------- t/t0050-filesystem.sh | 3 +- 6 files changed, 66 insertions(+), 42 deletions(-)Range-diff against v2:
1:2a219ace42! 1:5e122c0acft0001-t0028: avoid pipes with Git on LHS@@ t/t0000-basic.sh: test_expect_success 'update-index D/F conflict' ' ' @@ t/t0000-basic.sh: test_expect_success 'very long name in the index handled sanely' ' + >path4 && git update-index --add path4 && ++ git ls-files -s path4 >tmp && ( - git ls-files -s path4 | - sed -e "s/ .*/ /" | -+ git ls-files -s path4 >tmp && + sed -e "s/ .*/ /" tmp | tr -d "\012" && echo "$a" 2: c90fc271d9 ! 2: c412380af3 t0030-t0050: avoid pipes with Git on LHS @@ t/t0030-stripspace.sh: test_expect_success \ - ! (printf "$ttt$sss$sss$sss" | git stripspace | grep " " >/dev/null) + printf "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && -+ printf "$ttt$ttt$sss" | git stripspace && ++ printf "$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && -+ printf "$ttt$ttt$ttt$sss" | git stripspace && ++ printf "$ttt$ttt$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && -+ printf "$ttt$sss$sss" | git stripspace && ++ printf "$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && -+ printf "$ttt$ttt$sss$sss" | git stripspace && ++ printf "$ttt$ttt$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null && -+ printf "$ttt$sss$sss$sss" | git stripspace && ++ printf "$ttt$sss$sss$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null ' @@ t/t0030-stripspace.sh: test_expect_success \ + echo "$ttt$sss" | git stripspace >tmp && + ! grep " " tmp >/dev/null &&
Quoted 8 lines
+ echo "$ttt$ttt$sss" | git stripspace >tmp &&
-+ ! grep " " tmp>/dev/null &&
-+ echo "$ttt$ttt$ttt$sss" &&
++ ! grep " " tmp >/dev/null &&
++ echo "$ttt$ttt$ttt$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&
+ echo "$ttt$sss$sss" | git stripspace >tmp &&
+ ! grep " " tmp >/dev/null &&This round addresses all my comments. Thanks!
-- Hannes
Re: [GSoC] [PATCH v3 0/2] avoid pipes with Git on LHS
Quoted 2 lines
This round addresses all my comments. Thanks!
Thanks, this series really helped me learn how code reviewing works here :). looking forward to picking other tasks.
Thanks,
Shubham