t: general test cleanup + `set -o pipefail`
PATCH v5 6/26 t3600: use test_line_count() where possible
In reply to Denton LiuSince we have a helper function that can test the number of lines in a file that gives better debugging information on failure, use test_line_count() to test the number of lines.
--- t/t3600-rm.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
t/t3600-rm.sh +4 -3
@@ -113,9 +113,10 @@ test_expect_success '"rm" command printed' ' echo frotz >test-file && git add test-file && git commit -m "add file for rm test" && - git rm test-file >rm-output && - test $(grep "^rm " rm-output | wc -l) = 1 && - rm -f test-file rm-output && + git rm test-file >rm-output.raw && + grep "^rm " rm-output.raw >rm-output && + test_line_count = 1 rm-output && + rm -f test-file rm-output.raw rm-output && git commit -m "remove file from rm test" '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 7/26 t3600: stop losing return codes of git commands
In reply to Denton LiuWhen a command is in a non-assignment command substitution, the return code will be lost in favour of the surrounding command's. As a result, if a git command fails, we won't know about it. Rewrite instances of this so that git commands are either run in an assignment-only command substitution so that their return codes aren't lost.
--- t/t3600-rm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/t3600-rm.sh +4 -2
@@ -304,7 +304,8 @@ EOF test_expect_success 'rm removes empty submodules from work tree' ' mkdir submod && - git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) submod && + hash=$(git rev-parse HEAD) && + git update-index --add --cacheinfo 160000 "$hash" submod && git config -f .gitmodules submodule.sub.url ./. && git config -f .gitmodules submodule.sub.path submod && git submodule init &&
@@ -623,7 +624,8 @@ test_expect_success 'setup subsubmodule' ' git submodule update && ( cd submod && - git update-index --add --cacheinfo 160000 $(git rev-parse HEAD) subsubmod && + hash=$(git rev-parse HEAD) && + git update-index --add --cacheinfo 160000 "$hash" subsubmod && git config -f .gitmodules submodule.sub.url ../. && git config -f .gitmodules submodule.sub.path subsubmod && git submodule init &&
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 8/26 t3600: comment on inducing SIGPIPE in `git rm`
In reply to Denton LiuAdd a comment about intentionally inducing SIGPIPE since this is unusual and future developers should be aware. Also, even though we are trying to refactor git commands out of the upstream of pipes, we cannot do it here since we rely on it being upstream to induce SIGPIPE. Comment on that as well so that future developers do not try to change it.
--- t/t3600-rm.sh | 1 + 1 file changed, 1 insertion(+)
t/t3600-rm.sh +1 -0
@@ -251,6 +251,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' echo "100644 $hash 0 some-file-$i" i=$(( $i + 1 )) done | git update-index --index-info && + # git command is intentionally placed upstream of pipe to induce SIGPIPE git rm -n "some-file-*" | : && test_path_is_missing .git/index.lock '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 9/26 t4015: stop losing return codes of git commands
In reply to Denton LiuCurrently, there are two ways where the return codes of git commands are lost. The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream.
The other way is when a command is in a non-assignment command substitution. The return code will be lost in favour of the surrounding command's. Rewrite instances of this so that git commands are either run on their own or in an assignment-only command substitution.
--- t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 47 deletions(-)
t/t4015-diff-whitespace.sh +72 -47
@@ -16,7 +16,8 @@ test_expect_success "Ray Lehtiniemi's example" ' } while (0); EOF git update-index --add x && - before=$(git rev-parse --short $(git hash-object x)) && + old_hash_x=$(git hash-object x) && + before=$(git rev-parse --short "$old_hash_x") && cat <<-\EOF >x && do
@@ -25,7 +26,8 @@ test_expect_success "Ray Lehtiniemi's example" ' } while (0); EOF - after=$(git rev-parse --short $(git hash-object x)) && + new_hash_x=$(git hash-object x) && + after=$(git rev-parse --short "$new_hash_x") && cat <<-EOF >expect && diff --git a/x b/x
@@ -63,7 +65,8 @@ test_expect_success 'another test, without options' ' EOF git update-index x && - before=$(git rev-parse --short $(git hash-object x)) && + old_hash_x=$(git hash-object x) && + before=$(git rev-parse --short "$old_hash_x") && tr "_" " " <<-\EOF >x && _ whitespace at beginning
@@ -73,7 +76,8 @@ test_expect_success 'another test, without options' ' unchanged line CR at end EOF - after=$(git rev-parse --short $(git hash-object x)) && + new_hash_x=$(git hash-object x) && + after=$(git rev-parse --short "$new_hash_x") && tr "Q_" "\015 " <<-EOF >expect && diff --git a/x b/x
@@ -526,13 +530,15 @@ test_expect_success 'ignore-blank-lines: mix changes and blank lines' ' test_expect_success 'check mixed spaces and tabs in indent' ' # This is indented with SP HT SP. echo " foo();" >x && - git diff --check | grep "space before tab in indent" + test_must_fail git diff --check >check && + grep "space before tab in indent" check ' test_expect_success 'check mixed tabs and spaces in indent' ' # This is indented with HT SP HT. echo " foo();" >x && - git diff --check | grep "space before tab in indent" + test_must_fail git diff --check >check && + grep "space before tab in indent" check ' test_expect_success 'check with no whitespace errors' '
@@ -753,20 +759,23 @@ test_expect_success 'check tab-in-indent excluded from wildcard whitespace attri test_expect_success 'line numbers in --check output are correct' ' echo "" >x && echo "foo(); " >>x && - git diff --check | grep "x:2:" + test_must_fail git diff --check >check && + grep "x:2:" check ' test_expect_success 'checkdiff detects new trailing blank lines (1)' ' echo "foo();" >x && echo "" >>x && - git diff --check | grep "new blank line" + test_must_fail git diff --check >check && + grep "new blank line" check ' test_expect_success 'checkdiff detects new trailing blank lines (2)' ' { echo a; echo b; echo; echo; } >x && git add x && { echo a; echo; echo; echo; echo; } >x && - git diff --check | grep "new blank line" + test_must_fail git diff --check >check && + grep "new blank line" check ' test_expect_success 'checkdiff allows new blank lines' '
@@ -794,14 +803,16 @@ test_expect_success 'whitespace-only changes reported across renames' ' git reset --hard && for i in 1 2 3 4 5 6 7 8 9; do echo "$i$i$i$i$i$i"; done >x && git add x && - before=$(git rev-parse --short $(git hash-object x)) && + hash_x=$(git hash-object x) && + before=$(git rev-parse --short "$hash_x") && git commit -m "base" && sed -e "5s/^/ /" x >z && git rm x && git add z && - after=$(git rev-parse --short $(git hash-object z)) && - git diff -w -M --cached | - sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" >actual && + hash_z=$(git hash-object z) && + after=$(git rev-parse --short "$hash_z") && + git diff -w -M --cached >actual.raw && + sed -e "/^similarity index /s/[0-9][0-9]*/NUM/" actual.raw >actual && cat <<-EOF >expect && diff --git a/x b/z similarity index NUM%
@@ -840,7 +851,8 @@ test_expect_success 'combined diff with autocrlf conversion' ' git config core.autocrlf true && test_must_fail git merge master && - git diff | sed -e "1,/^@@@/d" >actual && + git diff >actual.raw && + sed -e "1,/^@@@/d" actual.raw >actual && ! grep "^-" actual '
@@ -864,11 +876,14 @@ test_expect_success 'diff that introduces a line with only tabs' ' git config core.whitespace blank-at-eol && git reset --hard && echo "test" >x && - before=$(git rev-parse --short $(git hash-object x)) && + old_hash_x=$(git hash-object x) && + before=$(git rev-parse --short "$old_hash_x") && git commit -m "initial" x && echo "{NTN}" | tr "NT" "\n\t" >>x && - after=$(git rev-parse --short $(git hash-object x)) && - git diff --color | test_decode_color >current && + new_hash_x=$(git hash-object x) && + after=$(git rev-parse --short "$new_hash_x") && + git diff --color >current.raw && + test_decode_color <current.raw >current && cat >expected <<-EOF && <BOLD>diff --git a/x b/x<RESET>
@@ -891,17 +906,19 @@ test_expect_success 'diff that introduces and removes ws breakages' ' echo "0. blank-at-eol " && echo "1. blank-at-eol " } >x && - before=$(git rev-parse --short $(git hash-object x)) && + old_hash_x=$(git hash-object x) && + before=$(git rev-parse --short "$old_hash_x") && git commit -a --allow-empty -m preimage && { echo "0. blank-at-eol " && echo "1. still-blank-at-eol " && echo "2. and a new line " } >x && - after=$(git rev-parse --short $(git hash-object x)) && + new_hash_x=$(git hash-object x) && + after=$(git rev-parse --short "$new_hash_x") && - git diff --color | - test_decode_color >current && + git diff --color >current.raw && + test_decode_color <current.raw >current && cat >expected <<-EOF && <BOLD>diff --git a/x b/x<RESET>
@@ -925,14 +942,16 @@ test_expect_success 'ws-error-highlight test setup' ' echo "0. blank-at-eol " && echo "1. blank-at-eol " } >x && - before=$(git rev-parse --short $(git hash-object x)) && + old_hash_x=$(git hash-object x) && + before=$(git rev-parse --short "$old_hash_x") && git commit -a --allow-empty -m preimage && { echo "0. blank-at-eol " && echo "1. still-blank-at-eol " && echo "2. and a new line " } >x && - after=$(git rev-parse --short $(git hash-object x)) && + new_hash_x=$(git hash-object x) && + after=$(git rev-parse --short "$new_hash_x") && cat >expect.default-old <<-EOF && <BOLD>diff --git a/x b/x<RESET>
@@ -974,32 +993,32 @@ test_expect_success 'ws-error-highlight test setup' ' test_expect_success 'test --ws-error-highlight option' ' - git diff --color --ws-error-highlight=default,old | - test_decode_color >current && + git diff --color --ws-error-highlight=default,old >current.raw && + test_decode_color <current.raw >current && test_cmp expect.default-old current && - git diff --color --ws-error-highlight=all | - test_decode_color >current && + git diff --color --ws-error-highlight=all >current.raw && + test_decode_color <current.raw >current && test_cmp expect.all current && - git diff --color --ws-error-highlight=none | - test_decode_color >current && + git diff --color --ws-error-highlight=none >current.raw && + test_decode_color <current.raw >current && test_cmp expect.none current ' test_expect_success 'test diff.wsErrorHighlight config' ' - git -c diff.wsErrorHighlight=default,old diff --color | - test_decode_color >current && + git -c diff.wsErrorHighlight=default,old diff --color >current.raw && + test_decode_color <current.raw >current && test_cmp expect.default-old current && - git -c diff.wsErrorHighlight=all diff --color | - test_decode_color >current && + git -c diff.wsErrorHighlight=all diff --color >current.raw && + test_decode_color <current.raw >current && test_cmp expect.all current && - git -c diff.wsErrorHighlight=none diff --color | - test_decode_color >current && + git -c diff.wsErrorHighlight=none diff --color >current.raw && + test_decode_color <current.raw >current && test_cmp expect.none current '
@@ -1007,18 +1026,18 @@ test_expect_success 'test diff.wsErrorHighlight config' ' test_expect_success 'option overrides diff.wsErrorHighlight' ' git -c diff.wsErrorHighlight=none \ - diff --color --ws-error-highlight=default,old | - test_decode_color >current && + diff --color --ws-error-highlight=default,old >current.raw && + test_decode_color <current.raw >current && test_cmp expect.default-old current && git -c diff.wsErrorHighlight=default \ - diff --color --ws-error-highlight=all | - test_decode_color >current && + diff --color --ws-error-highlight=all >current.raw && + test_decode_color <current.raw >current && test_cmp expect.all current && git -c diff.wsErrorHighlight=all \ - diff --color --ws-error-highlight=none | - test_decode_color >current && + diff --color --ws-error-highlight=none >current.raw && + test_decode_color <current.raw >current && test_cmp expect.none current '
@@ -1038,7 +1057,8 @@ test_expect_success 'detect moved code, complete file' ' git mv test.c main.c && test_config color.diff.oldMoved "normal red" && test_config color.diff.newMoved "normal green" && - git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual && + git diff HEAD --color-moved=zebra --color --no-renames >actual.raw && + test_decode_color <actual.raw >actual && cat >expected <<-EOF && <BOLD>diff --git a/main.c b/main.c<RESET> <BOLD>new file mode 100644<RESET>
@@ -1141,9 +1161,12 @@ test_expect_success 'detect malicious moved code, inside file' ' bar(); } EOF - after_main=$(git rev-parse --short $(git hash-object main.c)) && - after_test=$(git rev-parse --short $(git hash-object test.c)) && - git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual && + hash_main=$(git hash-object main.c) && + after_main=$(git rev-parse --short "$hash_main") && + hash_test=$(git hash-object test.c) && + after_test=$(git rev-parse --short "$hash_test") && + git diff HEAD --no-renames --color-moved=zebra --color >actual.raw && + test_decode_color <actual.raw >actual && cat <<-EOF >expected && <BOLD>diff --git a/main.c b/main.c<RESET> <BOLD>index $before_main..$after_main 100644<RESET>
@@ -1192,7 +1215,8 @@ test_expect_success 'plain moved code, inside file' ' test_config color.diff.oldMovedAlternative "blue" && test_config color.diff.newMovedAlternative "yellow" && # needs previous test as setup - git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual && + git diff HEAD --no-renames --color-moved=plain --color >actual.raw && + test_decode_color <actual.raw >actual && cat <<-EOF >expected && <BOLD>diff --git a/main.c b/main.c<RESET> <BOLD>index $before_main..$after_main 100644<RESET>
@@ -1771,7 +1795,8 @@ test_expect_success 'move detection with submodules' ' ! grep BRED decoded_actual && # nor did we mess with it another way - git diff --submodule=diff --color | test_decode_color >expect && + git diff --submodule=diff --color >expect.raw && + test_decode_color <expect.raw >expect && test_cmp expect decoded_actual && rm -rf bananas && git submodule deinit bananas
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 11/26 t4138: stop losing return codes of git commands
In reply to Denton LiuIn a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that we will know if a command fails.
--- t/t4138-apply-ws-expansion.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
t/t4138-apply-ws-expansion.sh +8 -8
@@ -17,8 +17,8 @@ test_expect_success setup ' printf "\t%s\n" 1 2 3 >after && printf "%64s\n" a b c >>after && printf "\t%s\n" 4 5 6 >>after && - git diff --no-index before after | - sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch && + test_expect_code 1 git diff --no-index before after >patch1.patch.raw && + sed -e "s/before/test-1/" -e "s/after/test-1/" patch1.patch.raw >patch1.patch && printf "%64s\n" 1 2 3 4 5 6 >test-1 && printf "%64s\n" 1 2 3 a b c 4 5 6 >expect-1 &&
@@ -33,8 +33,8 @@ test_expect_success setup ' x=$(( $x + 1 )) done && printf "\t%s\n" d e f >>after && - git diff --no-index before after | - sed -e "s/before/test-2/" -e "s/after/test-2/" >patch2.patch && + test_expect_code 1 git diff --no-index before after >patch2.patch.raw && + sed -e "s/before/test-2/" -e "s/after/test-2/" patch2.patch.raw >patch2.patch && printf "%64s\n" a b c d e f >test-2 && printf "%64s\n" a b c >expect-2 && x=1 &&
@@ -56,8 +56,8 @@ test_expect_success setup ' x=$(( $x + 1 )) done && printf "\t%s\n" d e f >>after && - git diff --no-index before after | - sed -e "s/before/test-3/" -e "s/after/test-3/" >patch3.patch && + test_expect_code 1 git diff --no-index before after >patch3.patch.raw && + sed -e "s/before/test-3/" -e "s/after/test-3/" patch3.patch.raw >patch3.patch && printf "%64s\n" a b c d e f >test-3 && printf "%64s\n" a b c >expect-3 && x=0 &&
@@ -84,8 +84,8 @@ test_expect_success setup ' printf "\t%02d\n" $x >>after x=$(( $x + 1 )) done && - git diff --no-index before after | - sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch && + test_expect_code 1 git diff --no-index before after >patch4.patch.raw && + sed -e "s/before/test-4/" -e "s/after/test-4/" patch4.patch.raw >patch4.patch && >test-4 && x=0 && while test $x -lt 50
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 10/26 t4015: use test_write_lines()
In reply to Denton LiuInstead of rolling our own method to write out some lines into a file, use the existing test_write_lines().
--- t/t4015-diff-whitespace.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t4015-diff-whitespace.sh +2 -2
@@ -771,9 +771,9 @@ test_expect_success 'checkdiff detects new trailing blank lines (1)' ' ' test_expect_success 'checkdiff detects new trailing blank lines (2)' ' - { echo a; echo b; echo; echo; } >x && + test_write_lines a b "" "" >x && git add x && - { echo a; echo; echo; echo; echo; } >x && + test_write_lines a "" "" "" "" >x && test_must_fail git diff --check >check && grep "new blank line" check '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 12/26 t5317: stop losing return codes of git commands
In reply to Denton LiuCurrently, there are two ways where the return codes of git commands are lost. The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream.
The other way is when a command is in a non-assignment command substitution. The return code will be lost in favour of the surrounding command's. Rewrite instances of this such that git commands output to a file and surrounding commands only call command substitutions with non-git commands.
--- t/t5317-pack-objects-filter-objects.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-)
t/t5317-pack-objects-filter-objects.sh +7 -6
@@ -72,7 +72,8 @@ test_expect_success 'get an error for missing tree object' ' echo foo >r5/foo && git -C r5 add foo && git -C r5 commit -m "foo" && - del=$(git -C r5 rev-parse HEAD^{tree} | sed "s|..|&/|") && + git -C r5 rev-parse HEAD^{tree} >tree && + del=$(sed "s|..|&/|" tree) && rm r5/.git/objects/$del && test_must_fail git -C r5 pack-objects --revs --stdout 2>bad_tree <<-EOF && HEAD
@@ -230,10 +231,9 @@ test_expect_success 'verify explicitly specifying oversized blob in input' ' awk -f print_2.awk ls_files_result | sort >expected && - git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k >filter.pack <<-EOF && - HEAD - $(git -C r2 rev-parse HEAD:large.10000) - EOF + echo HEAD >objects && + git -C r2 rev-parse HEAD:large.10000 >>objects && + git -C r2 pack-objects --revs --stdout --filter=blob:limit=1k <objects >filter.pack && git -C r2 index-pack ../filter.pack && git -C r2 verify-pack -v ../filter.pack >verify_result &&
@@ -377,7 +377,8 @@ test_expect_success 'verify sparse:oid=OID' ' awk -f print_2.awk ls_files_result | sort >expected && - oid=$(git -C r4 ls-files -s pattern | awk -f print_2.awk) && + git -C r4 ls-files -s pattern >staged && + oid=$(awk -f print_2.awk staged) && git -C r4 pack-objects --revs --stdout --filter=sparse:oid=$oid >filter.pack <<-EOF && HEAD EOF
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 13/26 t5317: use ! grep to check for no matching lines
In reply to Denton LiuSeveral times in t5317, we would use wc -l to ensure that a grep result is empty. However, grep already has a way to do that... Its return code! Use ! grep in the cases where we are ensuring that there are no matching lines.
While at it, drop unnecessary invocations of awk and sort in each affected test since those commands do not influence the outcome. It's not clear why that extra work was being done in the first place, and the code's history doesn't shed any light on the matter since these tests were simply born this way[1], likely due to copy-paste programming. The unnecessary work wasn't noticed even when the code was later touched for various cleanups[2][3].
[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21) [2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05) [3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05)
--- t/t5317-pack-objects-filter-objects.sh | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-)
t/t5317-pack-objects-filter-objects.sh +3 -18
@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' ' git -C r1 index-pack ../filter.pack && git -C r1 verify-pack -v ../filter.pack >verify_result && - grep blob verify_result | - awk -f print_1.awk | - sort >observed && - - nr=$(wc -l <observed) && - test 0 -eq $nr + ! grep blob verify_result ' test_expect_success 'verify normal and blob:none packfiles have same commits/trees' '
@@ -149,12 +144,7 @@ test_expect_success 'verify blob:limit=500 omits all blobs' ' git -C r2 index-pack ../filter.pack && git -C r2 verify-pack -v ../filter.pack >verify_result && - grep blob verify_result | - awk -f print_1.awk | - sort >observed && - - nr=$(wc -l <observed) && - test 0 -eq $nr + ! grep blob verify_result ' test_expect_success 'verify blob:limit=1000' '
@@ -164,12 +154,7 @@ test_expect_success 'verify blob:limit=1000' ' git -C r2 index-pack ../filter.pack && git -C r2 verify-pack -v ../filter.pack >verify_result && - grep blob verify_result | - awk -f print_1.awk | - sort >observed && - - nr=$(wc -l <observed) && - test 0 -eq $nr + ! grep blob verify_result ' test_expect_success 'verify blob:limit=1001' '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 14/26 t5703: simplify one-time-sed generation logic
In reply to Denton LiuIn inconsistency(), we had two git rev-parse invocations in the upstream of a pipe within a command substitution. In case this invocation ever failed, its exit code would be swallowed up and we would not know about it.
Pull the command substitutions out into variable assignments so that their return codes are not lost.
Drop the pipe into tr because the $(...) substitution already takes care of stripping out newlines, so the tr invocations in the code are superfluous.
Finally, given the way the tests actually employ "one-time-sed" via $(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, convert the printf into an echo. This makes it consistent with the final "server loses a ref - ref in want" test, which does use echo rather than printf.
--- t/t5703-upload-pack-ref-in-want.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
t/t5703-upload-pack-ref-in-want.sh +3 -4
@@ -312,10 +312,9 @@ inconsistency () { # repository appears to change during negotiation, for example, when # different servers in a load-balancing arrangement serve (stateless) # RPCs during a single negotiation. - printf "s/%s/%s/" \ - $(git -C "$REPO" rev-parse $1 | tr -d "\n") \ - $(git -C "$REPO" rev-parse $2 | tr -d "\n") \ - >"$HTTPD_ROOT_PATH/one-time-sed" + oid1=$(git -C "$REPO" rev-parse $1) && + oid2=$(git -C "$REPO" rev-parse $2) && + echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed" } test_expect_success 'server is initially ahead - no ref in want' '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 15/26 t5703: stop losing return codes of git commands
In reply to Denton LiuCurrently, there are two ways where the return codes of git commands are lost. The first way is when a command is in the upstream of a pipe. In a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream.
The other way is when a command is in a non-assignment command substitution. The return code will be lost in favour of the surrounding command's. Rewrite instances of this such that git commands are in an assignment-only command substitution.
--- t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-)
t/t5703-upload-pack-ref-in-want.sh +29 -17
@@ -18,14 +18,16 @@ get_actual_commits () { p }' <out | test-tool pkt-line unpack-sideband >o.pack && git index-pack o.pack && - git verify-pack -v o.idx | grep commit | cut -c-40 | sort >actual_commits + git verify-pack -v o.idx >objs && + grep commit objs | cut -c-40 | sort >actual_commits } check_output () { get_actual_refs && test_cmp expected_refs actual_refs && get_actual_commits && - test_cmp expected_commits actual_commits + sort expected_commits >sorted_commits && + test_cmp sorted_commits actual_commits } # c(o/foo) d(o/bar)
@@ -75,17 +77,19 @@ test_expect_success 'invalid want-ref line' ' ' test_expect_success 'basic want-ref' ' + oid=$(git rev-parse f) && cat >expected_refs <<-EOF && - $(git rev-parse f) refs/heads/master + $oid refs/heads/master EOF - git rev-parse f | sort >expected_commits && + git rev-parse f >expected_commits && + oid=$(git rev-parse a) && test-tool pkt-line pack >in <<-EOF && command=fetch 0001 no-progress want-ref refs/heads/master - have $(git rev-parse a) + have $oid done 0000 EOF
@@ -95,19 +99,22 @@ test_expect_success 'basic want-ref' ' ' test_expect_success 'multiple want-ref lines' ' + oid_c=$(git rev-parse c) && + oid_d=$(git rev-parse d) && cat >expected_refs <<-EOF && - $(git rev-parse c) refs/heads/o/foo - $(git rev-parse d) refs/heads/o/bar + $oid_c refs/heads/o/foo + $oid_d refs/heads/o/bar EOF - git rev-parse c d | sort >expected_commits && + git rev-parse c d >expected_commits && + oid=$(git rev-parse b) && test-tool pkt-line pack >in <<-EOF && command=fetch 0001 no-progress want-ref refs/heads/o/foo want-ref refs/heads/o/bar - have $(git rev-parse b) + have $oid done 0000 EOF
@@ -117,10 +124,11 @@ test_expect_success 'multiple want-ref lines' ' ' test_expect_success 'mix want and want-ref' ' + oid=$(git rev-parse f) && cat >expected_refs <<-EOF && - $(git rev-parse f) refs/heads/master + $oid refs/heads/master EOF - git rev-parse e f | sort >expected_commits && + git rev-parse e f >expected_commits && test-tool pkt-line pack >in <<-EOF && command=fetch
@@ -138,17 +146,19 @@ test_expect_success 'mix want and want-ref' ' ' test_expect_success 'want-ref with ref we already have commit for' ' + oid=$(git rev-parse c) && cat >expected_refs <<-EOF && - $(git rev-parse c) refs/heads/o/foo + $oid refs/heads/o/foo EOF >expected_commits && + oid=$(git rev-parse c) && test-tool pkt-line pack >in <<-EOF && command=fetch 0001 no-progress want-ref refs/heads/o/foo - have $(git rev-parse c) + have $oid done 0000 EOF
@@ -211,13 +221,14 @@ test_expect_success 'fetching with exact OID' ' rm -rf local && cp -r "$LOCAL_PRISTINE" local && + oid=$(git -C "$REPO" rev-parse d) && GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \ - $(git -C "$REPO" rev-parse d):refs/heads/actual && + "$oid":refs/heads/actual && git -C "$REPO" rev-parse "d" >expected && git -C local rev-parse refs/heads/actual >actual && test_cmp expected actual && - grep "want $(git -C "$REPO" rev-parse d)" log + grep "want $oid" log ' test_expect_success 'fetching multiple refs' '
@@ -239,13 +250,14 @@ test_expect_success 'fetching ref and exact OID' ' rm -rf local && cp -r "$LOCAL_PRISTINE" local && + oid=$(git -C "$REPO" rev-parse b) && GIT_TRACE_PACKET="$(pwd)/log" git -C local fetch origin \ - master $(git -C "$REPO" rev-parse b):refs/heads/actual && + master "$oid":refs/heads/actual && git -C "$REPO" rev-parse "master" "b" >expected && git -C local rev-parse refs/remotes/origin/master refs/heads/actual >actual && test_cmp expected actual && - grep "want $(git -C "$REPO" rev-parse b)" log && + grep "want $oid" log && grep "want-ref refs/heads/master" log '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 16/26 t7501: remove spaces after redirect operators
In reply to Denton LiuFor shell scripts, the usual convention is for there to be no space after redirection operators, (e.g. >file, not > file). Remove these spaces wherever they appear.
--- t/t7501-commit-basic-functionality.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-)
t/t7501-commit-basic-functionality.sh +11 -11
@@ -150,7 +150,7 @@ test_expect_success 'setup: commit message from file' ' test_expect_success 'amend commit' ' cat >editor <<-\EOF && #!/bin/sh - sed -e "s/a file/an amend commit/g" < "$1" > "$1-" + sed -e "s/a file/an amend commit/g" <"$1" >"$1-" mv "$1-" "$1" EOF chmod 755 editor &&
@@ -263,7 +263,7 @@ test_expect_success 'using message from other commit' ' test_expect_success 'editing message from other commit' ' cat >editor <<-\EOF && #!/bin/sh - sed -e "s/amend/older/g" < "$1" > "$1-" + sed -e "s/amend/older/g" <"$1" >"$1-" mv "$1-" "$1" EOF chmod 755 editor &&
@@ -367,7 +367,7 @@ test_expect_success 'amend commit to fix author' ' -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ expected && git commit --amend --author="$author" && - git cat-file -p HEAD > current && + git cat-file -p HEAD >current && test_cmp expected current '
@@ -382,7 +382,7 @@ test_expect_success 'amend commit to fix date' ' -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ expected && git commit --amend --date="$newtick" && - git cat-file -p HEAD > current && + git cat-file -p HEAD >current && test_cmp expected current '
@@ -448,7 +448,7 @@ test_expect_success 'signoff gap' ' git commit -s -m "welcome $alt" && - git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && + git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && ( echo welcome && echo &&
@@ -468,7 +468,7 @@ test_expect_success 'signoff gap 2' ' We have now $alt" && - git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && + git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && ( echo welcome && echo &&
@@ -489,7 +489,7 @@ test_expect_success 'signoff respects trailer config' ' non-trailer line Myfooter: x" && - git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && + git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && ( echo subject && echo &&
@@ -506,7 +506,7 @@ Myfooter: x" && non-trailer line Myfooter: x" && - git cat-file commit HEAD | sed -e "1,/^\$/d" > actual && + git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && ( echo subject && echo &&
@@ -560,14 +560,14 @@ test_expect_success 'amend commit to fix author' ' -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ expected && git commit --amend --author="$author" && - git cat-file -p HEAD > current && + git cat-file -p HEAD >current && test_cmp expected current ' test_expect_success 'git commit <file> with dirty index' ' - echo tacocat > elif && - echo tehlulz > chz && + echo tacocat >elif && + echo tehlulz >chz && git add chz && git commit elif -m "tacocat is a palindrome" && git show --stat | grep elif &&
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 17/26 t7501: stop losing return codes of git commands
In reply to Denton LiuIn a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that we will know if a command fails.
In the 'interactive add' test case, we prepend a test_must_fail to git commit --interactive. When there are no changes to commit, git commit will exit with status code 1. Following along with the rest of the file, we use test_must_fail to test for this case.
--- t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-)
t/t7501-commit-basic-functionality.sh +39 -30
@@ -285,9 +285,8 @@ test_expect_success 'overriding author from command line' ' ' test_expect_success PERL 'interactive add' ' - echo 7 | - git commit --interactive | - grep "What now" + echo 7 | test_must_fail git commit --interactive >out && + grep "What now" out ' test_expect_success PERL "commit --interactive doesn't change index if editor aborts" '
@@ -362,10 +361,10 @@ test_expect_success 'amend commit to fix author' ' oldtick=$GIT_AUTHOR_DATE && test_tick && git reset --hard && - git cat-file -p HEAD | + git cat-file -p HEAD >commit && sed -e "s/author.*/author $author $oldtick/" \ - -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ - expected && + -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \ + commit >expected && git commit --amend --author="$author" && git cat-file -p HEAD >current && test_cmp expected current
@@ -377,10 +376,10 @@ test_expect_success 'amend commit to fix date' ' test_tick && newtick=$GIT_AUTHOR_DATE && git reset --hard && - git cat-file -p HEAD | + git cat-file -p HEAD >commit && sed -e "s/author.*/author $author $newtick/" \ - -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ - expected && + -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \ + commit >expected && git commit --amend --date="$newtick" && git cat-file -p HEAD >current && test_cmp expected current
@@ -409,12 +408,13 @@ test_expect_success 'sign off (1)' ' echo 1 >positive && git add positive && git commit -s -m "thank you" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo thank you && echo && - git var GIT_COMMITTER_IDENT | - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" + git var GIT_COMMITTER_IDENT >ident && + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident ) >expected && test_cmp expected actual
@@ -428,13 +428,14 @@ test_expect_success 'sign off (2)' ' git commit -s -m "thank you $existing" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo thank you && echo && echo $existing && - git var GIT_COMMITTER_IDENT | - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" + git var GIT_COMMITTER_IDENT >ident && + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident ) >expected && test_cmp expected actual
@@ -448,13 +449,14 @@ test_expect_success 'signoff gap' ' git commit -s -m "welcome $alt" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo welcome && echo && echo $alt && - git var GIT_COMMITTER_IDENT | - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" + git var GIT_COMMITTER_IDENT >ident && + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident ) >expected && test_cmp expected actual '
@@ -468,15 +470,16 @@ test_expect_success 'signoff gap 2' ' We have now $alt" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo welcome && echo && echo We have now && echo $alt && echo && - git var GIT_COMMITTER_IDENT | - sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" + git var GIT_COMMITTER_IDENT >ident && + sed -e "s/>.*/>/" -e "s/^/Signed-off-by: /" ident ) >expected && test_cmp expected actual '
@@ -489,7 +492,8 @@ test_expect_success 'signoff respects trailer config' ' non-trailer line Myfooter: x" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo subject && echo &&
@@ -506,7 +510,8 @@ Myfooter: x" && non-trailer line Myfooter: x" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo subject && echo &&
@@ -538,7 +543,8 @@ test_expect_success 'multiple -m' ' >negative && git add negative && git commit -m "one" -m "two" -m "three" && - git cat-file commit HEAD | sed -e "1,/^\$/d" >actual && + git cat-file commit HEAD >commit && + sed -e "1,/^\$/d" commit >actual && ( echo one && echo &&
@@ -555,10 +561,10 @@ test_expect_success 'amend commit to fix author' ' oldtick=$GIT_AUTHOR_DATE && test_tick && git reset --hard && - git cat-file -p HEAD | + git cat-file -p HEAD >commit && sed -e "s/author.*/author $author $oldtick/" \ - -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" > \ - expected && + -e "s/^\(committer.*> \).*$/\1$GIT_COMMITTER_DATE/" \ + commit >expected && git commit --amend --author="$author" && git cat-file -p HEAD >current && test_cmp expected current
@@ -570,8 +576,10 @@ test_expect_success 'git commit <file> with dirty index' ' echo tehlulz >chz && git add chz && git commit elif -m "tacocat is a palindrome" && - git show --stat | grep elif && - git diff --cached | grep chz + git show --stat >stat && + grep elif stat && + git diff --cached >diff && + grep chz diff ' test_expect_success 'same tree (single parent)' '
@@ -584,7 +592,8 @@ test_expect_success 'same tree (single parent)' ' test_expect_success 'same tree (single parent) --allow-empty' ' git commit --allow-empty -m "forced empty" && - git cat-file commit HEAD | grep forced + git cat-file commit HEAD >commit && + grep forced commit '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 18/26 t7700: drop redirections to /dev/null
In reply to Denton LiuSince output is silenced when running without -v and debugging output is useful with -v, remove redirections to /dev/null as it is not useful.
In one case where the output of stdout is consumed, redirect the output of test_commit to stderr.
--- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
t/t7700-repack.sh +3 -3
@@ -5,7 +5,7 @@ test_description='git repack works correctly' . ./test-lib.sh commit_and_pack() { - test_commit "$@" >/dev/null && + test_commit "$@" 1>&2 && SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && echo pack-${SHA1}.pack }
@@ -19,7 +19,7 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' # Create two packs # The first pack will contain all of the objects except one git rev-list --objects --all | grep -v file2 | - git pack-objects pack > /dev/null && + git pack-objects pack && # The second pack will contain the excluded object packsha1=$(git rev-list --objects --all | grep file2 | git pack-objects pack) &&
@@ -235,7 +235,7 @@ test_expect_success 'incremental repack does not complain' ' test_expect_success 'bitmaps can be disabled on bare repos' ' git -c repack.writeBitmaps=false -C bare.git repack -ad && - bitmap=$(ls bare.git/objects/pack/*.bitmap 2>/dev/null || :) && + bitmap=$(ls bare.git/objects/pack/*.bitmap || :) && test -z "$bitmap" '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 19/26 t7700: remove spaces after redirect operators
In reply to Denton LiuFor shell scripts, the usual convention is for there to be no space after redirection operators, (e.g. >file, not > file). Remove these spaces wherever they appear.
--- t/t7700-repack.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-)
t/t7700-repack.sh +9 -9
@@ -11,8 +11,8 @@ commit_and_pack() { } test_expect_success 'objects in packs marked .keep are not repacked' ' - echo content1 > file1 && - echo content2 > file2 && + echo content1 >file1 && + echo content2 >file2 && git add . && test_tick && git commit -m initial_commit &&
@@ -75,8 +75,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && - echo $(pwd)/alt_objects > .git/objects/info/alternates && - echo content3 > file3 && + echo $(pwd)/alt_objects >.git/objects/info/alternates && + echo content3 >file3 && objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick &&
@@ -111,7 +111,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' ' rm -f .git/objects/pack/* && - echo new_content >> file1 && + echo new_content >>file1 && git add file1 && test_tick && git commit -m more_content &&
@@ -169,12 +169,12 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | egrep "^$csha1 " | sort | uniq | wc -l) && - echo > .git/objects/info/alternates && + echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' - echo $(pwd)/alt_objects > .git/objects/info/alternates && + echo $(pwd)/alt_objects >.git/objects/info/alternates && echo "$csha1" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ &&
@@ -186,7 +186,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | egrep "^$csha1 " | sort | uniq | wc -l) && - echo > .git/objects/info/alternates && + echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
@@ -196,7 +196,7 @@ test_expect_success 'objects made unreachable by grafts only are kept' ' H0=$(git rev-parse HEAD) && H1=$(git rev-parse HEAD^) && H2=$(git rev-parse HEAD^^) && - echo "$H0 $H2" > .git/info/grafts && + echo "$H0 $H2" >.git/info/grafts && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && git repack -a -d && git cat-file -t $H1
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 20/26 t7700: move keywords onto their own line
In reply to Denton LiuThe code style for tests is to have statements on their own line if possible. Move keywords onto their own line so that they conform with the test style.
--- t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-)
t/t7700-repack.sh +34 -17
@@ -29,10 +29,12 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && - for p in .git/objects/pack/*.idx; do + for p in .git/objects/pack/*.idx + do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1"; then + if git verify-pack -v $p | egrep "^$objsha1" + then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND" break
@@ -45,10 +47,12 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object # build on $objsha1, $packsha1, and .keep state from previous git repack -Adbl && test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx; do + for p in .git/objects/pack/*.idx + do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1"; then + if git verify-pack -v $p | egrep "^$objsha1" + then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND" break
@@ -61,10 +65,12 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx; do + for p in .git/objects/pack/*.idx + do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1"; then + if git verify-pack -v $p | egrep "^$objsha1" + then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND" break
@@ -83,8 +89,10 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git commit -m commit_file3 && git repack -a -d -l && git prune-packed && - for p in .git/objects/pack/*.idx; do - if git verify-pack -v $p | egrep "^$objsha1"; then + for p in .git/objects/pack/*.idx + do + if git verify-pack -v $p | egrep "^$objsha1" + then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND" break
@@ -99,10 +107,13 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is git repack -a && myidx=$(ls -1 .git/objects/pack/*.idx) && test -f "$myidx" && - for p in alt_objects/pack/*.idx; do + for p in alt_objects/pack/*.idx + do git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest; do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then + done | while read sha1 rest + do + if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + then echo "Missing object in local pack: $sha1" return 1 fi
@@ -119,10 +130,13 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git repack -a -d && myidx=$(ls -1 .git/objects/pack/*.idx) && test -f "$myidx" && - for p in alt_objects/pack/*.idx; do + for p in alt_objects/pack/*.idx + do git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest; do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then + done | while read sha1 rest + do + if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + then echo "Missing object in local pack: $sha1" return 1 fi
@@ -144,10 +158,13 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' git repack -a -d && myidx=$(ls -1 .git/objects/pack/*.idx) && test -f "$myidx" && - for p in alt_objects/pack/*.idx; do + for p in alt_objects/pack/*.idx + do git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest; do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ); then + done | while read sha1 rest + do + if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + then echo "Missing object in local pack: $sha1" return 1 fi
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 21/26 t7700: s/test -f/test_path_is_file/
In reply to Denton LiuSince we have debugging-friendly alternatives to test -f, replace instances of test -f with test_path_is_file so that if a command ever fails, we get better debugging information.
--- t/t7700-repack.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
t/t7700-repack.sh +4 -4
@@ -106,7 +106,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is mv .git/objects/pack/* alt_objects/pack && git repack -a && myidx=$(ls -1 .git/objects/pack/*.idx) && - test -f "$myidx" && + test_path_is_file "$myidx" && for p in alt_objects/pack/*.idx do git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -129,7 +129,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git repack && git repack -a -d && myidx=$(ls -1 .git/objects/pack/*.idx) && - test -f "$myidx" && + test_path_is_file "$myidx" && for p in alt_objects/pack/*.idx do git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
@@ -148,7 +148,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' for p in alt_objects/pack/*.pack do base_name=$(basename $p .pack) && - if test -f alt_objects/pack/$base_name.keep + if test_path_is_file alt_objects/pack/$base_name.keep then rm alt_objects/pack/$base_name.keep else
@@ -157,7 +157,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' done && git repack -a -d && myidx=$(ls -1 .git/objects/pack/*.idx) && - test -f "$myidx" && + test_path_is_file "$myidx" && for p in alt_objects/pack/*.idx do git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p"
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 22/26 t7700: consolidate code into test_no_missing_in_packs()
In reply to Denton LiuThe code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead.
Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job.
Instead of verifying each file of alt_objects/pack/*.idx individually in a for-loop, batch them together into one verification step.
The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use comm -23 so that finding missing lines from the original file is done more efficiently.
While we're at it, add a space to commit_and_pack () for style.
--- t/t7700-repack.sh | 55 +++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-)
t/t7700-repack.sh +15 -40
@@ -4,12 +4,23 @@ test_description='git repack works correctly' . ./test-lib.sh -commit_and_pack() { +commit_and_pack () { test_commit "$@" 1>&2 && SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && echo pack-${SHA1}.pack } +test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && + git verify-pack -v alt_objects/pack/*.idx >orig.raw && + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && + test_must_be_empty missing +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 &&
@@ -105,19 +116,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is mkdir alt_objects/pack && mv .git/objects/pack/* alt_objects/pack && git repack -a && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -128,19 +127,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git commit -m more_content && git repack && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -156,19 +143,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' fi done && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 23/26 t7700: consolidate code into test_has_duplicate_object()
In reply to Denton LiuThe code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead.
Refactor the resulting extraction so that if the git command fails, the return code is not silently lost.
--- t/t7700-repack.sh | 71 +++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 48 deletions(-)
t/t7700-repack.sh +23 -48
@@ -21,6 +21,25 @@ test_no_missing_in_packs () { test_must_be_empty missing } +# we expect $packsha1 and $objsha1 to be defined +test_has_duplicate_object () { + want_duplicate_object="$1" + found_duplicate_object=false + for p in .git/objects/pack/*.idx + do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist + then + found_duplicate_object=true + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$want_duplicate_object" = "$found_duplicate_object" +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 &&
@@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git repack -Adbl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'loose objects in alternate ODB are not repacked' '
@@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git commit -m commit_file3 && git repack -a -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 24/26 t7700: replace egrep with grep
In reply to Denton LiuThe egrep expressions in this test suite were of the form ^$variable. Although egrep works just fine, it's overkill since we're not using any extended regex. Replace egrep invocations with grep so that we aren't swatting flies with a sledgehammer.
--- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
t/t7700-repack.sh +3 -3
@@ -30,7 +30,7 @@ test_has_duplicate_object () { idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if egrep "^$objsha1" packlist + if grep "^$objsha1" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND"
@@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
@@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 25/26 t7700: make references to SHA-1 generic
In reply to Denton LiuMake the test more hash-agnostic by renaming variables from "sha1" to some variation of "oid" or "packid". Also, replace the regex, [0-9a-f]\{40\} with $OID_REGEX.
A better name for "incrpackid" (incremental pack-id) might have been just "packid". However, later in the test suite, we have other uses of "packid". Although the scopes of these variables don't conflict, a future developer may think that commit_and_pack() and test_has_duplicate_object() are semantically related somehow since they share the same variable name. Give them distinct names so that it's clear these uses are unrelated.
--- t/t7700-repack.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
t/t7700-repack.sh +19 -19
@@ -6,31 +6,31 @@ test_description='git repack works correctly' commit_and_pack () { test_commit "$@" 1>&2 && - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && - echo pack-${SHA1}.pack + incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && + echo pack-${incrpackid}.pack } test_no_missing_in_packs () { myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && git verify-pack -v alt_objects/pack/*.idx >orig.raw && - grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && + grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && test_must_be_empty missing } -# we expect $packsha1 and $objsha1 to be defined +# we expect $packid and $oid to be defined test_has_duplicate_object () { want_duplicate_object="$1" found_duplicate_object=false for p in .git/objects/pack/*.idx do idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue + test "pack-$packid.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if grep "^$objsha1" packlist + if grep "^$oid" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND"
@@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git rev-list --objects --all | grep -v file2 | git pack-objects pack && # The second pack will contain the excluded object - packsha1=$(git rev-list --objects --all | grep file2 | + packid=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - >pack-$packsha1.keep && - objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + >pack-$packid.keep && + oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | + sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git repack -Adbl && test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_has_duplicate_object true '
@@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo $(pwd)/alt_objects >.git/objects/info/alternates && echo content3 >file3 && - objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && + oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick && git commit -m commit_file3 &&
@@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f alt_objects/pack/*.keep && mv .git/objects/pack/* alt_objects/pack/ && - csha1=$(git rev-parse HEAD^{commit}) && + coid=$(git rev-parse HEAD^{commit}) && git reset --hard HEAD^ && test_tick && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
@@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' echo $(pwd)/alt_objects >.git/objects/info/alternates && - echo "$csha1" | git pack-objects --non-empty --all --reflog pack && + echo "$coid" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && # The pack-objects call on the next line is equivalent to
@@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'objects made unreachable by grafts only are kept' '
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v5 26/26 t7700: stop losing return codes of git commands
In reply to Denton LiuIn a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that we will know if a command fails.
--- t/t7700-repack.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
t/t7700-repack.sh +9 -10
@@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git commit -m initial_commit && # Create two packs # The first pack will contain all of the objects except one - git rev-list --objects --all | grep -v file2 | - git pack-objects pack && + git rev-list --objects --all >objs && + grep -v file2 objs | git pack-objects pack && # The second pack will contain the excluded object - packid=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packid=$(grep file2 objs | git pack-objects pack) && >pack-$packid.keep && - oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | - sed -e "s/^\($OID_REGEX\).*/\1/") && + git verify-pack -v pack-$packid.idx >packlist && + oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " packlist && echo >.git/objects/info/alternates && test_must_fail git show $coid '
@@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " && echo >.git/objects/info/alternates && test_must_fail git show $coid '
Signature · 1 line
2.24.0.504.g3cd56eb17d
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
In reply to Denton LiuQuoted 10 lines · Denton Liu
The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into
test_no_missing_in_packs()and use that instead.Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job.
Well,
$ sed -n -e 's/required match/desired part of the line/p'
is much much more approirate than
$ grep -e "requred match" |
extract desired part of the line"grep" is better only if the original were
$ sed -n -e '/required match/p'
but everybody would write it with grep to begin with ;-)
So, I dunno about this part of the conversion.
Quoted 2 lines
Instead of verifying each file of
alt_objects/pack/*.idxindividually in a for-loop, batch them together into one verification step.
Do you mean this one?
git verify-pack -v alt_objects/pack/*.idx
where we may pass 1 or more .idx file to the command? At first my reading was interrupted by a "Huh?", but that does look good. We'd need to be a bit careful to make sure that we have at least 1 .idx file, as the shell will happily feed a file whose name is "*.idx", which verify-pack would be unhappy about.
Quoted 4 lines
The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use
comm -23so that finding missing lines from the original file is done more efficiently.
OK. If we an show measurable speedups, it would be great, but the loop structure does look O(n^2) and unnecessary costly.
t/t7700-repack.sh test_description='git repack works correctly' · line 15
Quoted 3 lines
t/t7700-repack.sh +3
-0+test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" &&
If there are 2 or more .idx files, or if there is none, $myidx would hopefully be a concatenation of these filenames or a string that ends with asterisk-dot-idx and would fail path_is_file. Sounds OK.
Ah, I do not have to review this part---these are repeated patterns in the original.
t/t7700-repack.sh test_description='git repack works correctly' · line 17
Quoted 2 lines
t/t7700-repack.sh +2
-0+ git verify-pack -v alt_objects/pack/*.idx >orig.raw && + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
If output from 'grep' can be used as-is, it is worth doing, but if you have to pipe it to cut, the original that used sed to filter and edit the line would probably be a better way to write it.
t/t7700-repack.sh test_description='git repack works correctly' · line 18
Quoted 1 line
t/t7700-repack.sh +1
-0+ git verify-pack -v $myidx >dest.raw &&
This part does not quote $myidx" (inherited from the original); it probably is OK, as any potentially problematic value in $myidx would have been caught as an error much earlier in this test.
Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
In reply to Denton LiuHi Denton,
t/t7700-repack.sh test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' · line 137
Quoted 4 lines · Denton Liu
t/t7700-repack.sh +2
-2- test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " packlist &&
I think we want to use test_must_fail instead of !
t/t7700-repack.sh test_expect_success 'local packed unreachable obs that exist in alternate ODB ar · line 154
Quoted 11 lines
t/t7700-repack.sh +2
-2echo >.git/objects/info/alternates && test_must_fail git show $coid '@@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " &&
ditto
Signature · 1 line
Danh
Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
Quoted 4 lines · Danh Doan
Quoted 1 line · Denton Liu
+ ! grep "^$coid " packlist &&
I think we want to use
test_must_failinstead of !
test_must_fail() is intended only for use with 'git' commands; "!" should be used otherwise. Quoting from t/README:
Don't use '! git cmd' when you want to make sure the git command exits with failure in a controlled way by calling "die()". Instead, use 'test_must_fail git cmd'. This will signal a failure if git dies in an unexpected way (e.g. segfault).
On the other hand, don't use test_must_fail for running regular platform commands; just use '! cmd'. We are not in the business of verifying that the world given to us sanely works.
So, Denton's use of "!" here is correct.
Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
Quoted 14 lines · Eric Sunshine
Quoted 4 lines · Danh Doan
Quoted 1 line · Denton Liu
+ ! grep "^$coid " packlist &&
I think we want to use
test_must_failinstead of !
test_must_fail()is intended only for use with 'git' commands; "!" should be used otherwise. Quoting from t/README:Don't use '! git cmd' when you want to make sure the git command exits with failure in a controlled way by calling "
die()". Instead, use 'test_must_failgit cmd'. This will signal a failure if git dies in an unexpected way (e.g. segfault).
Quoted 5 lines
On the other hand, don't use
test_must_failfor running regular platform commands; just use '! cmd'. We are not in the business of verifying that the world given to us sanely works.So, Denton's use of "!" here is correct.
I wonder we can make the framework a bit more self-documenting to avoid having to waste time on discovering potential issues and explaining why it is not an issue, like this exchange.
Some ideas:
* Perhaps test_must_fail is not descriptive enough that it should apply only to git command invocation. Would it make it more obvious to rename it to say git_must_fail? That would also make it unnecessary to give this rather unfortunate comment in test-lib-functions.sh:
# This is not among top-level (test_expect_success | test_expect_failure)
# but is a prefix that can be used in the test script, like: # # test_expect_success 'complain and die' ' # do something && # do something else && # test_must_fail git checkout ../outerspace # ' #
* If it is too much trouble to rename it, perhaps test_must_fail can be documented better up there?
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index b299ecc326..052d88c5da 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -817,6 +817,13 @@ list_contains () {
# Multiple signals can be specified as a comma separated list.
# Currently recognized signal names are: sigpipe, success.
# (Don't use 'success', use 'test_might_fail' instead.) +#
+# Do not use this to run anything but "git". We are not in the business +# of vetting system supplied commands---IOW this is wrong:
+#
+# test_must_fail grep pattern output
+#
+# Just use '!' instead.
test_must_fail () {
case "$1" in* Or perhaps we can detect its use on anything that is not "git" automatically? This is merely to illustrate the idea (the exemption of "env" shown here is too broad for production use)
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..7ab113cd50 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -828,6 +828,10 @@ test_must_fail () {
_test_ok=
;;
esac
+ case "$1" in
+ git|test-tool|env) ;;
+ *) echo >&7 "warning: test_must_fail $*???" ;;
+ esac
"$@" 2>&7
exit_code=$?
if test $exit_code -eq 0 && ! list_contains "$_test_ok" successHmm?
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
In reply to Junio C HamanoHi Junio,
Quoted 19 lines · Junio C Hamano
Quoted 10 lines · Denton Liu
The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into
test_no_missing_in_packs()and use that instead.Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job.
Well,
$ sed -n -e 's/required match/desired part of the line/p'is much much more approirate than
Quoted 8 lines
$ grep -e "requred match" | extract desired part of the line"grep" is better only if the original were
$ sed -n -e '/required match/p'but everybody would write it with grep to begin with ;-)
This was what I was intending. It was originally written like the above and it made sense to convert it to use grep. I guess "filter lines" in my commit message is a little bit vague. Could we change this to "filter matching lines" perhaps?
Quoted 35 lines
So, I dunno about this part of the conversion.
Quoted 2 lines
Instead of verifying each file of
alt_objects/pack/*.idxindividually in a for-loop, batch them together into one verification step.Do you mean this one?
git verify-pack -v alt_objects/pack/*.idx
where we may pass 1 or more .idx file to the command? At first my reading was interrupted by a "Huh?", but that does look good. We'd need to be a bit careful to make sure that we have at least 1 .idx file, as the shell will happily feed a file whose name is "*.idx", which verify-pack would be unhappy about.
Quoted 4 lines
The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use
comm -23so that finding missing lines from the original file is done more efficiently.OK. If we an show measurable speedups, it would be great, but the loop structure does look O(n^2) and unnecessary costly.
t/t7700-repack.sh test_description='git repack works correctly' · line 15
Quoted 3 lines
t/t7700-repack.sh +3
-0+test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" &&If there are 2 or more .idx files, or if there is none, $myidx would hopefully be a concatenation of these filenames or a string that ends with asterisk-dot-idx and would fail
path_is_file. Sounds OK.Ah, I do not have to review this part---these are repeated patterns in the original.
Quoted 6 lines
t/t7700-repack.sh test_description='git repack works correctly' · line 17
Quoted 2 lines
t/t7700-repack.sh +2
-0+ git verify-pack -v alt_objects/pack/*.idx >orig.raw && + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&If output from 'grep' can be used as-is, it is worth doing, but if you have to pipe it to cut, the original that used sed to filter and edit the line would probably be a better way to write it.
The original sed actually only filtered the line; no editing done. The cut invocation was a consequence of using comm. Previously, in the while loop, we would separate the line into sha1 and rest components and only match using the sha1. Since we use comm now, we have to use cut to grab the sha1 and omit the rest of the line.
We could rewrite it with sed like this:
sed -n -e "/^[0-9a-f]\{40\}/s/^\($[0-9a-f]\{40\}\).*/\1/" orig.rawbut I believe that breaking it into grep and cut makes the intent much more clear.
What do you think?
(By the way, if I were to reroll this series, should I keep sending out the entire patchset? It feels very noisy to send out 20-something emails every reroll when I'm just making a small one or two line change.)
Thanks,
Denton
Quoted 7 lines
t/t7700-repack.sh test_description='git repack works correctly' · line 18
Quoted 2 lines
t/t7700-repack.sh +1
-0+ git verify-pack -v $myidx >dest.raw &&This part does not quote $myidx" (inherited from the original); it probably is OK, as any potentially problematic value in $myidx would have been caught as an error much earlier in this test.
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
Quoted 4 lines · Denton Liu
Hi Junio,
...Quoted 2 lines
"grep" is better only if the original were
Quoted 8 lines
Quoted 3 lines
$ sed -n -e '/required match/p'but everybody would write it with grep to begin with ;-)
This was what I was intending. It was originally written like the above and it made sense to convert it to use grep. I guess "filter lines" in my commit message is a little bit vague. Could we change this to "filter matching lines" perhaps?
Ah, I see. I somehow thought that some of the "sed" invocation in the original version were doing "find lines and filter its contents" (i.e. "-n -e 's/find/munge/p'"), but all three of them are just "find lines" (i.e. "-n -e '/find/p'"). So I think the change made by the patch is OK.
I think I was reacting to the output of "grep" being piped to "cut". IOW, the original
... | sed -n -e '/find/p' | while read sha1 garbage do ... use sha1 ...
were rewritten to
... >raw &&
grep -e 'find' raw | cut -d" " -f1 >orig
... use orig as a list of sha1s ...
But the "grep piped to cut" can be a single process
... >raw && sed -n -e 's/\(find\).*/\1/p' raw >orig ... use orig as a list of sha1s ...
So in the tiniest picture, turning "sed -n -e /find/p" into "grep" is not wrong per-se, but if you step back a bit and see a larger picture, using "sed" a bit more effectively turns out to be still a better rewrite.
... and I wrote the above before I read the remainder of your response, where you considered which one is easier to read between "grep piped to cut" and "sed" ;-)
Quoted 3 lines
(By the way, if I were to reroll this series, should I keep sending out the entire patchset? It feels very noisy to send out 20-something emails every reroll when I'm just making a small one or two line change.)
Especially if it is near the end of the series, just a single step is OK. But is there anything that is glaringly wrong that needs a reroll? Or would it be "this is good enough, so let's have them cook in 'next' and graduate to 'master'---further clean-up can be done after all the dust settles"? I have an impression that we reached the latter by now.
Thanks.
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
Hi Junio,
Quoted 10 lines · Junio C Hamano
Quoted 3 lines
(By the way, if I were to reroll this series, should I keep sending out the entire patchset? It feels very noisy to send out 20-something emails every reroll when I'm just making a small one or two line change.)
Especially if it is near the end of the series, just a single step is OK. But is there anything that is glaringly wrong that needs a reroll? Or would it be "this is good enough, so let's have them cook in 'next' and graduate to 'master'---further clean-up can be done after all the dust settles"? I have an impression that we reached the latter by now.
Perhaps the log message could use some improvement to document the discussion we had? I don't know if that's worth a reroll, though. Aside from that, I agree that it's ready for 'next'.
Quoted 2 lines
Thanks.
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
Quoted 10 lines · Denton Liu
Quoted 6 lines
Especially if it is near the end of the series, just a single step is OK. But is there anything that is glaringly wrong that needs a reroll? Or would it be "this is good enough, so let's have them cook in 'next' and graduate to 'master'---further clean-up can be done after all the dust settles"? I have an impression that we reached the latter by now.
Perhaps the log message could use some improvement to document the discussion we had? I don't know if that's worth a reroll, though. Aside from that, I agree that it's ready for 'next'.
Sure, let's see what you have in mind.
Thanks for working on this.
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
Hi Junio,
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Denton Liu
Quoted 6 lines
Especially if it is near the end of the series, just a single step is OK. But is there anything that is glaringly wrong that needs a reroll? Or would it be "this is good enough, so let's have them cook in 'next' and graduate to 'master'---further clean-up can be done after all the dust settles"? I have an impression that we reached the latter by now.
Quoted 5 lines
Quoted 3 lines
Perhaps the log message could use some improvement to document the discussion we had? I don't know if that's worth a reroll, though. Aside from that, I agree that it's ready for 'next'.
Sure, let's see what you have in mind.
Here's a complete replacement for the commit message:
t7700: consolidate code into test_no_missing_in_packs()
The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead.
Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job.
Instead of verifying each file of alt_objects/pack/*.idx individually in a for-loop, batch them together into one verification step.
The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use comm -23 so that finding missing lines from the original file is done more efficiently.
The result of this is that we end up with a grep | cut | sort pipeline. Previously, we were extracting the sha1 as part of the while read sha1 rest loop. Since we removed the while-loop, we need to use cut to extract the sha1 field. Note that we could have chosen to combine the grep | cut into a single sed invocation but we consciously leave it separate as it makes the intent more clear.
While we're at it, add a space to commit_and_pack () for style.
The only change between this and the old commit message is the addition of the "The result of this..." paragraph.
Thanks,
Denton
Quoted 2 lines
Thanks for working on this.
t: remove inappropriate uses of test_must_fail(), was Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands
In reply to Junio C HamanoHi all,
Quoted 4 lines · Junio C Hamano
* Or perhaps we can detect its use on anything that is not "git" automatically? This is merely to illustrate the idea (the exemption of "env" shown here is too broad for production use)
Quoted 15 lines
diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh
index b299ecc326..7ab113cd50 100644
--- a/t/test-lib-functions.sh
+++ b/t/test-lib-functions.sh
@@ -828,6 +828,10 @@ test_must_fail () {
_test_ok=
;;
esac
+ case "$1" in
+ git|test-tool|env) ;;
+ *) echo >&7 "warning: test_must_fail $*???" ;;
+ esac
"$@" 2>&7
exit_code=$?
if test $exit_code -eq 0 && ! list_contains "$_test_ok" successI've been cooking a series that gets rid of inappropriate uses test_must_fail() for a while now. As a finishing touch, I implemented the idea Junio suggested above and it seems to be working well.
It's a pretty hefty series, weighing in at 46 patches. After the dust settles on 'dl/test-cleanup' (once it gets merged to master), I'll probably start sending out this test_must_fail() series around 10 patches at a time.
An advanced preview can be found here[1]. Or, if you'd like me to privately mail you the series, I can do that too. Early comments would be very appreciated.
Thanks,
Denton
[1]: https://github.com/Denton-L/git/commits/ready/cleanup-test-must-fail
Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs()
In reply to Denton LiuQuoted 32 lines · Denton Liu
Quoted 1 line
Sure, let's see what you have in mind.
Here's a complete replacement for the commit message:
t7700: consolidate code into
test_no_missing_in_packs()The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into
test_no_missing_in_packs()and use that instead.Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job.
Instead of verifying each file of
alt_objects/pack/*.idxindividually in a for-loop, batch them together into one verification step.The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use
comm -23so that finding missing lines from the original file is done more efficiently.The result of this is that we end up with a
grep | cut | sortpipeline. Previously, we were extracting thesha1as part of thewhile read sha1 restloop. Since we removed the while-loop, we need to usecutto extract thesha1field. Note that we could have chosen to combine thegrep | cutinto a singlesedinvocation but we consciously leave it separate as it makes the intent more clear.
Quoted 6 lines
While we're at it, add a space to
commit_and_pack ()for style.Signed-off-by Denton Liu <[email protected]>The only change between this and the old commit message is the addition of the "The result of this..." paragraph.
Ah, you were planning to only update the log message? Then let's not bother. I do not think we would want to encourage "grep piped to cut" as a good pattern for others to follow and a single sed that finds the relevant lines and munges the content of these lines into what is desired conveys the intent clearly and more concisely (I was hoping that that was what you had in mind for a reroll).
v6 cover t: test cleanup stemming from experimentally enabling pipefail
Hi Junio,
Sorry for the confusion. Looking it over, I see that the sed expression you proposed indeed makes the intent a lot clearer. Here's a replacement series for the last five commits of the branch.
I would've opted to send out a single replacement patch but this change causes some minor textual conflicts in 4/5 so this should make your life a little easier ;)
Denton Liu (5):
t7700: consolidate code into test_no_missing_in_packs()
t7700: consolidate code into test_has_duplicate_object()
t7700: replace egrep with grep
t7700: make references to SHA-1 generic
t7700: stop losing return codes of git commands
t/t7700-repack.sh | 165 ++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 108 deletions(-)
Range-diff against v5:
1: a99a45cb6f ! 1: 3008ce8deb t7700: consolidate code into test_no_missing_in_packs()
@@ Commit message
Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
- We were using sed to filter lines. Although not incorrect, this is
- exactly what grep is built for. Replace this invocation of sed with grep
- so that we use the correct tool for the job.
-
Instead of verifying each file of alt_objects/pack/*.idx individually in a for-loop, batch them together into one verification step.
The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to
- sort the files then use comm -23 so that finding missing lines from
- the original file is done more efficiently.
+ extract the hash using sed or cut, sort the files, then use comm -23
+ so that finding missing lines from the original file is done more
+ efficiently.
While we're at it, add a space to commit_and_pack () for style.
@@ t/t7700-repack.sh: test_description='git repack works correctly'
+ myidx=$(ls -1 .git/objects/pack/*.idx) &&
+ test_path_is_file "$myidx" &&
+ git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
-+ grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
++ sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig &&
+ git verify-pack -v $myidx >dest.raw &&
+ cut -d" " -f1 dest.raw | sort >dest &&
+ comm -23 orig dest >missing &&
2: f79240e937 = 2: f3a0470edc t7700: consolidate code into test_has_duplicate_object()
3: 632a62f6e9 = 3: c34477a5a9 t7700: replace egrep with grep
4: bf70cc5a0d ! 4: 113f375192 t7700: make references to SHA-1 generic
@@ t/t7700-repack.sh: test_description='git repack works correctly'
myidx=$(ls -1 .git/objects/pack/*.idx) &&
test_path_is_file "$myidx" &&
git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
-- grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
-+ grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig &&
+- sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig &&
++ sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&
git verify-pack -v $myidx >dest.raw &&
cut -d" " -f1 dest.raw | sort >dest &&
comm -23 orig dest >missing &&5: 1f6d9a80ad = 5: ab653bd76f t7700: stop losing return codes of git commands
Signature · 1 line
2.24.0.578.g4820254054
PATCH v6 1/5 t7700: consolidate code into test_no_missing_in_packs()
The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead.
Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.
Instead of verifying each file of alt_objects/pack/*.idx individually in a for-loop, batch them together into one verification step.
The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to extract the hash using sed or cut, sort the files, then use comm -23 so that finding missing lines from the original file is done more efficiently.
While we're at it, add a space to commit_and_pack () for style.
--- t/t7700-repack.sh | 55 +++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-)
t/t7700-repack.sh +15 -40
@@ -4,12 +4,23 @@ test_description='git repack works correctly' . ./test-lib.sh -commit_and_pack() { +commit_and_pack () { test_commit "$@" 1>&2 && SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && echo pack-${SHA1}.pack } +test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && + git verify-pack -v alt_objects/pack/*.idx >orig.raw && + sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && + test_must_be_empty missing +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 &&
@@ -105,19 +116,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is mkdir alt_objects/pack && mv .git/objects/pack/* alt_objects/pack && git repack -a && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -128,19 +127,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git commit -m more_content && git repack && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -156,19 +143,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' fi done && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
Signature · 1 line
2.24.0.578.g4820254054
PATCH v6 2/5 t7700: consolidate code into test_has_duplicate_object()
In reply to Denton LiuThe code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead.
Refactor the resulting extraction so that if the git command fails, the return code is not silently lost.
--- t/t7700-repack.sh | 71 +++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 48 deletions(-)
t/t7700-repack.sh +23 -48
@@ -21,6 +21,25 @@ test_no_missing_in_packs () { test_must_be_empty missing } +# we expect $packsha1 and $objsha1 to be defined +test_has_duplicate_object () { + want_duplicate_object="$1" + found_duplicate_object=false + for p in .git/objects/pack/*.idx + do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist + then + found_duplicate_object=true + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$want_duplicate_object" = "$found_duplicate_object" +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 &&
@@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git repack -Adbl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'loose objects in alternate ODB are not repacked' '
@@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git commit -m commit_file3 && git repack -a -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' '
Signature · 1 line
2.24.0.578.g4820254054
PATCH v6 3/5 t7700: replace egrep with grep
In reply to Denton LiuThe egrep expressions in this test suite were of the form ^$variable. Although egrep works just fine, it's overkill since we're not using any extended regex. Replace egrep invocations with grep so that we aren't swatting flies with a sledgehammer.
--- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
t/t7700-repack.sh +3 -3
@@ -30,7 +30,7 @@ test_has_duplicate_object () { idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if egrep "^$objsha1" packlist + if grep "^$objsha1" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND"
@@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
@@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
Signature · 1 line
2.24.0.578.g4820254054
PATCH v6 4/5 t7700: make references to SHA-1 generic
In reply to Denton LiuMake the test more hash-agnostic by renaming variables from "sha1" to some variation of "oid" or "packid". Also, replace the regex, [0-9a-f]\{40\} with $OID_REGEX.
A better name for "incrpackid" (incremental pack-id) might have been just "packid". However, later in the test suite, we have other uses of "packid". Although the scopes of these variables don't conflict, a future developer may think that commit_and_pack() and test_has_duplicate_object() are semantically related somehow since they share the same variable name. Give them distinct names so that it's clear these uses are unrelated.
--- t/t7700-repack.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-)
t/t7700-repack.sh +19 -19
@@ -6,31 +6,31 @@ test_description='git repack works correctly' commit_and_pack () { test_commit "$@" 1>&2 && - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && - echo pack-${SHA1}.pack + incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && + echo pack-${incrpackid}.pack } test_no_missing_in_packs () { myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && git verify-pack -v alt_objects/pack/*.idx >orig.raw && - sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && + sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && test_must_be_empty missing } -# we expect $packsha1 and $objsha1 to be defined +# we expect $packid and $oid to be defined test_has_duplicate_object () { want_duplicate_object="$1" found_duplicate_object=false for p in .git/objects/pack/*.idx do idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue + test "pack-$packid.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if grep "^$objsha1" packlist + if grep "^$oid" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND"
@@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git rev-list --objects --all | grep -v file2 | git pack-objects pack && # The second pack will contain the excluded object - packsha1=$(git rev-list --objects --all | grep file2 | + packid=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - >pack-$packsha1.keep && - objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + >pack-$packid.keep && + oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | + sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git repack -Adbl && test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_has_duplicate_object true '
@@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo $(pwd)/alt_objects >.git/objects/info/alternates && echo content3 >file3 && - objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && + oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick && git commit -m commit_file3 &&
@@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f alt_objects/pack/*.keep && mv .git/objects/pack/* alt_objects/pack/ && - csha1=$(git rev-parse HEAD^{commit}) && + coid=$(git rev-parse HEAD^{commit}) && git reset --hard HEAD^ && test_tick && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all &&
@@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' echo $(pwd)/alt_objects >.git/objects/info/alternates && - echo "$csha1" | git pack-objects --non-empty --all --reflog pack && + echo "$coid" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && # The pack-objects call on the next line is equivalent to
@@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'objects made unreachable by grafts only are kept' '
Signature · 1 line
2.24.0.578.g4820254054
PATCH v6 5/5 t7700: stop losing return codes of git commands
In reply to Denton LiuIn a pipe, only the return code of the last command is used. Thus, all other commands will have their return codes masked. Rewrite pipes so that there are no git commands upstream so that we will know if a command fails.
--- t/t7700-repack.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-)
t/t7700-repack.sh +9 -10
@@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git commit -m initial_commit && # Create two packs # The first pack will contain all of the objects except one - git rev-list --objects --all | grep -v file2 | - git pack-objects pack && + git rev-list --objects --all >objs && + grep -v file2 objs | git pack-objects pack && # The second pack will contain the excluded object - packid=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packid=$(grep file2 objs | git pack-objects pack) && >pack-$packid.keep && - oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | - sed -e "s/^\($OID_REGEX\).*/\1/") && + git verify-pack -v pack-$packid.idx >packlist && + oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " packlist && echo >.git/objects/info/alternates && test_must_fail git show $coid '
@@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " && echo >.git/objects/info/alternates && test_must_fail git show $coid '
Signature · 1 line
2.24.0.578.g4820254054
Re: [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail
In reply to Denton LiuQuoted 24 lines · Denton Liu
Range-diff against v5:
1:a99a45cb6f! 1:3008ce8debt7700: consolidate code intotest_no_missing_in_packs()
@@ Commit message
Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost.- We were using sed to filter lines. Although not incorrect, this is
- exactly what grep is built for. Replace this invocation of sed with grep
- so that we use the correct tool for the job.
-
Instead of verifying each file ofalt_objects/pack/*.idxindividually in a for-loop, batch them together into one verification step.The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to
- sort the files then usecomm -23so that finding missing lines from
- the original file is done more efficiently.
+ extract the hash using sed or cut, sort the files, then usecomm -23
+ so that finding missing lines from the original file is done more
+ efficiently.While we're at it, add a space to
commit_and_pack ()for style.
Quoted 9 lines
@@
t/t7700-repack.sh: test_description='git repack works correctly'
+ myidx=$(ls -1 .git/objects/pack/*.idx) &&
+test_path_is_file"$myidx" &&
+ git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
-+ grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
++ sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig &&
+ git verify-pack -v $myidx >dest.raw &&
+ cut -d" " -f1 dest.raw | sort >dest &&
+ comm -23 orig dest >missing &&
OK.
Quoted 11 lines
2: f79240e937 = 2: f3a0470edc t7700: consolidate code into test_has_duplicate_object()
3: 632a62f6e9 = 3: c34477a5a9 t7700: replace egrep with grep
4: bf70cc5a0d ! 4: 113f375192 t7700: make references to SHA-1 generic
@@ t/t7700-repack.sh: test_description='git repack works correctly'
myidx=$(ls -1 .git/objects/pack/*.idx) &&
test_path_is_file "$myidx" &&
git verify-pack -v alt_objects/pack/*.idx >orig.raw &&
-- grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig &&
-+ grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig &&
+- sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig &&
++ sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig &&Looking really good.
Thanks for following through. Will replace and queue.
Hopefully this round is now ready for 'next'. Knock knock...
cover tests: add a bash "set -o pipefail" test mode
In reply to Jeff KingThere's been past attempts to add a "set -o pipefail" test mode. I suspect it can't be done in any sane way the way it works in bash now. See 6/6 for details.
This series makes it work because I patched it to work sanely in bash itself when it comes to SIGPIPE. I'm partially submitting this so I can prod the bash maintainer with a link to this thread.
But also because even though you need to patch your bash to benefit from this new test mode, it doesn't break anything for anyone who doesn't have the patch (we guard it with a detection for the sane behavior), and at the very least 4/6 (or maybe just to 2/6) are generally sane fixes even without the rest.
1. https://lore.kernel.org/git/[email protected]/
Ævar Arnfjörð Bjarmason (6):
test-lib: add tests for test_might_fail
test-lib: add ok=* support to test_might_fail
test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
tests: use "test_might_fail ok=sigpipe grep" when appropriate
tests: split up bash detection library
tests: add a "set -o pipefail" for a patched bash
t/README | 6 +++++ t/lib-bash-detection.sh | 8 +++++++ t/lib-bash.sh | 4 +++- t/t0000-basic.sh | 38 ++++++++++++++++++++++++++++++ t/t0005-signals.sh | 4 ++-- t/t0090-cache-tree.sh | 2 +- t/t5000-tar-tree.sh | 2 +- t/t5703-upload-pack-ref-in-want.sh | 2 +- t/t9151-svn-mergeinfo.sh | 6 ++--- t/t9902-completion.sh | 5 ++++ t/test-lib-functions.sh | 24 ++++++++++++++++++- t/test-lib.sh | 29 +++++++++++++++++++++++ 12 files changed, 120 insertions(+), 10 deletions(-) create mode 100644 t/lib-bash-detection.sh
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 1/6 test-lib: add tests for test_might_fail
In reply to Jeff KingThis trivial sibling command of test_must_fail added in fdf1bc48ca (t7006: guard cleanup with test_expect_success, 2010-04-14) didn't have any tests. Let's add at least a basic one.
--- t/t0000-basic.sh | 6 ++++++ 1 file changed, 6 insertions(+)
t/t0000-basic.sh +6 -0
@@ -1326,4 +1326,10 @@ test_expect_success 'test_must_fail rejects a non-git command with env' ' grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err ' +test_expect_success 'test_might_fail is like test_must_fail ok=' ' + ! test_must_fail git version && + ! test_must_fail ok= git version && + test_might_fail git version +' + test_done
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 2/6 test-lib: add ok=* support to test_might_fail
In reply to Jeff KingAdd the same ok=* support to test_might_fail as its test_must_fail sibling. This will be used to make it accept "sigpipe" failures.
--- t/t0000-basic.sh | 5 +++++ t/test-lib-functions.sh | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-)
t/t0000-basic.sh +5 -0
@@ -1332,4 +1332,9 @@ test_expect_success 'test_might_fail is like test_must_fail ok=' ' test_might_fail git version ' +test_expect_success 'test_might_fail supports an ok=* option like test_must_fail' ' + test_might_fail git version && + test_might_fail ok=success git version +' + test_done
t/test-lib-functions.sh +11 -1
@@ -918,7 +918,17 @@ test_must_fail () { # Accepts the same options as test_must_fail. test_might_fail () { - test_must_fail ok=success "$@" 2>&7 + case "$1" in + ok=*) + _test_ok=success,${1#ok=} + shift + ;; + *) + _test_ok=success + ;; + esac + + test_must_fail ok=$_test_ok "$@" 2>&7 } 7>&2 2>&4 # Similar to test_must_fail and test_might_fail, but check that a
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 3/6 test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
In reply to Jeff KingAs the documentation here notes you usually do not want to do:
test_might_fail grep ...
But instead:
! grep ...
However, as a future commit will show it's handy to be able to do:
some | test_might_fail ok=sigpipe grep | commands | here
To allow "grep" to fail in the middle of a pipe, if we're in a mode such as a "set -o pipefail" that knows how to accept check intra-pipe failures.
To test this in t0000-basic.sh we don't actually need to have test_{might,must}_fail in the middle of a pipe, it'll just that it accepts e.g. "grep" when we provide ok=sigpipe.
--- t/t0000-basic.sh | 13 +++++++++++++ t/test-lib-functions.sh | 12 ++++++++++++ 2 files changed, 25 insertions(+)
t/t0000-basic.sh +13 -0
@@ -1337,4 +1337,17 @@ test_expect_success 'test_might_fail supports an ok=* option like test_must_fail test_might_fail ok=success git version ' +test_expect_success 'test_{must,might}_fail accept non-git on "sigpipe"' ' + ! test_must_fail grep blob <badobjects 2>err && + grep "only.*git.*is allowed" err && + ! test_might_fail grep blob <badobjects && + grep "only.*git.*is allowed" err && + + ! test_must_fail ok=sigpipe grep . badobjects 2>err && + test_must_be_empty err && + test_might_fail ok=sigpipe grep . badobjects >out 2>err && + test_must_be_empty err && + test_cmp badobjects out +' + test_done
t/test-lib-functions.sh +12 -0
@@ -828,6 +828,7 @@ test_must_fail_acceptable () { return 0 ;; *) + list_contains "$_test_ok" sigpipe && return 0 return 1 ;; esac
@@ -863,6 +864,17 @@ test_must_fail_acceptable () { # Instead use '!': # # ! grep pattern output +# +# An exception to this is if ok=* contains "sigpipe". Then you might +# want to use this in a test to ignore e.g. "grep" failing due to not +# finding anything in a multi-pipe command: +# +# test_must_fail ok=success,sigpipe grep [...] | [...] +# +# Or, more succinctly with the test_might_fail wrapper function: +# +# test_might_fail ok=sigpipe grep [...] | [...] +# test_must_fail () { case "$1" in
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 4/6 tests: use "test_might_fail ok=sigpipe grep" when appropriate
In reply to Jeff KingChange tests where the "grep" might exit with non-zero to use our new "test_might_fail ok=sigpipe" wrapper. A subsequent commit will show how useful this is in combination with "set -o pipefail".
--- t/t0090-cache-tree.sh | 2 +- t/t5703-upload-pack-ref-in-want.sh | 2 +- t/t9151-svn-mergeinfo.sh | 6 +++--- 3 files changed, 5 insertions(+), 5 deletions(-)
t/t0090-cache-tree.sh +1 -1
@@ -22,7 +22,7 @@ generate_expected_cache_tree_rec () { # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux # We want to count only foo because it's the only direct child git ls-files >files && - subtrees=$(grep / files|cut -d / -f 1|uniq) && + subtrees=$(test_might_fail ok=sigpipe grep / files |cut -d / -f 1|uniq) && subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') && entries=$(wc -l <files) && printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
t/t5703-upload-pack-ref-in-want.sh +1 -1
@@ -16,7 +16,7 @@ get_actual_commits () { test-tool pkt-line unpack-sideband <out >o.pack && git index-pack o.pack && git verify-pack -v o.idx >objs && - grep commit objs | cut -d" " -f1 | sort >actual_commits + test_might_fail ok=sigpipe grep commit objs | cut -d" " -f1 | sort >actual_commits } check_output () {
t/t9151-svn-mergeinfo.sh +3 -3
@@ -18,19 +18,19 @@ test_expect_success 'load svn dump' " test_expect_success 'all svn merges became git merge commits' ' unmarked=$(git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep -v " .* " | cut -f1 -d" ") && [ -z "$unmarked" ] ' test_expect_success 'cherry picks did not become git merge commits' ' bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep grep " .* " | cut -f1 -d" ") && [ -z "$bad_cherries" ] ' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' bad_non_merges=$(git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep grep " .* " | cut -f1 -d" ") && [ -z "$bad_non_merges" ] '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 5/6 tests: split up bash detection library
In reply to Jeff KingSplit up the detection for whether we're running under bash, and whether it's the /bin/sh POSIX-y mode or the /bin/bash bash-y mode into its own library.
This will soon be used very early in test-lib.sh itself to check for the /bin/bash, so let's make this new file as small as possible.
--- t/lib-bash-detection.sh | 8 ++++++++ t/lib-bash.sh | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 t/lib-bash-detection.sh
t/lib-bash-detection.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh + +TEST_SH_IS_BIN_BASH= +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then + TEST_SH_IS_BIN_BASH=true + export TEST_SH_IS_BIN_BASH +fi
t/lib-bash.sh +3 -1
@@ -2,7 +2,9 @@ # to run under Bash; primarily intended for tests of the completion # script. -if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +. ./lib-bash-detection.sh + +if test -n "$TEST_SH_IS_BIN_BASH" then # we are in full-on bash mode true
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 6/6 tests: add a "set -o pipefail" for a patched bash
In reply to Jeff KingAdd a "set -o pipefail" test mode to the test suite to detect failures in "git" its output is fed directly to a pipe. Doing so is a pattern we discourage[1] in the test suite, but we've got plenty of tests like that. Now we can reliably detect those failures.
There was a previous attempt in [2] to add such a test mode, but as noted by Jeff King in [3] adding it is a matter of peeing against the wind with current bash semantics of failing on SIGPIPE.
This series relies on a patch of mine to bash, which I'm submitting upstream. Vanilla bash ignores SIGPIPE under "set -e" since version 3.1. It's only under "set -o pipefail" (added in 3.2) that it doesn't take account of SIGPIPE, in a seeming omission nobody bothered to fix yet.
Patching bash[4] with:
diff --git a/jobs.c b/jobs.c
index a581f305..fa5de82a 100644
--- a/jobs.c
+++ b/jobs.c
@@ -2851,8 +2851,14 @@ raw_job_exit_status (job)
p = jobs[job]->pipe;
do
{
- if (WSTATUS (p->status) != EXECUTION_SUCCESS)
- fail = WSTATUS(p->status);
+ if (WSTATUS (p->status) != EXECUTION_SUCCESS
+#if defined (DONT_REPORT_SIGPIPE)
+ && WTERMSIG (p->status) != SIGPIPE
+#endif
+ )
+ {
+ fail = WSTATUS(p->status);
+ }
p = p->next;
}
while (p != jobs[job]->pipe);Makes it useful for something like the git test suite. With vanilla bash and GIT_TEST_PIPEFAIL=true we'll fail 4 tests in my one-off test.
With my patched bash the only tests we need to skip are those that are explicitly testing that a piped command returned SIGPIPE.
As Jeff noted in [3] that count isn't reliable, as more will fail in a way that's hard to reproduce due to the racy nature of vanilla "set -o pipefail"
1. a378fee5b0 (Documentation: add shell guidelines, 2018-10-05)
2. https://lore.kernel.org/git/[email protected]/
3. https://lore.kernel.org/git/[email protected]/
4. https://github.com/bminor/bash/compare/master...avar:avar/ignore-sigterm-and-sigpipe-on-pipe-fail
--- t/README | 6 ++++++ t/t0000-basic.sh | 14 ++++++++++++++ t/t0005-signals.sh | 4 ++-- t/t5000-tar-tree.sh | 2 +- t/t9902-completion.sh | 5 +++++ t/test-lib.sh | 29 +++++++++++++++++++++++++++++ 6 files changed, 57 insertions(+), 3 deletions(-)
t/README +6 -0
@@ -439,6 +439,12 @@ GIT_TEST_DEFAULT_HASH=<hash-algo> specifies which hash algorithm to use in the test scripts. Recognized values for <hash-algo> are "sha1" and "sha256". +GIT_TEST_PIPEFAIL=<boolean>, when true, run 'set -o pipefail' to catch +failures in commands that aren't the last in a pipe. Defaults to true +on bash versions which know how to ignore SIGPIPE failures under the +'set -o pipefail' mode (as of 2021-01-14 only in an out-of-tree patch +to bash). + Naming Tests ------------
t/t0000-basic.sh +14 -0
@@ -1350,4 +1350,18 @@ test_expect_success 'test_{must,might}_fail accept non-git on "sigpipe"' ' test_cmp badobjects out ' +test_expect_failure BASH_SET_O_PIPEFAIL 'test_{must,might}_fail ok=sigpipe under bash "set -o pipefail"' ' + grep string </dev/null | true +' + +test_expect_failure BASH_SET_O_PIPEFAIL 'test_{must,might}_fail ok=sigpipe under bash "set -o pipefail"' ' + test_must_fail grep string </dev/null | true && + test_might_fail grep string </dev/null | true +' + +test_expect_success BASH_SET_O_PIPEFAIL 'test_{must,might}_fail ok=sigpipe under bash "set -o pipefail"' ' + test_must_fail ok=sigpipe grep string </dev/null | true && + test_might_fail ok=sigpipe grep string </dev/null | true +' + test_done
t/t0005-signals.sh +2 -2
@@ -40,12 +40,12 @@ test_expect_success 'create blob' ' git add file ' -test_expect_success !MINGW 'a constipated git dies with SIGPIPE' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE' ' OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" ' -test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE even if parent ignores it' ' OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" '
t/t5000-tar-tree.sh +1 -1
@@ -416,7 +416,7 @@ test_expect_success LONG_IS_64BIT 'set up repository with huge blob' ' # We expect git to die with SIGPIPE here (otherwise we # would generate the whole 64GB). -test_expect_success LONG_IS_64BIT 'generate tar with huge size' ' +test_expect_success LONG_IS_64BIT,!BASH_SET_O_PIPEFAIL 'generate tar with huge size' ' { git archive HEAD echo $? >exit-code
t/t9902-completion.sh +5 -0
@@ -7,6 +7,11 @@ test_description='test bash completion' . ./lib-bash.sh +if test -n "$GIT_TEST_PIPEFAIL_TRUE" +then + set +o pipefail +fi + complete () { # do nothing
t/test-lib.sh +29 -0
@@ -36,6 +36,31 @@ then fi GIT_BUILD_DIR="$TEST_DIRECTORY"/.. +# Does "set -o pipefail" on this bash version handle SIGPIPE? Use it! +. "$TEST_DIRECTORY/lib-bash-detection.sh" +GIT_TEST_PIPEFAIL_TRUE= +GIT_TEST_PIPEFAIL_DEFAULT=false +if test -n "$TEST_SH_IS_BIN_BASH" && + $BASH -c 'set -eo pipefail; yes | head -n 1 >/dev/null' +then + GIT_TEST_PIPEFAIL_DEFAULT=true +fi +# We're too early for test_bool_env +if git env--helper --type=bool --default="$GIT_TEST_PIPEFAIL_DEFAULT" \ + --exit-code GIT_TEST_PIPEFAIL +then + set -o pipefail + + # Only "set -o pipefail" in the main test scripts, not any + # sub-programs we spawn. + GIT_TEST_PIPEFAIL= + export GIT_TEST_PIPEFAIL + + # For the convenience of the prereq for it. + GIT_TEST_PIPEFAIL_TRUE=true + export GIT_TEST_PIPEFAIL_TRUE +fi + # If we were built with ASAN, it may complain about leaks # of program-lifetime variables. Disable it by default to lower # the noise level. This needs to happen at the start of the script,
@@ -1552,6 +1577,10 @@ test_lazy_prereq PIPE ' rm -f testfifo && mkfifo testfifo ' +test_lazy_prereq BASH_SET_O_PIPEFAIL ' + test -n "$GIT_TEST_PIPEFAIL_TRUE" +' + test_lazy_prereq SYMLINKS ' # test whether the filesystem supports symbolic links ln -s x y && test -h y
Signature · 1 line
2.29.2.222.g5d2a92d10f8
Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
In reply to Ævar Arnfjörð BjarmasonHi Ævar,
First of all, thanks for reviving this series! I hope that Bash accepts your proposed patch because it would definitely be helpful.
Quoted 8 lines · Ævar Arnfjörð Bjarmason
As the documentation here notes you usually do not want to do:
test_might_failgrep ...But instead:
! grep ...
Quoted 7 lines
However, as a future commit will show it's handy to be able to do:
some |
test_might_failok=sigpipe grep | commands | hereTo allow "grep" to fail in the middle of a pipe, if we're in a mode such as a "set -o pipefail" that knows how to accept check intra-pipe failures.
From what I can see, there presently aren't any other use cases here except for with grep. I propose writing a wrapper around grep, à la [0]:
test_filter () {
grep "$@" || :
}This has two main advantanges: the first would be that we could avoid complicating the test_must_fail_acceptable() code. The second is that it would be much less of a mouthful to write and it would be more readable.
Compare
some | test_might_fail ok=sigpipe grep | commands | here
to
some | test_filter | commands | here
Thanks,
Denton
Quoted 5 lines
To test this in
t0000-basic.shwe don't actually need to have test_{might,must}_fail in the middle of a pipe, it'll just that it accepts e.g. "grep" when we provide ok=sigpipe.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>
Re: [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate
In reply to Ævar Arnfjörð Bjarmasont/t9151-svn-mergeinfo.sh test_expect_success 'load svn dump' " · line 33
Quoted 7 lines · Ævar Arnfjörð Bjarmason
test_expect_success'cherry picks did not become git merge commits' 't/t9151-svn-mergeinfo.sh +2
-2bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep grep " .* " | cut -f1 -d" ") && - grep " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep grep " .* " | cut -f1 -d" ") &&
So, "grep grep" is an obvious typo there. Oops. The test still passes because it's fragile to begin with, we're just checking that we get no output, so "grep this string is not here" would also pass.
Re: [PATCH 1/6] test-lib: add tests for test_might_fail
In reply to Ævar Arnfjörð Bjarmasont/t0000-basic.sh test_expect_success 'test_must_fail rejects a non-git command with env' ' · line 1333
Quoted 5 lines · Ævar Arnfjörð Bjarmason
t/t0000-basic.sh +5
-0+test_expect_success 'test_might_fail is like test_must_fail ok=' ' + ! test_must_fail git version && + ! test_must_fail ok= git version && + test_might_fail git version +'
The title confuses me. Isn't might_fail like "must_fail ok=success"?
And certainly the code here shows us expecting the _opposite_ of what "Must_fail ok=" does.
-Peff
Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
In reply to Denton LiuQuoted 4 lines · Denton Liu
Hi Ævar,
First of all, thanks for reviving this series! I hope that Bash accepts your proposed patch because it would definitely be helpful.
*nod*
Quoted 30 lines · Ævar Arnfjörð Bjarmason
Quoted 8 lines
As the documentation here notes you usually do not want to do:
test_might_failgrep ...But instead:
! grep ...Quoted 7 lines
However, as a future commit will show it's handy to be able to do:
some |
test_might_failok=sigpipe grep | commands | hereTo allow "grep" to fail in the middle of a pipe, if we're in a mode such as a "set -o pipefail" that knows how to accept check intra-pipe failures.
From what I can see, there presently aren't any other use cases here except for with grep. I propose writing a wrapper around grep, à la [0]:
test_filter () { grep "$@" || : }This has two main advantanges: the first would be that we could avoid complicating the
test_must_fail_acceptable()code. The second is that it would be much less of a mouthful to write and it would be more readable.
Quoted 7 lines
Compare
some |
test_might_failok=sigpipe grep | commands | hereto
some |
test_filter| commands | here
I saw your original series/patch. including Junio's suggestion that test_grep_return_success was a bit too verbose & the suggestion for "test_filter".
I think the "test_might_fail" in this case is more readable, readable != short. I.e. imagine you haven't just been looking at this code & open that test file. If it's using "test_{might,must}_fail ok=*" you're more likely to immediately understand it since you've seen those functions in lots of places before.
If not, then "test might fail ok=sigpipe" is almost so self-documenting that you don't need to look at the function.
Whereas a "test_filter" for me at least would prompt an immediate "hrm? what's that?", followed by grepping it and the side-quest of reading the source for that function we use in a grand total of <10 places.
Anyway, just my 0.02. I also think it makes conceptual sense to just have a limited whitelist in "test_{might,must}_fail", since in this case the reason we recommend against its use for non-git doesn't apply. I.e. we're normally not in the business of testing the OS, but in this case it's got the useful behavior of knowing how to handle the exit code & signal special-case, so we might as well use it.
Quoted 7 lines
Quoted 5 lines
To test this in
t0000-basic.shwe don't actually need to have test_{might,must}_fail in the middle of a pipe, it'll just that it accepts e.g. "grep" when we provide ok=sigpipe.Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>
Re: [PATCH 5/6] tests: split up bash detection library
In reply to Ævar Arnfjörð Bjarmasont/lib-bash-detection.sh line 8
Quoted 6 lines · Ævar Arnfjörð Bjarmason
t/lib-bash-detection.sh new file +6
-0+TEST_SH_IS_BIN_BASH= +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then + TEST_SH_IS_BIN_BASH=true + export TEST_SH_IS_BIN_BASH +fi
I haven't been able to find from bash's documentation & sources whether this really is the right thing here. I.e. in test-lib.sh we've got an existing test for checking $BASH_VERSION. As far as I can tell it's not documented, but that variable doesn't appear in bash's /bin/sh mode, just in /bin/bash mode.
And then there's $POSIXLY_CORRECT, does that make it 2 modes in total, or 4 (or 3)? I didn't look too carefully, and in any case this worked for all the cases I threw at it of running the tests with /bin/sh or /bin/bash, but it would be a nice follow-up patch to unify this & the other $BASH_VERSION check in test-lib.sh if we could...
Re: [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate
In reply to Ævar Arnfjörð BjarmasonQuoted 14 lines · Ævar Arnfjörð Bjarmason
Review
Quoted 7 lines · Ævar Arnfjörð Bjarmason
test_expect_success'cherry picks did not become git merge commits' '(quoted diff) +2
-2bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep grep " .* " | cut -f1 -d" ") && - grep " .* " | cut -f1 -d" ") && + test_might_fail ok=sigpipe grep grep " .* " | cut -f1 -d" ") &&So, "grep grep" is an obvious typo there. Oops. The test still passes because it's fragile to begin with, we're just checking that we get no output, so "grep this string is not here" would also pass.
This is a good example of why tests are often better written to check for an expected outcome, rather than lack of an unexpected one.
That does often make tests more verbose and brittle, though (in this case, I guess we'd presumably have to validate the whole "rev-list" output. So it may not be practical.
I do wonder if this test needs these pipes at all. It looks like we are looking for merge commits. Maybe "rev-list --merges" would be a bit simpler these days? I.e.:
t/t9151-svn-mergeinfo.sh +9 -12
@@ -17,22 +17,19 @@ test_expect_success 'load svn dump' " " test_expect_success 'all svn merges became git merge commits' ' - unmarked=$(git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" ") && - [ -z "$unmarked" ] - ' + git rev-list --all --no-merges --grep=Merge >actual && + test_must_be_empty actual +' test_expect_success 'cherry picks did not become git merge commits' ' - bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") && - [ -z "$bad_cherries" ] - ' + git rev-list --all --merges --grep=Cherry >actual && + test_must_be_empty actual +' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' - bad_non_merges=$(git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" ") && - [ -z "$bad_non_merges" ] - ' + git rev-list --all --merges --grep=non-merge >actual && + test_must_be_empty actual +' test_expect_success 'commit made to merged branch is reachable from the merge' ' before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") &&
-Peff
Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
In reply to Ævar Arnfjörð BjarmasonQuoted 12 lines · Ævar Arnfjörð Bjarmason
Quoted 7 lines
Compare
some |
test_might_failok=sigpipe grep | commands | hereto
some |
test_filter| commands | hereI saw your original series/patch. including Junio's suggestion that
test_grep_return_successwas a bit too verbose & the suggestion for "test_filter".
Quoted 8 lines
I think the "
test_might_fail" in this case is more readable, readable != short. I.e. imagine you haven't just been looking at this code & open that test file. If it's using "test_{might,must}_fail ok=*" you're more likely to immediately understand it since you've seen those functions in lots of places before.If not, then "test might fail ok=sigpipe" is almost so self-documenting that you don't need to look at the function.
But I'm left confused...do we expect grep to get sigpipe here? I don't think so. The problem is that grep will return 0 for "I did not match anything". We would get sigpipe if "commands | here" exited without reading all of the input.
So the "ok=sigpipe" seems very misleading to me (and likewise, the whole "test_might_fail ok=sigpipe" exception seems weird; sigpipe is not the reason we want to use it with grep here; it is because grep might actually fail).
Whereas the test-filter approach is expressing what we actually are interested in (ignoring the exit code of grep, no matter what).
Quoted 3 lines
Whereas a "
test_filter" for me at least would prompt an immediate "hrm? what's that?", followed by grepping it and the side-quest of reading the source for that function we use in a grand total of <10 places.
I agree this is sometimes a problem. But if we want to inline it, it seems like the correct spelling here is:
some | { grep ... || true; } | commands | hereQuoted 6 lines
Anyway, just my 0.02. I also think it makes conceptual sense to just have a limited whitelist in "test_{might,must}_fail", since in this case the reason we recommend against its use for non-git doesn't apply. I.e. we're normally not in the business of testing the OS, but in this case it's got the useful behavior of knowing how to handle the exit code & signal special-case, so we might as well use it.
I'm somewhat lukewarm on the whitelist already, as I got bit recently by a (not yet published) test doing:
foo() {
git --with --some --options "$@"
}
test_expect_success '...' '
# this one is expected to succeed
foo ok &&
# this one is not
test_must_fail foo bad
'-Peff
Re: [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash
In reply to Ævar Arnfjörð BjarmasonQuoted 9 lines · Ævar Arnfjörð Bjarmason
Makes it useful for something like the git test suite. With vanilla bash and GIT_TEST_PIPEFAIL=true we'll fail 4 tests in my one-off test.
With my patched bash the only tests we need to skip are those that are explicitly testing that a piped command returned SIGPIPE.
As Jeff noted in [3] that count isn't reliable, as more will fail in a way that's hard to reproduce due to the racy nature of vanilla "set -o pipefail"
Yeah, the count is IMHO not important. Without a way to globally ignore sigpipe for pipefail, we're left with annotating callers. Which means it has now become much easier for people to introduce tests which racily fail. That is much worse than the problem you are trying to solve here. ;)
So it does not matter much how many cases we have. The fact that it would be easy to introduce new ones makes it unworkable IMHO (without the bash patch, I mean).
-Peff
PATCH v2 9/11 archive tests: use a cheaper "zipinfo -h" invocation to get header
In reply to Ævar Arnfjörð BjarmasonChange an invocation of zipinfo added in 19ee29401d (t5004: test ZIP archives with many entries, 2015-08-22) to simply ask zipinfo for the header info, rather than spewing out info about the entire archive and race to kill it with SIGPIPE due to the downstream "head -2".
I ran across this because I'm adding a "set -o pipefail" test mode. This won't be needed for the version of the mode that I'm introducing (which currently relies on a patch to GNU bash), but I think this is a good idea anyway.
--- t/t5004-archive-corner-cases.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/t5004-archive-corner-cases.sh +2 -1
@@ -153,7 +153,8 @@ test_expect_success ZIPINFO 'zip archive with many entries' ' # check the number of entries in the ZIP file directory expr 65536 + 256 >expect && - "$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual && + "$ZIPINFO" -h many.zip >zipinfo && + sed -n "2s/.* //p" <zipinfo >actual && test_cmp expect actual '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 8/11 upload-pack tests: avoid a non-zero "grep" exit status
In reply to Ævar Arnfjörð BjarmasonContinue changing a test that 763b47bafa (t5703: stop losing return codes of git commands, 2019-11-27) already refactored. A follow-up commit will add support for testing under bash's "set -o pipefail", under that mode this test will fail because sometimes there's no commits in the "objs" output.
It's easier to just fix this than to exempt these tests under a soon-to-be added "set -o pipefail" test mode. So let's do that.
--- t/t5703-upload-pack-ref-in-want.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
t/t5703-upload-pack-ref-in-want.sh +5 -1
@@ -16,7 +16,11 @@ get_actual_commits () { test-tool pkt-line unpack-sideband <out >o.pack && git index-pack o.pack && git verify-pack -v o.idx >objs && - grep commit objs | cut -d" " -f1 | sort >actual_commits + >actual_commits && + if grep -q commit objs + then + grep commit objs | cut -d" " -f1 | sort >actual_commits + fi } check_output () {
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 10/11 tests: split up bash detection library
In reply to Ævar Arnfjörð BjarmasonSplit up the detection for whether we're running under bash, and whether it's the /bin/sh POSIX-y mode or the /bin/bash bash-y mode into its own library.
This will soon be used very early in test-lib.sh itself to check for the /bin/bash, so let's make this new file as small as possible.
--- t/lib-bash-detection.sh | 8 ++++++++ t/lib-bash.sh | 4 +++- 2 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 t/lib-bash-detection.sh
t/lib-bash-detection.sh new file +8 -0
@@ -0,0 +1,8 @@ +#!/bin/sh + +TEST_SH_IS_BIN_BASH= +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then + TEST_SH_IS_BIN_BASH=true + export TEST_SH_IS_BIN_BASH +fi
t/lib-bash.sh +3 -1
@@ -2,7 +2,9 @@ # to run under Bash; primarily intended for tests of the completion # script. -if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +. ./lib-bash-detection.sh + +if test -n "$TEST_SH_IS_BIN_BASH" then # we are in full-on bash mode true
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 5/11 git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty
In reply to Ævar Arnfjörð BjarmasonRefactor some old-style test code to use test_must_be_empty instead of "test -z". This makes a follow-up commit easier to read.
--- t/t9151-svn-mergeinfo.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
t/t9151-svn-mergeinfo.sh +16 -15
@@ -17,41 +17,42 @@ test_expect_success 'load svn dump' " " test_expect_success 'all svn merges became git merge commits' ' - unmarked=$(git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" ") && - [ -z "$unmarked" ] + git rev-list --parents --all --grep=Merge | + grep -v " .* " | cut -f1 -d" " >unmarked && + test_must_be_empty unmarked ' + test_expect_success 'cherry picks did not become git merge commits' ' - bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") && - [ -z "$bad_cherries" ] + git rev-list --parents --all --grep=Cherry | + grep " .* " | cut -f1 -d" " >bad-cherries && + test_must_be_empty bad-cherries ' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' - bad_non_merges=$(git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" ") && - [ -z "$bad_non_merges" ] + git rev-list --parents --all --grep=non-merge | + grep " .* " | cut -f1 -d" " >bad-non-merges && + test_must_be_empty bad-non-merges ' test_expect_success 'commit made to merged branch is reachable from the merge' ' before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") && merge_commit=$(git rev-list --all --grep="Merge trunk to b2") && - not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) && - [ -z "$not_reachable" ] + git rev-list -1 $before_commit --not $merge_commit >not-reachable && + test_must_be_empty not-reachable ' test_expect_success 'merging two branches in one commit is detected correctly' ' f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") && f2_commit=$(git rev-list --all --grep="make f2 branch from trunk") && merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") && - not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) && - [ -z "$not_reachable" ] + git rev-list -1 $f1_commit $f2_commit --not $merge_commit >not-reachable && + test_must_be_empty not-reachable ' test_expect_failure 'everything got merged in the end' ' - unmerged=$(git rev-list --all --not master) && - [ -z "$unmerged" ] + git rev-list --all --not master >unmerged && + test_must_be_empty unmerged ' test_done
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 11/11 tests: add a "set -o pipefail" for a patched bash
In reply to Ævar Arnfjörð BjarmasonAdd a "set -o pipefail" test mode to the test suite to detect failures in "git" its output is fed directly to a pipe. Doing so is a pattern we discourage[1] in the test suite, but we've got plenty of tests like that. Now we can reliably detect those failures.
There was a previous attempt in [2] to add such a test mode, but as noted by Jeff King in [3] adding it is a matter of peeing against the wind with current bash semantics of failing on SIGPIPE.
This series relies on a patch of mine to bash, which I'm submitting upstream, while not breaking anything for vanilla bash users. They won't have GIT_TEST_PIPEFAIL turned on for them, and will only get breakages if they turn it on explicitly with "GIT_TEST_PIPEFAIL=true".
Vanilla bash ignores SIGPIPE under "set -e" since version 3.1. It's only under "set -o pipefail" (added in 3.2) that it doesn't take account of SIGPIPE, in a seeming omission nobody bothered to fix yet.
Patching bash[4] with:
diff --git a/jobs.c b/jobs.c
index a581f305..fa5de82a 100644
--- a/jobs.c
+++ b/jobs.c
@@ -2851,8 +2851,14 @@ raw_job_exit_status (job)
p = jobs[job]->pipe;
do
{
- if (WSTATUS (p->status) != EXECUTION_SUCCESS)
- fail = WSTATUS(p->status);
+ if (WSTATUS (p->status) != EXECUTION_SUCCESS
+#if defined (DONT_REPORT_SIGPIPE)
+ && WTERMSIG (p->status) != SIGPIPE
+#endif
+ )
+ {
+ fail = WSTATUS(p->status);
+ }
p = p->next;
}
while (p != jobs[job]->pipe);Makes it useful for something like the git test suite.
Under this test mode we only tests we need to skip those tests which are explicitly testing that a piped command returned SIGPIPE. Those tests will now return 0 instead of an exit code indicating SIGPIPE.
Forcing the mode to run under vanilla bash with "GIT_TEST_PIPEFAIL=true" doesn't fail any tests for me, except the test in t0000-basic.sh which explicitly checks for the desired pipefail semantics. However, as Jeff noted in [3] that absence of failure isn't reliable. I might not see some of the failures due to the racy nature of how vanilla "set -o pipefail" interacts with *nix pipe semantics.
1. a378fee5b0 (Documentation: add shell guidelines, 2018-10-05)
2. https://lore.kernel.org/git/[email protected]/
3. https://lore.kernel.org/git/[email protected]/
4. https://github.com/bminor/bash/compare/master...avar:avar/ignore-sigterm-and-sigpipe-on-pipe-fail
--- t/README | 5 +++++ t/t0000-basic.sh | 4 ++++ t/t0005-signals.sh | 4 ++-- t/t3600-rm.sh | 5 ++++- t/t5000-tar-tree.sh | 2 +- t/t9902-completion.sh | 5 +++++ t/test-lib.sh | 29 +++++++++++++++++++++++++++++ 7 files changed, 50 insertions(+), 4 deletions(-)
t/README +5 -0
@@ -439,6 +439,11 @@ GIT_TEST_DEFAULT_HASH=<hash-algo> specifies which hash algorithm to use in the test scripts. Recognized values for <hash-algo> are "sha1" and "sha256". +GIT_TEST_PIPEFAIL=<boolean>, when true, run 'set -o pipefail' to catch +failures in commands that aren't the last in a pipe. Defaults to true +on bash versions which know how to ignore SIGPIPE failures under the +'set -o pipefail' mode. + Naming Tests ------------
t/t0000-basic.sh +4 -0
@@ -1326,4 +1326,8 @@ test_expect_success 'test_must_fail rejects a non-git command with env' ' grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err ' +test_expect_success BASH_SET_O_PIPEFAIL 'our bash under "set -o pipefail" mode ignores SIGPIPE failures' ' + yes | head -n 1 | true +' + test_done
t/t0005-signals.sh +2 -2
@@ -40,12 +40,12 @@ test_expect_success 'create blob' ' git add file ' -test_expect_success !MINGW 'a constipated git dies with SIGPIPE' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE' ' OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" ' -test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE even if parent ignores it' ' OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" '
t/t3600-rm.sh +4 -1
@@ -251,7 +251,10 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' i=$(( $i + 1 )) done | git update-index --index-info && OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && - test_match_signal 13 "$OUT" && + if ! test_have_prereq BASH_SET_O_PIPEFAIL + then + test_match_signal 13 "$OUT" + fi && test_path_is_missing .git/index.lock '
t/t5000-tar-tree.sh +1 -1
@@ -416,7 +416,7 @@ test_expect_success LONG_IS_64BIT 'set up repository with huge blob' ' # We expect git to die with SIGPIPE here (otherwise we # would generate the whole 64GB). -test_expect_success LONG_IS_64BIT 'generate tar with huge size' ' +test_expect_success LONG_IS_64BIT,!BASH_SET_O_PIPEFAIL 'generate tar with huge size' ' { git archive HEAD echo $? >exit-code
t/t9902-completion.sh +5 -0
@@ -7,6 +7,11 @@ test_description='test bash completion' . ./lib-bash.sh +if test -n "$GIT_TEST_PIPEFAIL_TRUE" +then + set +o pipefail +fi + complete () { # do nothing
t/test-lib.sh +29 -0
@@ -36,6 +36,31 @@ then fi GIT_BUILD_DIR="$TEST_DIRECTORY"/.. +# Does "set -o pipefail" on this bash version handle SIGPIPE? Use it! +. "$TEST_DIRECTORY/lib-bash-detection.sh" +GIT_TEST_PIPEFAIL_TRUE= +GIT_TEST_PIPEFAIL_DEFAULT=false +if test -n "$TEST_SH_IS_BIN_BASH" && + $BASH -c 'set -eo pipefail; yes | head -n 1 >/dev/null' +then + GIT_TEST_PIPEFAIL_DEFAULT=true +fi +# We're too early for test_bool_env +if git env--helper --type=bool --default="$GIT_TEST_PIPEFAIL_DEFAULT" \ + --exit-code GIT_TEST_PIPEFAIL +then + set -o pipefail + + # Only "set -o pipefail" in the main test scripts, not any + # sub-programs we spawn. + GIT_TEST_PIPEFAIL= + export GIT_TEST_PIPEFAIL + + # For the convenience of the prereq for it. + GIT_TEST_PIPEFAIL_TRUE=true + export GIT_TEST_PIPEFAIL_TRUE +fi + # If we were built with ASAN, it may complain about leaks # of program-lifetime variables. Disable it by default to lower # the noise level. This needs to happen at the start of the script,
@@ -1552,6 +1577,10 @@ test_lazy_prereq PIPE ' rm -f testfifo && mkfifo testfifo ' +test_lazy_prereq BASH_SET_O_PIPEFAIL ' + test -n "$GIT_TEST_PIPEFAIL_TRUE" +' + test_lazy_prereq SYMLINKS ' # test whether the filesystem supports symbolic links ln -s x y && test -h y
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 2/11 cache-tree tests: use a sub-shell with less indirection
In reply to Ævar Arnfjörð BjarmasonChange a "cd xyz && work && cd .." pattern introduced in 9c4d6c0297 (cache-tree: Write updated cache-tree after commit, 2014-07-13) to use a sub-shell instead with less indirection.
We did actually recover correctly if we failed in this function since we were wrapped in a subshell one function call up. Let's just use the sub-shell at the point where we want to change the directory instead. This also allows us to get rid of the wrapper function.
--- t/t0090-cache-tree.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
t/t0090-cache-tree.sh +5 -10
@@ -27,20 +27,15 @@ generate_expected_cache_tree_rec () { printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && for subtree in $subtrees do - cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" || return 1 - cd .. + ( + cd "$subtree" + generate_expected_cache_tree_rec "$dir$subtree" || return 1 + ) done } -generate_expected_cache_tree () { - ( - generate_expected_cache_tree_rec - ) -} - test_cache_tree () { - generate_expected_cache_tree >expect && + generate_expected_cache_tree_rec >expect && cmp_cache_tree expect }
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 7/11 rm tests: actually test for SIGPIPE in SIGPIPE test
In reply to Ævar Arnfjörð BjarmasonChange a test initially added in 50cd31c652 (t3600: comment on inducing SIGPIPE in git rm, 2019-11-27) to explicitly test for SIGPIPE using a pattern initially established in 7559a1be8a (unblock and unignore SIGPIPE, 2014-09-18).
--- t/t3600-rm.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t3600-rm.sh +2 -2
@@ -250,8 +250,8 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' echo "100644 $hash 0 some-file-$i" i=$(( $i + 1 )) done | git update-index --index-info && - # git command is intentionally placed upstream of pipe to induce SIGPIPE - git rm -n "some-file-*" | : && + OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && + test_match_signal 13 "$OUT" && test_path_is_missing .git/index.lock '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 1/11 cache-tree tests: remove unused $2 parameter
In reply to Ævar Arnfjörð BjarmasonRemove the $2 paramater. This appears to have been some work-in-progress code from an earlier version of 9c4d6c0297 (cache-tree: Write updated cache-tree after commit, 2014-07-13) which was left in the final version.
--- t/t0090-cache-tree.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
t/t0090-cache-tree.sh +2 -4
@@ -18,7 +18,6 @@ cmp_cache_tree () { # correct. generate_expected_cache_tree_rec () { dir="$1${1:+/}" && - parent="$2" && # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux # We want to count only foo because it's the only direct child git ls-files >files &&
@@ -29,10 +28,9 @@ generate_expected_cache_tree_rec () { for subtree in $subtrees do cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" "$dir" || return 1 + generate_expected_cache_tree_rec "$dir$subtree" || return 1 cd .. - done && - dir=$parent + done } generate_expected_cache_tree () {
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 3/11 cache-tree tests: refactor overly complex function
In reply to Ævar Arnfjörð BjarmasonRefactor overly complex code added in 9c4d6c0297 (cache-tree: Write updated cache-tree after commit, 2014-07-13).
Interestingly, in the numerous commits[1][2][3] who fixed commits bugs in this code since its introduction it seems not to have been noticed that we didn't need to be doing some dance with grep/cut/uniq/awk to extract this information. It can be done in a much simpler way with just "ls-tree" and "wc -l".
I'm also removing the comment, because I think now that this code is trivial to understand it's not needed anymore.
1. c8db708d5d (t0090: avoid passing empty string to printf %d, 2014-09-30)
2. d69360c6b1 (t0090: tweak awk statement for Solaris /usr/xpg4/bin/awk, 2014-12-22)
3. 9b5a9fa60a (t0090: stop losing return codes of git commands, 2019-11-27)
--- t/t0090-cache-tree.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)
t/t0090-cache-tree.sh +6 -10
@@ -18,20 +18,16 @@ cmp_cache_tree () { # correct. generate_expected_cache_tree_rec () { dir="$1${1:+/}" && - # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux - # We want to count only foo because it's the only direct child - git ls-files >files && - subtrees=$(grep / files|cut -d / -f 1|uniq) && - subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') && - entries=$(wc -l <files) && - printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && - for subtree in $subtrees + git ls-tree --name-only HEAD >files && + git ls-tree --name-only -d HEAD >subtrees && + printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) && + while read subtree do ( cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" || return 1 + generate_expected_cache_tree_rec "$subtree" || return 1 ) - done + done <subtrees } test_cache_tree () {
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH 1/1 test-lib: add tests for test_might_fail
In reply to Jeff KingThis trivial sibling command of test_must_fail added in fdf1bc48ca (t7006: guard cleanup with test_expect_success, 2010-04-14) didn't have any tests. Let's add at least a basic one.
---
Quoted 8 lines · Jeff King
Review
Quoted 5 lines · Ævar Arnfjörð Bjarmason
(quoted diff) +5
-0+test_expect_success 'test_might_fail is like test_must_fail ok=' ' + ! test_must_fail git version && + ! test_must_fail ok= git version && + test_might_fail git version +'
Quoted 4 lines
The title confuses me. Isn't
might_faillike "must_failok=success"?And certainly the code here shows us expecting the _opposite_ of what "
Must_failok=" does.
Yes, this made no sense. Here's a sensibe test.
Junio: This is a stand-alone patch now. I'm splitting this off from my WIP v2 of the "set -o pipefail" series.
t/t0000-basic.sh | 5 +++++ 1 file changed, 5 insertions(+)
t/t0000-basic.sh +5 -0
@@ -1326,4 +1326,9 @@ test_expect_success 'test_must_fail rejects a non-git command with env' ' grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err ' +test_expect_success 'test_might_fail is like test_must_fail ok=success' ' + test_must_fail ok=success git version && + test_might_fail git version +' + test_done
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 4/11 git svn mergeinfo tests: modernize redirection & quoting style
In reply to Ævar Arnfjörð BjarmasonUse "<file" instead of "< file", and don't put the closing quote for strings on an indented line. This makes a follow-up refactoring commit easier to read.
--- t/t9151-svn-mergeinfo.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
t/t9151-svn-mergeinfo.sh +8 -8
@@ -9,37 +9,37 @@ test_description='git-svn svn mergeinfo properties' test_expect_success 'load svn dump' " svnadmin load -q '$rawsvnrepo' \ - < '$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' && + <'$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' && git svn init --minimize-url -R svnmerge \ --rewrite-root=http://svn.example.org \ -T trunk -b branches '$svnrepo' && git svn fetch --all - " +" test_expect_success 'all svn merges became git merge commits' ' unmarked=$(git rev-list --parents --all --grep=Merge | grep -v " .* " | cut -f1 -d" ") && [ -z "$unmarked" ] - ' +' test_expect_success 'cherry picks did not become git merge commits' ' bad_cherries=$(git rev-list --parents --all --grep=Cherry | grep " .* " | cut -f1 -d" ") && [ -z "$bad_cherries" ] - ' +' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' bad_non_merges=$(git rev-list --parents --all --grep=non-merge | grep " .* " | cut -f1 -d" ") && [ -z "$bad_non_merges" ] - ' +' test_expect_success 'commit made to merged branch is reachable from the merge' ' before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") && merge_commit=$(git rev-list --all --grep="Merge trunk to b2") && not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) && [ -z "$not_reachable" ] - ' +' test_expect_success 'merging two branches in one commit is detected correctly' ' f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") &&
@@ -47,11 +47,11 @@ test_expect_success 'merging two branches in one commit is detected correctly' ' merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") && not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) && [ -z "$not_reachable" ] - ' +' test_expect_failure 'everything got merged in the end' ' unmerged=$(git rev-list --all --not master) && [ -z "$unmerged" ] - ' +' test_done
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v2 6/11 git-svn tests: rewrite brittle tests to use "--[no-]merges".
In reply to Ævar Arnfjörð BjarmasonFrom: Jeff King <[email protected]>
Rewrite a brittle tests which used "rev-list" without "--[no-]merges" to figure out if a set of commits turned into merge commits or not.
--- t/t9151-svn-mergeinfo.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
t/t9151-svn-mergeinfo.sh +3 -7
@@ -17,21 +17,17 @@ test_expect_success 'load svn dump' " " test_expect_success 'all svn merges became git merge commits' ' - git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" " >unmarked && + git rev-list --all --no-merges --grep=Merge >unmarked && test_must_be_empty unmarked ' - test_expect_success 'cherry picks did not become git merge commits' ' - git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" " >bad-cherries && + git rev-list --all --merges --grep=Cherry >bad-cherries && test_must_be_empty bad-cherries ' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' - git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" " >bad-non-merges && + git rev-list --all --merges --grep=non-merge >bad-non-merges && test_must_be_empty bad-non-merges '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
v2 cover tests: add a bash "set -o pipefail" test mode
In reply to Ævar Arnfjörð BjarmasonAn unstated aim of v1 of this series was to fix up the tests on vanilla bash's "set -o pipefail" enough that the test suite would have some failures, but wouldn't look like a complete dumpster fire.
But this was confusing and relied on a side-quest to change the test_{must,might}_fail helpers. See
https://lore.kernel.org/git/[email protected]/
I've now ejected all of that, in favor of just fixing some of the tests instead as Jeff suggested. Jeff, I added your Signed-off-by to 06/11 which you're mostly the author of. Please Ack that you're OK with that (the original diff-for-discussin didn't have a SOB).
Jeff King (1):
git-svn tests: rewrite brittle tests to use "--[no-]merges".
Ævar Arnfjörð Bjarmason (10):
cache-tree tests: remove unused $2 parameter
cache-tree tests: use a sub-shell with less indirection cache-tree tests: refactor overly complex function
git svn mergeinfo tests: modernize redirection & quoting style git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty rm tests: actually test for SIGPIPE in SIGPIPE test upload-pack tests: avoid a non-zero "grep" exit status archive tests: use a cheaper "zipinfo -h" invocation to get header
tests: split up bash detection library
tests: add a "set -o pipefail" for a patched bash
t/README | 5 ++++ t/lib-bash-detection.sh | 8 ++++++ t/lib-bash.sh | 4 ++- t/t0000-basic.sh | 4 +++ t/t0005-signals.sh | 4 +-- t/t0090-cache-tree.sh | 31 +++++++-------------- t/t3600-rm.sh | 7 +++-- t/t5000-tar-tree.sh | 2 +- t/t5004-archive-corner-cases.sh | 3 ++- t/t5703-upload-pack-ref-in-want.sh | 6 ++++- t/t9151-svn-mergeinfo.sh | 43 ++++++++++++++---------------- t/t9902-completion.sh | 5 ++++ t/test-lib.sh | 29 ++++++++++++++++++++ 13 files changed, 99 insertions(+), 52 deletions(-) create mode 100644 t/lib-bash-detection.sh
Range-diff:
1: d950fbb967 < -: ---------- test-lib: add tests for test_might_fail
2: 1a0ffb1159 < -: ---------- test-lib: add ok=* support to test_might_fail
3: f7eaceeb3e < -: ---------- test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
4: 0e77779947 < -: ---------- tests: use "test_might_fail ok=sigpipe grep" when appropriate
-: ---------- > 1: 8e8e03fa3d cache-tree tests: remove unused $2 parameter
-: ---------- > 2: 828d25533c cache-tree tests: use a sub-shell with less indirection
-: ---------- > 3: fefdc570a5 cache-tree tests: refactor overly complex function
-: ---------- > 4: a16938e58d git svn mergeinfo tests: modernize redirection & quoting style
-: ---------- > 5: b520656240 git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty
-: ---------- > 6: f2e70ac911 git-svn tests: rewrite brittle tests to use "--[no-]merges".
-: ---------- > 7: dcf001e165 rm tests: actually test for SIGPIPE in SIGPIPE test
-: ---------- > 8: 2212fa65eb upload-pack tests: avoid a non-zero "grep" exit status
-: ---------- > 9: 8167c2e346 archive tests: use a cheaper "zipinfo -h" invocation to get header
5: c3916b8e7b = 10: 30c454ae7c tests: split up bash detection library
6: 4a988d1c73 ! 11: 6f290f850c tests: add a "set -o pipefail" for a patched bash @@ Commit message
wind with current bash semantics of failing on SIGPIPE.
This series relies on a patch of mine to bash, which I'm submitting
- upstream. Vanilla bash ignores SIGPIPE under "set -e" since version
- 3.1. It's only under "set -o pipefail" (added in 3.2) that it doesn't
- take account of SIGPIPE, in a seeming omission nobody bothered to fix
- yet.
+ upstream, while not breaking anything for vanilla bash users. They
+ won't have GIT_TEST_PIPEFAIL turned on for them, and will only get
+ breakages if they turn it on explicitly with "GIT_TEST_PIPEFAIL=true".
+
+ Vanilla bash ignores SIGPIPE under "set -e" since version 3.1. It's
+ only under "set -o pipefail" (added in 3.2) that it doesn't take
+ account of SIGPIPE, in a seeming omission nobody bothered to fix yet.
Patching bash[4] with:
@@ Commit message
}
while (p != jobs[job]->pipe);
- Makes it useful for something like the git test suite. With vanilla
- bash and GIT_TEST_PIPEFAIL=true we'll fail 4 tests in my one-off test.
+ Makes it useful for something like the git test suite.
- With my patched bash the only tests we need to skip are those that are
- explicitly testing that a piped command returned SIGPIPE.
+ Under this test mode we only tests we need to skip those tests which
+ are explicitly testing that a piped command returned SIGPIPE. Those
+ tests will now return 0 instead of an exit code indicating SIGPIPE.
- As Jeff noted in [3] that count isn't reliable, as more will fail in a
- way that's hard to reproduce due to the racy nature of vanilla "set -o
- pipefail"
+ Forcing the mode to run under vanilla bash with
+ "GIT_TEST_PIPEFAIL=true" doesn't fail any tests for me, except the
+ test in t0000-basic.sh which explicitly checks for the desired
+ pipefail semantics. However, as Jeff noted in [3] that absence of
+ failure isn't reliable. I might not see some of the failures due to
+ the racy nature of how vanilla "set -o pipefail" interacts with *nix
+ pipe semantics.
1. a378fee5b0 (Documentation: add shell guidelines, 2018-10-05)
2. https://lore.kernel.org/git/[email protected]/
@@ t/README: GIT_TEST_DEFAULT_HASH=<hash-algo> specifies which hash algorithm to
+GIT_TEST_PIPEFAIL=<boolean>, when true, run 'set -o pipefail' to catch +failures in commands that aren't the last in a pipe. Defaults to true +on bash versions which know how to ignore SIGPIPE failures under the
-+'set -o pipefail' mode (as of 2021-01-14 only in an out-of-tree patch -+to bash).
++'set -o pipefail' mode.
+
Naming Tests
------------
## t/t0000-basic.sh ##
-@@ t/t0000-basic.sh: test_expect_success 'test_{must,might}_fail accept non-git on "sigpipe"' '
- test_cmp badobjects out
+@@ t/t0000-basic.sh: test_expect_success 'test_must_fail rejects a non-git command with env' '
+ grep -F "test_must_fail: only '"'"'git'"'"' is allowed" err
'
-+test_expect_failure BASH_SET_O_PIPEFAIL 'test_{must,might}_fail ok=sigpipe under bash "set -o pipefail"' '
-+ grep string </dev/null | true
-+'
-+
-+test_expect_failure BASH_SET_O_PIPEFAIL 'test_{must,might}_fail ok=sigpipe under bash "set -o pipefail"' '
-+ test_must_fail grep string </dev/null | true &&
-+ test_might_fail grep string </dev/null | true
-+'
-+
-+test_expect_success BASH_SET_O_PIPEFAIL 'test_{must,might}_fail ok=sigpipe under bash "set -o pipefail"' '
-+ test_must_fail ok=sigpipe grep string </dev/null | true &&
-+ test_might_fail ok=sigpipe grep string </dev/null | true
++test_expect_success BASH_SET_O_PIPEFAIL 'our bash under "set -o pipefail" mode ignores SIGPIPE failures' '
++ yes | head -n 1 | true
+'
+
test_done
@@ t/t0005-signals.sh: test_expect_success 'create blob' '
test_match_signal 13 "$OUT"
'
+ ## t/t3600-rm.sh ##
+@@ t/t3600-rm.sh: test_expect_success 'choking "git rm" should not let it die with cruft' '
+ i=$(( $i + 1 ))
+ done | git update-index --index-info &&
+ OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) &&
+- test_match_signal 13 "$OUT" &&
++ if ! test_have_prereq BASH_SET_O_PIPEFAIL
++ then
++ test_match_signal 13 "$OUT"
++ fi &&
+ test_path_is_missing .git/index.lock
+ '
+
+
## t/t5000-tar-tree.sh ##
@@ t/t5000-tar-tree.sh: test_expect_success LONG_IS_64BIT 'set up repository with huge blob' '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
Re: [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
Continue changing a test that
763b47bafa(t5703: stop losing return codes of git commands, 2019-11-27) already refactored. A follow-up commit will add support for testing under bash's "set -o pipefail", under that mode this test will fail because sometimes there's no commits in the "objs" output.It's easier to just fix this than to exempt these tests under a soon-to-be added "set -o pipefail" test mode. So let's do that.
Hmph, if you do not like the fact that grep indicates hits vs no hits via its exit codes and you are purely interested in its text munging utility, why not use a more appropriate tool than grep piped to cut? Running the same grep twice just to work around its exit code looks doubly suboptimal.
sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs | sort >actual_commits
perhaps?
Quoted 22 lines
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t5703-upload-pack-ref-in-want.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)t/t5703-upload-pack-ref-in-want.sh +5
-1@@ -16,7 +16,11 @@ get_actual_commits () { test-tool pkt-line unpack-sideband <out >o.pack && git index-pack o.pack && git verify-pack -v o.idx >objs && - grep commit objs | cut -d" " -f1 | sort >actual_commits + >actual_commits && + if grep -q commit objs + then + grep commit objs | cut -d" " -f1 | sort >actual_commits + fi } check_output () {
Re: [PATCH v2 00/11] tests: add a bash "set -o pipefail" test mode
In reply to Ævar Arnfjörð BjarmasonQuoted 4 lines · Ævar Arnfjörð Bjarmason
An unstated aim of v1 of this series was to fix up the tests on vanilla bash's "set -o pipefail" enough that the test suite would have some failures, but wouldn't look like a complete dumpster fire.
Quoted 8 lines
But this was confusing and relied on a side-quest to change the test_{must,might}_fail helpers. See
https://lore.kernel.org/git/[email protected]/I've now ejected all of that, in favor of just fixing some of the tests instead as Jeff suggested. Jeff, I added your Signed-off-by to 06/11 which you're mostly the author of. Please Ack that you're OK with that (the original diff-for-discussin didn't have a SOB).
I didn't read the last two pieces that are bash specific, but everything else was a pleasant read. I did have a few comments, though.
Thanks.
Re: [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges".
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
From: Jeff King <[email protected]>
Rewrite a brittle tests which used "rev-list" without "--[no-]merges" to figure out if a set of commits turned into merge commits or not.
Signed-off-by Jeff King <[email protected]>Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>Commit-message-by Ævar Arnfjörð Bjarmason <[email protected]>
The last two entries are not chronological, but when you relay a patch by others with tweaks, we typically do it more like this:
From: Jeff King <[email protected]>
Rewrite a brittle ...
e.g. cf. 155067ab4f, a9ecaa06a723, 567ad2c0f9
Thanks.
Re: [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style
In reply to Ævar Arnfjörð BjarmasonQuoted 14 lines · Ævar Arnfjörð Bjarmason
Use "<file" instead of "< file", and don't put the closing quote for strings on an indented line. This makes a follow-up refactoring commit easier to read.
Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t9151-svn-mergeinfo.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)t/t9151-svn-mergeinfo.sh +0
-0
t/t9151-svn-mergeinfo.sh test_description='git-svn svn mergeinfo properties' · line 12
Quoted 5 lines
t/t9151-svn-mergeinfo.sh +1
-1@@ -9,37 +9,37 @@ test_description='git-svn svn mergeinfo properties' test_expect_success 'load svn dump' " svnadmin load -q '$rawsvnrepo' \ - < '$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' && + <'$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' &&
This is not a new issue, but if $TEST_DIRECTORY or $rawsvnrepo have a funny character (like "'") in them, the above does not do the right thing. Everything would work much better, if swap dq and sq for the body, because these $variables _are_ visible in the body that is eval'ed.
But you mentioned "a follow-up refactoring", so let's expect that things will get better in a later step.
Thanks.
Re: [PATCH v2 03/11] cache-tree tests: refactor overly complex function
In reply to Ævar Arnfjörð BjarmasonQuoted 2 lines · Ævar Arnfjörð Bjarmason
Refactor overly complex code added in
9c4d6c0297(cache-tree: Write updated cache-tree after commit, 2014-07-13).
OK.
Quoted 2 lines
Interestingly, in the numerous commits[1][2][3] who fixed commits bugs in this code since its introduction it seems not to have been noticed
Sorry but -ECANNOTPARSE.
Quoted 3 lines
that we didn't need to be doing some dance with grep/cut/uniq/awk to extract this information. It can be done in a much simpler way with just "ls-tree" and "wc -l".
The new code seems to take advantage of the fact that the index and HEAD are always in sync when test_cache_tree is called; it is worth mentioning in the log message around here.
Quoted 2 lines
I'm also removing the comment, because I think now that this code is trivial to understand it's not needed anymore.
OK.
Thanks.
Quoted 43 lines
1.
c8db708d5d(t0090: avoid passing empty string to printf %d, 2014-09-30)
2.d69360c6b1(t0090: tweak awk statement for Solaris/usr/xpg4/bin/awk, 2014-12-22)
3.9b5a9fa60a(t0090: stop losing return codes of git commands, 2019-11-27)Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>--- t/t0090-cache-tree.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-)t/t0090-cache-tree.sh +6
-10@@ -18,20 +18,16 @@ cmp_cache_tree () { # correct. generate_expected_cache_tree_rec () { dir="$1${1:+/}" && - # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux - # We want to count only foo because it's the only direct child - git ls-files >files && - subtrees=$(grep / files|cut -d / -f 1|uniq) && - subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') && - entries=$(wc -l <files) && - printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && - for subtree in $subtrees + git ls-tree --name-only HEAD >files && + git ls-tree --name-only -d HEAD >subtrees && + printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) && + while read subtree do ( cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" || return 1 + generate_expected_cache_tree_rec "$subtree" || return 1 ) - done + done <subtrees } test_cache_tree () {
Re: [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges".
In reply to Ævar Arnfjörð BjarmasonQuoted 8 lines · Ævar Arnfjörð Bjarmason
From: Jeff King <[email protected]>
Rewrite a brittle tests which used "rev-list" without "--[no-]merges" to figure out if a set of commits turned into merge commits or not.
Signed-off-by Jeff King <[email protected]>Signed-off-by Ævar Arnfjörð Bjarmason <[email protected]>Commit-message-by Ævar Arnfjörð Bjarmason <[email protected]>
Thanks for picking this up. I think it's a cleanup worth doing.
I didn't actually sign-off the original I sent, though. I'm quite happy to do so now, and in general everything I send to the list as a "something like this" patch will be done with the intent that it could be contributed under the DCO. But I think in such a case, we should stop short of forging the signoff. And ideally get an explicit signoff, or lacking that just add your own to assert DCO's paragraph (b).
Anyway, this is most definitely:
-Peff
Re: [PATCH] test-lib: add tests for test_might_fail
In reply to Ævar Arnfjörð BjarmasonQuoted 9 lines · Ævar Arnfjörð Bjarmason
Quoted 4 lines
The title confuses me. Isn't
might_faillike "must_failok=success"?And certainly the code here shows us expecting the _opposite_ of what "
Must_failok=" does.Yes, this made no sense. Here's a sensibe test.
Junio: This is a stand-alone patch now. I'm splitting this off from my WIP v2 of the "set -o pipefail" series.
OK, I'm glad I wasn't just missing something. :) This one makes sense to me, and seems like a reasonable thing to be checking.
-Peff
Re: [PATCH v2 00/11] tests: add a bash "set -o pipefail" test mode
In reply to Ævar Arnfjörð BjarmasonQuoted 4 lines · Ævar Arnfjörð Bjarmason
I've now ejected all of that, in favor of just fixing some of the tests instead as Jeff suggested. Jeff, I added your Signed-off-by to 06/11 which you're mostly the author of. Please Ack that you're OK with that (the original diff-for-discussin didn't have a SOB).
Oh, I just wrote my other response before reading this (reading emails in order? Preposterous!). So you can soften my lecture on S-o-b while reading that one. :)
And just to repeat what I said there: yes, my signoff is fine there.
-Peff
Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection
In reply to Ævar Arnfjörð BjarmasonQuoted 6 lines · Ævar Arnfjörð Bjarmason
t/t0090-cache-tree.sh +0
-0@@ -27,20 +27,15 @@ generate_expected_cache_tree_rec () { printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
t/t0090-cache-tree.sh generate_expected_cache_tree_rec () { · line 34
Quoted 10 lines
t/t0090-cache-tree.sh +4
-3for subtree in $subtrees do - cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" || return 1 - cd .. + ( + cd "$subtree" + generate_expected_cache_tree_rec "$dir$subtree" || return 1 + ) done
We don't check that "cd" worked either before or after your patch. Should we?
After your patch, we "return" from inside a subshell. Is that portable? ISTR issues around that before, but it just have been when we are not in a function at all. Still, I wonder if:
for ...
do
( cd "$subtree" && generate_expected_cache_tree_rec "$dir$subtree" ) || return 1
done
might be more obvious.
t/t0090-cache-tree.sh generate_expected_cache_tree_rec () { · line 40
Quoted 5 lines
t/t0090-cache-tree.sh +0
-5-generate_expected_cache_tree () { - ( - generate_expected_cache_tree_rec - ) -}
I wondered what the "rec" was for, but I guess it is "recurse". Not a problem to keep it, but I wonder if it could be dropped in the name of shortness/simplicity (not worth a re-roll for sure, but maybe worth doing so if you re-roll for the above issues).
-Peff
Re: [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header
In reply to Ævar Arnfjörð BjarmasonQuoted 9 lines · Ævar Arnfjörð Bjarmason
Change an invocation of zipinfo added in
19ee29401d(t5004: test ZIP archives with many entries, 2015-08-22) to simply ask zipinfo for the header info, rather than spewing out info about the entire archive and race to kill it with SIGPIPE due to the downstream "head -2".I ran across this because I'm adding a "set -o pipefail" test mode. This won't be needed for the version of the mode that I'm introducing (which currently relies on a patch to GNU bash), but I think this is a good idea anyway.
Makes sense. The only risk here would be that "-h" is not portable. But I don't have any reason to think that's the case, and since it's just a test, I'm fine with proceeding and seeing if anybody screams.
-Peff
Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection
In reply to Jeff KingQuoted 11 lines · Jeff King
t/t0090-cache-tree.sh generate_expected_cache_tree_rec () { · line 34
Quoted 7 lines · Ævar Arnfjörð Bjarmason
for subtree in $subtrees
dot/t0090-cache-tree.sh +4
-0+ ( + cd "$subtree" + generate_expected_cache_tree_rec "$dir$subtree" || return 1 + ) doneWe don't check that "cd" worked either before or after your patch. Should we?
I'd say "yes".
Quoted 12 lines
After your patch, we "return" from inside a subshell. Is that portable? ISTR issues around that before, but it just have been when we are not in a function at all. Still, I wonder if:
for ... do ( cd "$subtree" && generate_expected_cache_tree_rec "$dir$subtree" ) || return 1 done
Quoted 1 line
might be more obvious.
Yes, a good recommendation. Normally, we exit 1 from within subshells[1], but that wouldn't help us exit this loop early, so the || return 1 outside the subshell seems a good solution.
Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection
In reply to Jeff KingQuoted 26 lines · Jeff King
Quoted 6 lines · Ævar Arnfjörð Bjarmason
t/t0090-cache-tree.sh +0
-0@@ -27,20 +27,15 @@ generate_expected_cache_tree_rec () { printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&t/t0090-cache-tree.sh generate_expected_cache_tree_rec () { · line 34
Quoted 10 lines
t/t0090-cache-tree.sh +4
-3for subtree in $subtrees do - cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" || return 1 - cd .. + ( + cd "$subtree" + generate_expected_cache_tree_rec "$dir$subtree" || return 1 + ) doneWe don't check that "cd" worked either before or after your patch. Should we?
After your patch, we "return" from inside a subshell. Is that portable? ISTR issues around that before, but it just have been when we are not in a function at all. Still, I wonder if:
Quoted 7 lines
for ...
do( cd "$subtree" && generate_expected_cache_tree_rec "$dir$subtree" ) || return 1done
Thanks, I missed that bogus/confusing return.
Quoted 15 lines
might be more obvious.
t/t0090-cache-tree.sh generate_expected_cache_tree_rec () { · line 40
Quoted 5 lines
t/t0090-cache-tree.sh +0
-5-generate_expected_cache_tree () { - ( - generate_expected_cache_tree_rec - ) -}I wondered what the "rec" was for, but I guess it is "recurse". Not a problem to keep it, but I wonder if it could be dropped in the name of shortness/simplicity (not worth a re-roll for sure, but maybe worth doing so if you re-roll for the above issues).
-Peff
Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash
In reply to Ævar Arnfjörð BjarmasonQuoted 5 lines · Ævar Arnfjörð Bjarmason
Add a "set -o pipefail" test mode to the test suite to detect failures in "git" its output is fed directly to a pipe. Doing so is a pattern we discourage[1] in the test suite, but we've got plenty of tests like that. Now we can reliably detect those failures.
Quoted 8 lines
There was a previous attempt in [2] to add such a test mode, but as noted by Jeff King in [3] adding it is a matter of peeing against the wind with current bash semantics of failing on SIGPIPE.
This series relies on a patch of mine to bash, which I'm submitting upstream, while not breaking anything for vanilla bash users. They won't have
GIT_TEST_PIPEFAILturned on for them, and will only get breakages if they turn it on explicitly with "GIT_TEST_PIPEFAIL=true".
I'm not sure about adding code to our test framework that only works with a patched shell.
Quoted 59 lines
Vanilla bash ignores SIGPIPE under "set -e" since version 3.1. It's only under "set -o pipefail" (added in 3.2) that it doesn't take account of SIGPIPE, in a seeming omission nobody bothered to fix yet.
Patching bash[4] with:
diff --git a/jobs.c b/jobs.c index a581f305..fa5de82a 100644 --- a/jobs.c +++ b/jobs.c @@ -2851,8 +2851,14 @@ raw_job_exit_status (job) p = jobs[job]->pipe; do { - if (WSTATUS (p->status) != EXECUTION_SUCCESS) - fail = WSTATUS(p->status); + if (WSTATUS (p->status) != EXECUTION_SUCCESS +#if defined (DONT_REPORT_SIGPIPE) + && WTERMSIG (p->status) != SIGPIPE +#endif + ) + { + fail = WSTATUS(p->status); + } p = p->next; } while (p != jobs[job]->pipe);Makes it useful for something like the git test suite.
Under this test mode we only tests we need to skip those tests which are explicitly testing that a piped command returned SIGPIPE. Those tests will now return 0 instead of an exit code indicating SIGPIPE.
Forcing the mode to run under vanilla bash with "GIT_TEST_PIPEFAIL=true" doesn't fail any tests for me, except the test in
t0000-basic.shwhich explicitly checks for the desired pipefail semantics. However, as Jeff noted in [3] that absence of failure isn't reliable. I might not see some of the failures due to the racy nature of how vanilla "set -o pipefail" interacts with *nix pipe semantics.1.
a378fee5b0(Documentation: add shell guidelines, 2018-10-05)
2. https://lore.kernel.org/git/[email protected]/
3. https://lore.kernel.org/git/[email protected]/
4. https://github.com/bminor/bash/compare/master...avar:avar/ignore-sigterm-and-sigpipe-on-pipe-failSigned-off-by Ævar Arnfjörð Bjarmason <[email protected]>t/test-lib.sh +1
-0@@ -36,6 +36,31 @@ then fi GIT_BUILD_DIR="$TEST_DIRECTORY"/.. +# Does "set -o pipefail" on this bash version handle SIGPIPE? Use it!
t/test-lib.sh then · line 49
Quoted 10 lines
t/test-lib.sh +10
-0+. "$TEST_DIRECTORY/lib-bash-detection.sh" +GIT_TEST_PIPEFAIL_TRUE= +GIT_TEST_PIPEFAIL_DEFAULT=false +if test -n "$TEST_SH_IS_BIN_BASH" && + $BASH -c 'set -eo pipefail; yes | head -n 1 >/dev/null' +then + GIT_TEST_PIPEFAIL_DEFAULT=true +fi +# We're too early for test_bool_env +if git env--helper --type=bool --default="$GIT_TEST_PIPEFAIL_DEFAULT" \
We're too early to invoke 'git' like this, period.
At this point PATH has not yet been set up to include the 'git' binary we are testing, and we can't rely on a recent enough 'git' supporting 'env--helper' to be present in the regular PATH, or that any 'git' is present in PATH at all. And indeed we have CI jobs whose output with this patch now looks like this:
*** prove ***
t5401-update-hooks.sh: ./test-lib.sh: line 49: git: not found t9001-send-email.sh: ./test-lib.sh: line 49: git: not found t5608-clone-2gb.sh: ./test-lib.sh: line 49: git: not found
[22:05:24] t9001-send-email.sh ................................ ok 58390 ms ( 0.06 usr 0.00 sys + 27.37 cusr 7.49 csys = 34.92 CPU)
t2013-checkout-submodule.sh: ./test-lib.sh: line 49: git: not found
[22:05:34] t2013-checkout-submodule.sh ........................ ok 9412 ms ( 0.03 usr 0.01 sys + 5.68 cusr 3.00 csys = 8.72 CPU)
t0027-auto-crlf.sh: ./test-lib.sh: line 49: git: not found
Quoted 31 lines
t/test-lib.sh +18
-0+ --exit-code GIT_TEST_PIPEFAIL +then + set -o pipefail + + # Only "set -o pipefail" in the main test scripts, not any + # sub-programs we spawn. + GIT_TEST_PIPEFAIL= + export GIT_TEST_PIPEFAIL + + # For the convenience of the prereq for it. + GIT_TEST_PIPEFAIL_TRUE=true + export GIT_TEST_PIPEFAIL_TRUE +fi + # If we were built with ASAN, it may complain about leaks # of program-lifetime variables. Disable it by default to lower # the noise level. This needs to happen at the start of the script,@@ -1552,6 +1577,10 @@ test_lazy_prereq PIPE ' rm -f testfifo && mkfifo testfifo ' +test_lazy_prereq BASH_SET_O_PIPEFAIL ' + test -n "$GIT_TEST_PIPEFAIL_TRUE" +' + test_lazy_prereq SYMLINKS ' # test whether the filesystem supports symbolic links ln -s x y && test -h ySignature · 1 line
2.29.2.222.g5d2a92d10f8
Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash
In reply to Ævar Arnfjörð Bjarmasont/t0005-signals.sh test_expect_success 'create blob' ' · line 51
Quoted 11 lines · Ævar Arnfjörð Bjarmason
t/t0005-signals.sh +2
-2-test_expect_success !MINGW 'a constipated git dies with SIGPIPE' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE' ' OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" ' -test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE even if parent ignores it' ' OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" '
The above have already !MINGW
Quoted 5 lines
t/t3600-rm.sh +0
-0
t/t3600-rm.sh test_expect_success 'choking "git rm" should not let it die with cruft' ' · line 259
Quoted 10 lines
t/t3600-rm.sh +4
-1@@ -251,7 +251,10 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' i=$(( $i + 1 )) done | git update-index --index-info && OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && - test_match_signal 13 "$OUT" && + if ! test_have_prereq BASH_SET_O_PIPEFAIL + then + test_match_signal 13 "$OUT" + fi && test_path_is_missing .git/index.lock '
but this one does not. Yet, we've been using test_match_signal on 13 without issues, it appears.
And somehow with the lazy prereq on SET_O_PIPEFAIL, this part starts to break, like so:
https://github.com/git/git/runs/1752687552?check_suite_focus=true#step:7:37042
The output captured in OUT is 0 as we can see on #37032 in the test log.
I am tempted to eject 11/11 and probably 10/11 out of the topic, as the earlier patches before them look more or less uncontroversial cleanups, and 11/11 seems to be more trouble than it is worth at this moment.
It's not like this would allow us to loosen the rule that we shouldn't put a "git" invocation of the git subcommand being tested on the upstream side of a pipe---not everybody is running bash, and it is unrealistic to tell our developers "if you want to make sure your tests are good, you must install and use this patched bash".
Thanks.
Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash
Quoted 22 lines · Junio C Hamano
...
The above have already !MINGWQuoted 5 lines
t/t3600-rm.sh +0
-0t/t3600-rm.sh test_expect_success 'choking "git rm" should not let it die with cruft' ' · line 259
Quoted 10 lines
t/t3600-rm.sh +4
-1@@ -251,7 +251,10 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' i=$(( $i + 1 )) done | git update-index --index-info && OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && - test_match_signal 13 "$OUT" && + if ! test_have_prereq BASH_SET_O_PIPEFAIL + then + test_match_signal 13 "$OUT" + fi && test_path_is_missing .git/index.lock 'but this one does not. Yet, we've been using
test_match_signalon 13 without issues, it appears.
Quoted 7 lines
And somehow with the lazy prereq on
SET_O_PIPEFAIL, this part starts to break, like so:https://github.com/git/git/runs/1752687552?check_suite_focus=true#step:7:37042
The output captured in OUT is 0 as we can see on #37032 in the test log.
Nah, it seems that t3600-rm's "match signal 13" is already broken without O_PIPEFAIL patch on Windows. For example:
https://github.com/git/git/runs/1753231308?check_suite_focus=true#step:7:36912
This was introduced by c15ffae5 (rm tests: actually test for SIGPIPE in SIGPIPE test, 2021-01-16) in the same series.
I am not sure "actually testing for SIGPIPE" is more important than "make sure 'git rm' choked should not die with cruft", so without thinking too deeply about the issue, my gut reaction is that reverting is better than using !MINGW as other tests. That is, no matter how "git rm" gets killed, it should not leave .git/index.lock behind, and the original already tests that. The patch tried to make sure it dies with signal #13 (and fails the test on Windows) before it even looks at the leftover index.lock file, which feels a bit backwards.
Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash
Quoted 32 lines · Junio C Hamano
Quoted 22 lines · Junio C Hamano
...
The above have already !MINGWQuoted 5 lines
t/t3600-rm.sh +0
-0t/t3600-rm.sh test_expect_success 'choking "git rm" should not let it die with cruft' ' · line 259
Quoted 10 lines
t/t3600-rm.sh +4
-1@@ -251,7 +251,10 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' i=$(( $i + 1 )) done | git update-index --index-info && OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && - test_match_signal 13 "$OUT" && + if ! test_have_prereq BASH_SET_O_PIPEFAIL + then + test_match_signal 13 "$OUT" + fi && test_path_is_missing .git/index.lock 'but this one does not. Yet, we've been using
test_match_signalon 13 without issues, it appears.Quoted 7 lines
And somehow with the lazy prereq on
SET_O_PIPEFAIL, this part starts to break, like so:https://github.com/git/git/runs/1752687552?check_suite_focus=true#step:7:37042
The output captured in OUT is 0 as we can see on #37032 in the test log.
Quoted 7 lines
Nah, it seems that t3600-rm's "match signal 13" is already broken without
O_PIPEFAILpatch on Windows. For example:https://github.com/git/git/runs/1753231308?check_suite_focus=true#step:7:36912
This was introduced by
c15ffae5(rm tests: actually test for SIGPIPE in SIGPIPE test, 2021-01-16) in the same series.
Yes, not adding !MINGW here is a stupid oversight on my part, I can re-roll with that added, which seems to be like it'll work & be better. I.e. we'll actually test for SIGPIPE ...(read on)....
Quoted 6 lines
I am not sure "actually testing for SIGPIPE" is more important than "make sure 'git rm' choked should not die with cruft", so without thinking too deeply about the issue, my gut reaction is that reverting is better than using !MINGW as other tests. That is, no matter how "git rm" gets killed, it should not leave .git/index.lock behind, and the original already tests that.
I don't get it. I understand why we'd do any of:
1. Keep my patch with !MINGW added. I.e. the intent of your 0693f9ddad (Make sure lockfiles are unlocked when dying on SIGPIPE, 2008-12-18) which added the test is to explicitly stress SIGPIPE, but we never actually checked it explicitly...
2. Just remove/rewrite that part of the test. We have 7559a1be8a (unblock and unignore SIGPIPE, 2014-09-18) (the other test whose pattern I copied) now.
That along with 12e0437f23 (common-main: call restore_sigpipe_to_default(), 2016-07-01) means we do this everywhere, so why test "git rm" in particular in this one place but not other git commands?
3. Remove the overly specific PIPE test added in 7559a1be8a in favor of this "git rm" test. After all if we want to test the SIGPIPE pattern but sometimes we get SIGPIPE, sometimes we don't (MINGW), but we don't really care because we assume on some platforms it's being tested.
But not why we'd keep the test as-is now that we've dug up this old code and found that since it got added we have a reliable way to test for actually-sigpipe.
Just to maintain the coverage on MINGW? Wouldn't it be better to have two tests then, one without the prereq to run everywhere, and another identical one with the "trap" on !MINGW?
I don't really care and can re-roll in whatever way you prefer, I just don't understand what I'd put as a reason in the commit message(s), depending on which route we go...
Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash
In reply to Junio C HamanoQuoted 40 lines · Junio C Hamano
t/t0005-signals.sh test_expect_success 'create blob' ' · line 51
Quoted 11 lines · Ævar Arnfjörð Bjarmason
t/t0005-signals.sh +2
-2-test_expect_success !MINGW 'a constipated git dies with SIGPIPE' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE' ' OUT=$( ((large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" ' -test_expect_success !MINGW 'a constipated git dies with SIGPIPE even if parent ignores it' ' +test_expect_success !MINGW,!BASH_SET_O_PIPEFAIL 'a constipated git dies with SIGPIPE even if parent ignores it' ' OUT=$( ((trap "" PIPE; large_git; echo $? 1>&3) | :) 3>&1 ) && test_match_signal 13 "$OUT" 'The above have already !MINGW
Quoted 5 lines
t/t3600-rm.sh +0
-0t/t3600-rm.sh test_expect_success 'choking "git rm" should not let it die with cruft' ' · line 259
Quoted 10 lines
t/t3600-rm.sh +4
-1@@ -251,7 +251,10 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' i=$(( $i + 1 )) done | git update-index --index-info && OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && - test_match_signal 13 "$OUT" && + if ! test_have_prereq BASH_SET_O_PIPEFAIL + then + test_match_signal 13 "$OUT" + fi && test_path_is_missing .git/index.lock 'but this one does not. Yet, we've been using
test_match_signalon 13 without issues, it appears.And somehow with the lazy prereq on
SET_O_PIPEFAIL, this part starts to break, like so:https://github.com/git/git/runs/1752687552?check_suite_focus=true#step:7:37042
Quoted 7 lines
The output captured in OUT is 0 as we can see on #37032 in the test log.
I am tempted to eject 11/11 and probably 10/11 out of the topic, as the earlier patches before them look more or less uncontroversial cleanups, and 11/11 seems to be more trouble than it is worth at this moment.
I think that makes sense, once I fix the breakage on 07/11 you noted downthread.
Quoted 3 lines
It's not like this would allow us to loosen the rule that we shouldn't put a "git" invocation of the git subcommand being tested on the upstream side of a pipe[...]
FWIW it seems from my off-list discussion with the bash maintainer that no version of my patch is likely to make it into bash. He views it as a feature that "pipefail" treats all non-zero exit codes equally.
But as it pertains to our test suite I mainly wrote this to check if we had any failures that didn't make sense once SIGPIPE was ignored. I think smoking out any potential historical cases (and finding we didn't have any that mattered) was probably an effort worth it in itself. Then we just have to continue not putting git on the LHS on a pipe for new tests.
Quoted 3 lines
[...]---not everybody is running bash, and it is unrealistic to tell our developers "if you want to make sure your tests are good, you must install and use this patched bash".
I think if others think this was worth keeping and bash never accepted the patches we could rather easily get most of the benefit from it by having a CI job that ran with such a patched bash. To test with "set -o pipefail" it's enough that it's done semi-regularly by someone if you want to smoke out bugs in the tests, not everyone has to do it all the time.
v3 cover Miscellaneous "set -o pipefail"-related test cleanups
In reply to Ævar Arnfjörð BjarmasonThis started as an attempt to add a bash "set -o pipefail" test mode, but now comes without that. Junio suggested dropping it in <[email protected]>.
The "cache-tree tests" part is mostly rewritten. I'd removed the index dependency of the tests, but the point of the tests is to test the index. Now we do that again in a more readable way.
The "git rm" test at the end fixes the current CI failure in this topic, and does some version of what I suggested in <[email protected]>. Junio, I think that makes sense as a fix while we're at it, but if you don't like it just drop it.
Jeff King (1):
git-svn tests: rewrite brittle tests to use "--[no-]merges".
Ævar Arnfjörð Bjarmason (9):
cache-tree tests: refactor for modern test style cache-tree tests: remove unused $2 parameter
cache-tree tests: use a sub-shell with less indirection cache-tree tests: explicitly test HEAD and index differences git svn mergeinfo tests: modernize redirection & quoting style git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty upload-pack tests: avoid a non-zero "grep" exit status archive tests: use a cheaper "zipinfo -h" invocation to get header rm tests: actually test for SIGPIPE in SIGPIPE test
t/t0090-cache-tree.sh | 82 +++++++++++++++--------------- t/t3600-rm.sh | 16 +++++- t/t5004-archive-corner-cases.sh | 3 +- t/t5703-upload-pack-ref-in-want.sh | 3 +- t/t9151-svn-mergeinfo.sh | 43 ++++++++-------- 5 files changed, 80 insertions(+), 67 deletions(-)
Range-diff:
-: ---------- > 1: b30499c4e4 cache-tree tests: refactor for modern test style
1: 8e8e03fa3d = 2: af0b25a048 cache-tree tests: remove unused $2 parameter
2: 828d25533c ! 3: 09959568de cache-tree tests: use a sub-shell with less indirection
@@ Commit message
We did actually recover correctly if we failed in this function since
we were wrapped in a subshell one function call up. Let's just use the
sub-shell at the point where we want to change the directory
- instead. This also allows us to get rid of the wrapper function.
+ instead.
+
+ It's important that the "|| return 1" is outside the
+ subshell. Normally, we `exit 1` from within subshells[1], but that
+ wouldn't help us exit this loop early[1][2].
+
+ Since we can get rid of the wrapper function let's rename the main
+ function to drop the "rec" (for "recursion") suffix[3].
+
+ 1. https://lore.kernel.org/git/CAPig+cToj8nQmyBCqC1k7DXF2vXaonCEA-fCJ4x7JBZG2ixYBw@mail.gmail.com/
+ 2. https://lore.kernel.org/git/[email protected]/
+ 3. https://lore.kernel.org/git/[email protected]/
Signed-off-by: Ævar Arnfjörð Bjarmason <[email protected]>
## t/t0090-cache-tree.sh ##
+@@ t/t0090-cache-tree.sh: cmp_cache_tree () {
+ # We don't bother with actually checking the SHA1:
+ # test-tool dump-cache-tree already verifies that all existing data is
+ # correct.
+-generate_expected_cache_tree_rec () {
++generate_expected_cache_tree () {
+ dir="$1${1:+/}" &&
+ # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
+ # We want to count only foo because it's the only direct child
@@ t/t0090-cache-tree.sh: generate_expected_cache_tree_rec () {
printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
for subtree in $subtrees
@@ t/t0090-cache-tree.sh: generate_expected_cache_tree_rec () {
- generate_expected_cache_tree_rec "$dir$subtree" || return 1
- cd ..
+ (
-+ cd "$subtree"
-+ generate_expected_cache_tree_rec "$dir$subtree" || return 1
-+ )
++ cd "$subtree" &&
++ generate_expected_cache_tree "$dir$subtree"
++ ) || return 1
done
}
@@ t/t0090-cache-tree.sh: generate_expected_cache_tree_rec () {
-}
-
test_cache_tree () {
-- generate_expected_cache_tree >expect &&
-+ generate_expected_cache_tree_rec >expect &&
+ generate_expected_cache_tree >expect &&
cmp_cache_tree expect
- }
- 3: fefdc570a5 ! 4: 697b0084fd cache-tree tests: refactor overly complex function
@@ Metadata
Author: Ævar Arnfjörð Bjarmason <[email protected]>
## Commit message ##
- cache-tree tests: refactor overly complex function
+ cache-tree tests: explicitly test HEAD and index differences
- Refactor overly complex code added in 9c4d6c0297 (cache-tree: Write
- updated cache-tree after commit, 2014-07-13).
+ The test code added in 9c4d6c0297 (cache-tree: Write updated
+ cache-tree after commit, 2014-07-13) used "ls-files" in lieu of
+ "ls-tree" because it wanted to test the data in the index, since this
+ test is testing the cache-tree extension.
- Interestingly, in the numerous commits[1][2][3] who fixed commits bugs
- in this code since its introduction it seems not to have been noticed
- that we didn't need to be doing some dance with grep/cut/uniq/awk to
- extract this information. It can be done in a much simpler way with
- just "ls-tree" and "wc -l".
+ Change the test to instead use "ls-tree" for traversal, and then
+ explicitly check how HEAD differs from the index. This is more easily
+ understood, and less fragile as numerous past bug fixes[1][2][3] to
+ the old code we're replacing demonstrate.
- I'm also removing the comment, because I think now that this code is
- trivial to understand it's not needed anymore.
+ As an aside this would be a bit easier if empty pathspecs hadn't been
+ made an error in d426430e6e (pathspec: warn on empty strings as
+ pathspec, 2016-06-22) and 9e4e8a64c2 (pathspec: die on empty strings
+ as pathspec, 2017-06-06).
+
+ If that was still allowed this code could be simplified slightly:
+
+ diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
+ index 9bf66c9e68..0b02881f55 100755
+ --- a/t/t0090-cache-tree.sh
+ +++ b/t/t0090-cache-tree.sh
+ @@ -18,19 +18,18 @@ cmp_cache_tree () {
+ # test-tool dump-cache-tree already verifies that all existing data is
+ # correct.
+ generate_expected_cache_tree () {
+ - pathspec="$1" &&
+ - dir="$2${2:+/}" &&
+ + pathspec="$1${1:+/}" &&
+ git ls-tree --name-only HEAD -- "$pathspec" >files &&
+ git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees &&
+ - printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) &&
+ + printf "SHA %s (%d entries, %d subtrees)\n" "$pathspec" $(wc -l <files) $(wc -l <subtrees) &&
+ while read subtree
+ do
+ - generate_expected_cache_tree "$pathspec/$subtree/" "$subtree" || return 1
+ + generate_expected_cache_tree "$subtree" || return 1
+ done <subtrees
+ }
+
+ test_cache_tree () {
+ - generate_expected_cache_tree "." >expect &&
+ + generate_expected_cache_tree >expect &&
+ cmp_cache_tree expect &&
+ rm expect actual files subtrees &&
+ git status --porcelain -- ':!status' ':!expected.status' >status &&
1. c8db708d5d (t0090: avoid passing empty string to printf %d, 2014-09-30)
@@ Commit message
## t/t0090-cache-tree.sh ##
@@ t/t0090-cache-tree.sh: cmp_cache_tree () {
+ # test-tool dump-cache-tree already verifies that all existing data is # correct.
- generate_expected_cache_tree_rec () {
- dir="$1${1:+/}" &&
+ generate_expected_cache_tree () {
+- dir="$1${1:+/}" &&
- # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux
- # We want to count only foo because it's the only direct child
- git ls-files >files &&
@@ t/t0090-cache-tree.sh: cmp_cache_tree () {
- entries=$(wc -l <files) &&
- printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" &&
- for subtree in $subtrees
-+ git ls-tree --name-only HEAD >files &&
-+ git ls-tree --name-only -d HEAD >subtrees &&
++ pathspec="$1" &&
++ dir="$2${2:+/}" &&
++ git ls-tree --name-only HEAD -- "$pathspec" >files &&
++ git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees &&
+ printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) &&
+ while read subtree
do
- (
- cd "$subtree"
-- generate_expected_cache_tree_rec "$dir$subtree" || return 1
-+ generate_expected_cache_tree_rec "$subtree" || return 1
- )
+- (
+- cd "$subtree" &&
+- generate_expected_cache_tree "$dir$subtree"
+- ) || return 1
- done
++ generate_expected_cache_tree "$pathspec/$subtree/" "$subtree" || return 1
+ done <subtrees
}
test_cache_tree () {
+- generate_expected_cache_tree >expect &&
+- cmp_cache_tree expect
++ generate_expected_cache_tree "." >expect &&
++ cmp_cache_tree expect &&
++ rm expect actual files subtrees &&
++ git status --porcelain -- ':!status' ':!expected.status' >status &&
++ if test -n "$1"
++ then
++ test_cmp "$1" status
++ else
++ test_must_be_empty status
++ fi
+ }
+
+ test_invalid_cache_tree () {
+@@ t/t0090-cache-tree.sh: test_expect_success 'second commit has cache-tree' '
+ '
+
+ test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' '
++ test_when_finished "git reset --hard" &&
+ cat <<-\EOT >foo.c &&
+ int foo()
+ {
+@@ t/t0090-cache-tree.sh: test_expect_success PERL 'commit --interactive gives cache-tree on partial commi
+ EOT
+ test_write_lines p 1 "" s n y q |
+ git commit --interactive -m foo &&
+- test_cache_tree
++ cat <<-\EOF >expected.status &&
++ M foo.c
++ EOF
++ test_cache_tree expected.status
+ '
+
+ test_expect_success PERL 'commit -p with shrinking cache-tree' '
+@@ t/t0090-cache-tree.sh: test_expect_success 'partial commit gives cache-tree' '
+ git add one.t &&
+ echo "some other change" >two.t &&
+ git commit two.t -m partial &&
+- test_cache_tree
++ cat <<-\EOF >expected.status &&
++ M one.t
++ EOF
++ test_cache_tree expected.status
+ '
+
+ test_expect_success 'no phantom error when switching trees' '
4: a16938e58d = 5: 5ede74a1ab git svn mergeinfo tests: modernize redirection & quoting style 5: b520656240 = 6: c287f5a24a git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty 6: f2e70ac911 ! 7: 9bd6ad6e25 git-svn tests: rewrite brittle tests to use "--[no-]merges".
@@ Commit message
to figure out if a set of commits turned into merge commits or not.
+ [ÆAB: wrote commit message]
- Commit-message-by: Ævar Arnfjörð Bjarmason <[email protected]>
## t/t9151-svn-mergeinfo.sh ##
@@ t/t9151-svn-mergeinfo.sh: test_expect_success 'load svn dump' "
7: dcf001e165 < -: ---------- rm tests: actually test for SIGPIPE in SIGPIPE test 8: 2212fa65eb ! 8: fd40e818a7 upload-pack tests: avoid a non-zero "grep" exit status
@@ Commit message
upload-pack tests: avoid a non-zero "grep" exit status
Continue changing a test that 763b47bafa (t5703: stop losing return
- codes of git commands, 2019-11-27) already refactored. A follow-up
- commit will add support for testing under bash's "set -o pipefail",
- under that mode this test will fail because sometimes there's no
- commits in the "objs" output.
+ codes of git commands, 2019-11-27) already refactored.
- It's easier to just fix this than to exempt these tests under a
- soon-to-be added "set -o pipefail" test mode. So let's do that.
+ This was originally added as part of a series to add support for
+ running under bash's "set -o pipefail", under that mode this test will
+ fail because sometimes there's no commits in the "objs" output.
+
+ It's easier to fix that than exempt these tests under a hypothetical
+ "set -o pipefail" test mode. It looks like we probably won't have
+ that, but once we've dug this code up let's refactor it[2] so we don't
+ hide a potential pipe failure.
+
+ 1. https://lore.kernel.org/git/[email protected]/
@@ t/t5703-upload-pack-ref-in-want.sh: get_actual_commits () {
git index-pack o.pack &&
git verify-pack -v o.idx >objs &&
- grep commit objs | cut -d" " -f1 | sort >actual_commits
-+ >actual_commits &&
-+ if grep -q commit objs
-+ then
-+ grep commit objs | cut -d" " -f1 | sort >actual_commits
-+ fi
++ sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs >objs.sed &&
++ sort >actual_commits <objs.sed
}
check_output () {
9: 8167c2e346 = 9: 5405062665 archive tests: use a cheaper "zipinfo -h" invocation to get header 10: 30c454ae7c < -: ---------- tests: split up bash detection library 11: 6f290f850c < -: ---------- tests: add a "set -o pipefail" for a patched bash -: ---------- > 10: b526b3cb24 rm tests: actually test for SIGPIPE in SIGPIPE test
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 1/10 cache-tree tests: refactor for modern test style
In reply to Ævar Arnfjörð BjarmasonRefactor the cache-tree test file to use our current recommended patterns. This makes a subsequent meaningful change easier to read.
--- t/t0090-cache-tree.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-)
t/t0090-cache-tree.sh +14 -14
@@ -10,7 +10,8 @@ cache-tree extension. cmp_cache_tree () { test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual && sed "s/$OID_REGEX/SHA/" <actual >filtered && - test_cmp "$1" filtered + test_cmp "$1" filtered && + rm filtered } # We don't bother with actually checking the SHA1:
@@ -54,7 +55,7 @@ test_invalid_cache_tree () { } test_no_cache_tree () { - : >expect && + >expect && cmp_cache_tree expect }
@@ -83,18 +84,6 @@ test_expect_success 'git-add in subdir invalidates cache-tree' ' test_invalid_cache_tree ' -cat >before <<\EOF -SHA (3 entries, 2 subtrees) -SHA dir1/ (1 entries, 0 subtrees) -SHA dir2/ (1 entries, 0 subtrees) -EOF - -cat >expect <<\EOF -invalid (2 subtrees) -invalid dir1/ (0 subtrees) -SHA dir2/ (1 entries, 0 subtrees) -EOF - test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' git tag no-children && test_when_finished "git reset --hard no-children; git read-tree HEAD" &&
@@ -102,9 +91,20 @@ test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' test_commit dir1/a && test_commit dir2/b && echo "I changed this file" >dir1/a && + test_when_finished "rm before" && + cat >before <<-\EOF && + SHA (3 entries, 2 subtrees) + SHA dir1/ (1 entries, 0 subtrees) + SHA dir2/ (1 entries, 0 subtrees) + EOF cmp_cache_tree before && echo "I changed this file" >dir1/a && git add dir1/a && + cat >expect <<-\EOF && + invalid (2 subtrees) + invalid dir1/ (0 subtrees) + SHA dir2/ (1 entries, 0 subtrees) + EOF cmp_cache_tree expect '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 2/10 cache-tree tests: remove unused $2 parameter
In reply to Ævar Arnfjörð BjarmasonRemove the $2 paramater. This appears to have been some work-in-progress code from an earlier version of 9c4d6c0297 (cache-tree: Write updated cache-tree after commit, 2014-07-13) which was left in the final version.
--- t/t0090-cache-tree.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
t/t0090-cache-tree.sh +2 -4
@@ -19,7 +19,6 @@ cmp_cache_tree () { # correct. generate_expected_cache_tree_rec () { dir="$1${1:+/}" && - parent="$2" && # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux # We want to count only foo because it's the only direct child git ls-files >files &&
@@ -30,10 +29,9 @@ generate_expected_cache_tree_rec () { for subtree in $subtrees do cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" "$dir" || return 1 + generate_expected_cache_tree_rec "$dir$subtree" || return 1 cd .. - done && - dir=$parent + done } generate_expected_cache_tree () {
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 3/10 cache-tree tests: use a sub-shell with less indirection
In reply to Ævar Arnfjörð BjarmasonChange a "cd xyz && work && cd .." pattern introduced in 9c4d6c0297 (cache-tree: Write updated cache-tree after commit, 2014-07-13) to use a sub-shell instead with less indirection.
We did actually recover correctly if we failed in this function since we were wrapped in a subshell one function call up. Let's just use the sub-shell at the point where we want to change the directory instead.
It's important that the "|| return 1" is outside the subshell. Normally, we exit 1 from within subshells[1], but that wouldn't help us exit this loop early[1][2].
Since we can get rid of the wrapper function let's rename the main function to drop the "rec" (for "recursion") suffix[3].
1. https://lore.kernel.org/git/CAPig+cToj8nQmyBCqC1k7DXF2vXaonCEA-fCJ4x7JBZG2ixYBw@mail.gmail.com/
2. https://lore.kernel.org/git/[email protected]/
3. https://lore.kernel.org/git/[email protected]/
--- t/t0090-cache-tree.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-)
t/t0090-cache-tree.sh +5 -10
@@ -17,7 +17,7 @@ cmp_cache_tree () { # We don't bother with actually checking the SHA1: # test-tool dump-cache-tree already verifies that all existing data is # correct. -generate_expected_cache_tree_rec () { +generate_expected_cache_tree () { dir="$1${1:+/}" && # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux # We want to count only foo because it's the only direct child
@@ -28,18 +28,13 @@ generate_expected_cache_tree_rec () { printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && for subtree in $subtrees do - cd "$subtree" - generate_expected_cache_tree_rec "$dir$subtree" || return 1 - cd .. + ( + cd "$subtree" && + generate_expected_cache_tree "$dir$subtree" + ) || return 1 done } -generate_expected_cache_tree () { - ( - generate_expected_cache_tree_rec - ) -} - test_cache_tree () { generate_expected_cache_tree >expect && cmp_cache_tree expect
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 4/10 cache-tree tests: explicitly test HEAD and index differences
In reply to Ævar Arnfjörð BjarmasonThe test code added in 9c4d6c0297 (cache-tree: Write updated cache-tree after commit, 2014-07-13) used "ls-files" in lieu of "ls-tree" because it wanted to test the data in the index, since this test is testing the cache-tree extension.
Change the test to instead use "ls-tree" for traversal, and then explicitly check how HEAD differs from the index. This is more easily understood, and less fragile as numerous past bug fixes[1][2][3] to the old code we're replacing demonstrate.
As an aside this would be a bit easier if empty pathspecs hadn't been made an error in d426430e6e (pathspec: warn on empty strings as pathspec, 2016-06-22) and 9e4e8a64c2 (pathspec: die on empty strings as pathspec, 2017-06-06).
If that was still allowed this code could be simplified slightly:
diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh
index 9bf66c9e68..0b02881f55 100755
--- a/t/t0090-cache-tree.sh
+++ b/t/t0090-cache-tree.sh
@@ -18,19 +18,18 @@ cmp_cache_tree () {
# test-tool dump-cache-tree already verifies that all existing data is
# correct.
generate_expected_cache_tree () {
- pathspec="$1" &&
- dir="$2${2:+/}" &&
+ pathspec="$1${1:+/}" &&
git ls-tree --name-only HEAD -- "$pathspec" >files &&
git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees &&
- printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) &&
+ printf "SHA %s (%d entries, %d subtrees)\n" "$pathspec" $(wc -l <files) $(wc -l <subtrees) &&
while read subtree
do
- generate_expected_cache_tree "$pathspec/$subtree/" "$subtree" || return 1
+ generate_expected_cache_tree "$subtree" || return 1
done <subtrees
}
test_cache_tree () {
- generate_expected_cache_tree "." >expect &&
+ generate_expected_cache_tree >expect &&
cmp_cache_tree expect &&
rm expect actual files subtrees &&
git status --porcelain -- ':!status' ':!expected.status' >status &&1. c8db708d5d (t0090: avoid passing empty string to printf %d, 2014-09-30)
2. d69360c6b1 (t0090: tweak awk statement for Solaris /usr/xpg4/bin/awk, 2014-12-22)
3. 9b5a9fa60a (t0090: stop losing return codes of git commands, 2019-11-27)
--- t/t0090-cache-tree.sh | 45 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-)
t/t0090-cache-tree.sh +27 -18
@@ -18,26 +18,28 @@ cmp_cache_tree () { # test-tool dump-cache-tree already verifies that all existing data is # correct. generate_expected_cache_tree () { - dir="$1${1:+/}" && - # ls-files might have foo/bar, foo/bar/baz, and foo/bar/quux - # We want to count only foo because it's the only direct child - git ls-files >files && - subtrees=$(grep / files|cut -d / -f 1|uniq) && - subtree_count=$(echo "$subtrees"|awk -v c=0 '$1 != "" {++c} END {print c}') && - entries=$(wc -l <files) && - printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && - for subtree in $subtrees + pathspec="$1" && + dir="$2${2:+/}" && + git ls-tree --name-only HEAD -- "$pathspec" >files && + git ls-tree --name-only -d HEAD -- "$pathspec" >subtrees && + printf "SHA %s (%d entries, %d subtrees)\n" "$dir" $(wc -l <files) $(wc -l <subtrees) && + while read subtree do - ( - cd "$subtree" && - generate_expected_cache_tree "$dir$subtree" - ) || return 1 - done + generate_expected_cache_tree "$pathspec/$subtree/" "$subtree" || return 1 + done <subtrees } test_cache_tree () { - generate_expected_cache_tree >expect && - cmp_cache_tree expect + generate_expected_cache_tree "." >expect && + cmp_cache_tree expect && + rm expect actual files subtrees && + git status --porcelain -- ':!status' ':!expected.status' >status && + if test -n "$1" + then + test_cmp "$1" status + else + test_must_be_empty status + fi } test_invalid_cache_tree () {
@@ -126,6 +128,7 @@ test_expect_success 'second commit has cache-tree' ' ' test_expect_success PERL 'commit --interactive gives cache-tree on partial commit' ' + test_when_finished "git reset --hard" && cat <<-\EOT >foo.c && int foo() {
@@ -152,7 +155,10 @@ test_expect_success PERL 'commit --interactive gives cache-tree on partial commi EOT test_write_lines p 1 "" s n y q | git commit --interactive -m foo && - test_cache_tree + cat <<-\EOF >expected.status && + M foo.c + EOF + test_cache_tree expected.status ' test_expect_success PERL 'commit -p with shrinking cache-tree' '
@@ -243,7 +249,10 @@ test_expect_success 'partial commit gives cache-tree' ' git add one.t && echo "some other change" >two.t && git commit two.t -m partial && - test_cache_tree + cat <<-\EOF >expected.status && + M one.t + EOF + test_cache_tree expected.status ' test_expect_success 'no phantom error when switching trees' '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 5/10 git svn mergeinfo tests: modernize redirection & quoting style
In reply to Ævar Arnfjörð BjarmasonUse "<file" instead of "< file", and don't put the closing quote for strings on an indented line. This makes a follow-up refactoring commit easier to read.
--- t/t9151-svn-mergeinfo.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-)
t/t9151-svn-mergeinfo.sh +8 -8
@@ -9,37 +9,37 @@ test_description='git-svn svn mergeinfo properties' test_expect_success 'load svn dump' " svnadmin load -q '$rawsvnrepo' \ - < '$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' && + <'$TEST_DIRECTORY/t9151/svn-mergeinfo.dump' && git svn init --minimize-url -R svnmerge \ --rewrite-root=http://svn.example.org \ -T trunk -b branches '$svnrepo' && git svn fetch --all - " +" test_expect_success 'all svn merges became git merge commits' ' unmarked=$(git rev-list --parents --all --grep=Merge | grep -v " .* " | cut -f1 -d" ") && [ -z "$unmarked" ] - ' +' test_expect_success 'cherry picks did not become git merge commits' ' bad_cherries=$(git rev-list --parents --all --grep=Cherry | grep " .* " | cut -f1 -d" ") && [ -z "$bad_cherries" ] - ' +' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' bad_non_merges=$(git rev-list --parents --all --grep=non-merge | grep " .* " | cut -f1 -d" ") && [ -z "$bad_non_merges" ] - ' +' test_expect_success 'commit made to merged branch is reachable from the merge' ' before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") && merge_commit=$(git rev-list --all --grep="Merge trunk to b2") && not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) && [ -z "$not_reachable" ] - ' +' test_expect_success 'merging two branches in one commit is detected correctly' ' f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") &&
@@ -47,11 +47,11 @@ test_expect_success 'merging two branches in one commit is detected correctly' ' merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") && not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) && [ -z "$not_reachable" ] - ' +' test_expect_failure 'everything got merged in the end' ' unmerged=$(git rev-list --all --not master) && [ -z "$unmerged" ] - ' +' test_done
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 6/10 git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty
In reply to Ævar Arnfjörð BjarmasonRefactor some old-style test code to use test_must_be_empty instead of "test -z". This makes a follow-up commit easier to read.
--- t/t9151-svn-mergeinfo.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-)
t/t9151-svn-mergeinfo.sh +16 -15
@@ -17,41 +17,42 @@ test_expect_success 'load svn dump' " " test_expect_success 'all svn merges became git merge commits' ' - unmarked=$(git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" ") && - [ -z "$unmarked" ] + git rev-list --parents --all --grep=Merge | + grep -v " .* " | cut -f1 -d" " >unmarked && + test_must_be_empty unmarked ' + test_expect_success 'cherry picks did not become git merge commits' ' - bad_cherries=$(git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" ") && - [ -z "$bad_cherries" ] + git rev-list --parents --all --grep=Cherry | + grep " .* " | cut -f1 -d" " >bad-cherries && + test_must_be_empty bad-cherries ' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' - bad_non_merges=$(git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" ") && - [ -z "$bad_non_merges" ] + git rev-list --parents --all --grep=non-merge | + grep " .* " | cut -f1 -d" " >bad-non-merges && + test_must_be_empty bad-non-merges ' test_expect_success 'commit made to merged branch is reachable from the merge' ' before_commit=$(git rev-list --all --grep="trunk commit before merging trunk to b2") && merge_commit=$(git rev-list --all --grep="Merge trunk to b2") && - not_reachable=$(git rev-list -1 $before_commit --not $merge_commit) && - [ -z "$not_reachable" ] + git rev-list -1 $before_commit --not $merge_commit >not-reachable && + test_must_be_empty not-reachable ' test_expect_success 'merging two branches in one commit is detected correctly' ' f1_commit=$(git rev-list --all --grep="make f1 branch from trunk") && f2_commit=$(git rev-list --all --grep="make f2 branch from trunk") && merge_commit=$(git rev-list --all --grep="Merge f1 and f2 to trunk") && - not_reachable=$(git rev-list -1 $f1_commit $f2_commit --not $merge_commit) && - [ -z "$not_reachable" ] + git rev-list -1 $f1_commit $f2_commit --not $merge_commit >not-reachable && + test_must_be_empty not-reachable ' test_expect_failure 'everything got merged in the end' ' - unmerged=$(git rev-list --all --not master) && - [ -z "$unmerged" ] + git rev-list --all --not master >unmerged && + test_must_be_empty unmerged ' test_done
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 7/10 git-svn tests: rewrite brittle tests to use "--[no-]merges".
In reply to Ævar Arnfjörð BjarmasonFrom: Jeff King <[email protected]>
Rewrite a brittle tests which used "rev-list" without "--[no-]merges" to figure out if a set of commits turned into merge commits or not.
--- t/t9151-svn-mergeinfo.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-)
t/t9151-svn-mergeinfo.sh +3 -7
@@ -17,21 +17,17 @@ test_expect_success 'load svn dump' " " test_expect_success 'all svn merges became git merge commits' ' - git rev-list --parents --all --grep=Merge | - grep -v " .* " | cut -f1 -d" " >unmarked && + git rev-list --all --no-merges --grep=Merge >unmarked && test_must_be_empty unmarked ' - test_expect_success 'cherry picks did not become git merge commits' ' - git rev-list --parents --all --grep=Cherry | - grep " .* " | cut -f1 -d" " >bad-cherries && + git rev-list --all --merges --grep=Cherry >bad-cherries && test_must_be_empty bad-cherries ' test_expect_success 'svn non-merge merge commits did not become git merge commits' ' - git rev-list --parents --all --grep=non-merge | - grep " .* " | cut -f1 -d" " >bad-non-merges && + git rev-list --all --merges --grep=non-merge >bad-non-merges && test_must_be_empty bad-non-merges '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 8/10 upload-pack tests: avoid a non-zero "grep" exit status
In reply to Ævar Arnfjörð BjarmasonContinue changing a test that 763b47bafa (t5703: stop losing return codes of git commands, 2019-11-27) already refactored.
This was originally added as part of a series to add support for running under bash's "set -o pipefail", under that mode this test will fail because sometimes there's no commits in the "objs" output.
It's easier to fix that than exempt these tests under a hypothetical "set -o pipefail" test mode. It looks like we probably won't have that, but once we've dug this code up let's refactor it[2] so we don't hide a potential pipe failure.
1. https://lore.kernel.org/git/[email protected]/
--- t/t5703-upload-pack-ref-in-want.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/t5703-upload-pack-ref-in-want.sh +2 -1
@@ -16,7 +16,8 @@ get_actual_commits () { test-tool pkt-line unpack-sideband <out >o.pack && git index-pack o.pack && git verify-pack -v o.idx >objs && - grep commit objs | cut -d" " -f1 | sort >actual_commits + sed -n -e 's/\([0-9a-f][0-9a-f]*\) commit .*/\1/p' objs >objs.sed && + sort >actual_commits <objs.sed } check_output () {
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 10/10 rm tests: actually test for SIGPIPE in SIGPIPE test
In reply to Ævar Arnfjörð BjarmasonChange a test initially added in 50cd31c652 (t3600: comment on inducing SIGPIPE in git rm, 2019-11-27) to explicitly test for SIGPIPE using a pattern initially established in 7559a1be8a (unblock and unignore SIGPIPE, 2014-09-18).
The problem with using that pattern is that it requires us to skip the test on MINGW[1]. If we kept the test with its initial semantics[2] we'd get coverage there, at the cost of not checking whether we actually had SIGPIPE outside of MinGW.
Arguably we should just remove this test. Between the test added in 7559a1be8a and the change made in 12e0437f23 (common-main: call restore_sigpipe_to_default(), 2016-07-01) it's a bit arbitrary to only check this for "git rm".
But in lieu of having wider test coverage for other "git" subcommands let's refactor this to explicitly test for SIGPIPE outside of MinGW, and then just that we remove the ".git/index.lock" (as before) on all platforms.
1. https://lore.kernel.org/git/[email protected]/
2. 0693f9ddad (Make sure lockfiles are unlocked when dying on SIGPIPE, 2008-12-18)
--- t/t3600-rm.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-)
t/t3600-rm.sh +14 -2
@@ -240,7 +240,7 @@ test_expect_success 'refresh index before checking if it is up-to-date' ' test_path_is_missing frotz/nitfol ' -test_expect_success 'choking "git rm" should not let it die with cruft' ' +choke_git_rm_setup() { git reset -q --hard && test_when_finished "rm -f .git/index.lock && git reset -q --hard" && i=0 &&
@@ -249,12 +249,24 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' do echo "100644 $hash 0 some-file-$i" i=$(( $i + 1 )) - done | git update-index --index-info && + done | git update-index --index-info +} + +test_expect_success 'choking "git rm" should not let it die with cruft (induce SIGPIPE)' ' + choke_git_rm_setup && # git command is intentionally placed upstream of pipe to induce SIGPIPE git rm -n "some-file-*" | : && test_path_is_missing .git/index.lock ' + +test_expect_success !MINGW 'choking "git rm" should not let it die with cruft (induce and check SIGPIPE)' ' + choke_git_rm_setup && + OUT=$( ((trap "" PIPE; git rm -n "some-file-*"; echo $? 1>&3) | :) 3>&1 ) && + test_match_signal 13 "$OUT" && + test_path_is_missing .git/index.lock +' + test_expect_success 'Resolving by removal is not a warning-worthy event' ' git reset -q --hard && test_when_finished "rm -f .git/index.lock msg && git reset -q --hard" &&
Signature · 1 line
2.29.2.222.g5d2a92d10f8
PATCH v3 9/10 archive tests: use a cheaper "zipinfo -h" invocation to get header
In reply to Ævar Arnfjörð BjarmasonChange an invocation of zipinfo added in 19ee29401d (t5004: test ZIP archives with many entries, 2015-08-22) to simply ask zipinfo for the header info, rather than spewing out info about the entire archive and race to kill it with SIGPIPE due to the downstream "head -2".
I ran across this because I'm adding a "set -o pipefail" test mode. This won't be needed for the version of the mode that I'm introducing (which currently relies on a patch to GNU bash), but I think this is a good idea anyway.
--- t/t5004-archive-corner-cases.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/t5004-archive-corner-cases.sh +2 -1
@@ -153,7 +153,8 @@ test_expect_success ZIPINFO 'zip archive with many entries' ' # check the number of entries in the ZIP file directory expr 65536 + 256 >expect && - "$ZIPINFO" many.zip | head -2 | sed -n "2s/.* //p" >actual && + "$ZIPINFO" -h many.zip >zipinfo && + sed -n "2s/.* //p" <zipinfo >actual && test_cmp expect actual '
Signature · 1 line
2.29.2.222.g5d2a92d10f8
Re: [PATCH v3 01/10] cache-tree tests: refactor for modern test style
In reply to Ævar Arnfjörð Bjarmasont/t0090-cache-tree.sh cache-tree extension. · line 15
Quoted 12 lines · Ævar Arnfjörð Bjarmason
t/t0090-cache-tree.sh +2
-1@@ -10,7 +10,8 @@ cache-tree extension. cmp_cache_tree () { test-tool dump-cache-tree | sed -e '/#(ref)/d' >actual && sed "s/$OID_REGEX/SHA/" <actual >filtered && - test_cmp "$1" filtered + test_cmp "$1" filtered && + rm filtered }
OK. Cleaning after itself is good, and not cleaning when there is an error is probably a bit more helpful to those who debug, but I think test_cmp would give them enough to work on. A failure to remove filtered at the end CAN mistakenly make the caller to think that the expected output was not obtained, though.
Quoted 29 lines
t/t0090-cache-tree.sh +6
-12@@ -83,18 +84,6 @@ test_expect_success 'git-add in subdir invalidates cache-tree' ' test_invalid_cache_tree ' -cat >before <<\EOF -SHA (3 entries, 2 subtrees) -SHA dir1/ (1 entries, 0 subtrees) -SHA dir2/ (1 entries, 0 subtrees) -EOF - -cat >expect <<\EOF -invalid (2 subtrees) -invalid dir1/ (0 subtrees) -SHA dir2/ (1 entries, 0 subtrees) -EOF - test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' git tag no-children && test_when_finished "git reset --hard no-children; git read-tree HEAD" &&@@ -102,9 +91,20 @@ test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' test_commit dir1/a && test_commit dir2/b && echo "I changed this file" >dir1/a && + test_when_finished "rm before" && + cat >before <<-\EOF && + SHA (3 entries, 2 subtrees) + SHA dir1/ (1 entries, 0 subtrees) + SHA dir2/ (1 entries, 0 subtrees) + EOF
t/t0090-cache-tree.sh test_expect_success 'git-add in subdir does not invalidate sibling cache-tree' ' · line 109
Quoted 10 lines
t/t0090-cache-tree.sh +5
-0cmp_cache_tree before && echo "I changed this file" >dir1/a && git add dir1/a && + cat >expect <<-\EOF && + invalid (2 subtrees) + invalid dir1/ (0 subtrees) + SHA dir2/ (1 entries, 0 subtrees) + EOF cmp_cache_tree expect '
Why remove only 'before' and not 'expect' in when-finished handler?
Re: [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter
In reply to Ævar Arnfjörð BjarmasonQuoted 4 lines · Ævar Arnfjörð Bjarmason
Remove the $2 paramater. This appears to have been some work-in-progress code from an earlier version of
9c4d6c0297(cache-tree: Write updated cache-tree after commit, 2014-07-13) which was left in the final version.
Good.
Re: [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection
In reply to Ævar Arnfjörð BjarmasonQuoted 3 lines · Ævar Arnfjörð Bjarmason
Change a "cd xyz && work && cd .." pattern introduced in
9c4d6c0297(cache-tree: Write updated cache-tree after commit, 2014-07-13) to use a sub-shell instead with less indirection.
Much nicer. Pleased.