t: general test cleanup + `set -o pipefail`
cover t: general test cleanup + `set -o pipefail`
Patches 1-20 perform some general test cleanup to modernise the style. They should be relatively uncontroversial and can be merged earlier (or as a separate series) if desired. The reason these tests were identified for cleanup was because they failed under set -o pipefail.
Patches 21-27 should be considered RFC. In an attempt to catch git commands failing in the upstream of a pipe, we enable set -o pipefail on Bash. This may result in some funny-looking shell script constructs (e.g. needing to wrap grep since it may "fail") but overall, I think it is an improvement since we catch failure in more cases.
This change should be backwards compatible with shells that don't support pipefail since tests that pass under pipefail should be a subset of tests that can pass without pipefail.
I've tested these patches on Linux, MacOS and Travis[1], although I skipped CVS, SVN, Apache2 tests (and maybe others?). I'd appreciate help testing these patches on that regard.
[1]: https://travis-ci.org/Denton-L/git/builds/612133448
Denton Liu (27):
lib-bash.sh: move then onto its own line
t0014: remove git command upstream of pipe
t0090: stop losing return codes of git commands
t3301: stop losing return codes of git commands
t3600: use test_line_count() where possible
t3600: stop losing return codes of git commands
t3600: comment on inducing SIGPIPE in git rm
t4015: stop losing return codes of git commands
t4015: use test_write_lines()
t4138: stop losing return codes of git commands
t5317: stop losing return codes of git commands
t5317: use ! grep to check for no matching lines
t5703: stop losing return codes of git commands
t7501: remove spaces after redirect operators
t7501: stop losing return codes of git commands
t7700: drop redirections to /dev/null
t7700: remove spaces after redirect operators
t7700: move keywords onto their own line
t7700: s/test -f/test_path_is_file/
t7700: stop losing return codes of git commands
t: define test_grep_return_success()
t0090: mask failing grep status
t3600: mark git command as failing
t5004: ignore SIGPIPE in zipinfo
t5703: mask failing grep status
t9902: disable pipefail
t: run tests with set -o pipefail on Bash
t/README | 4 + t/lib-bash.sh | 3 +- t/t0014-alias.sh | 4 +- t/t0090-cache-tree.sh | 5 +- t/t3301-notes.sh | 230 ++++++++++++++++++------- t/t3600-rm.sh | 16 +- t/t4015-diff-whitespace.sh | 123 +++++++------ t/t4138-apply-ws-expansion.sh | 16 +- t/t5004-archive-corner-cases.sh | 4 +- t/t5317-pack-objects-filter-objects.sh | 34 ++-- t/t5703-upload-pack-ref-in-want.sh | 52 ++++-- t/t7501-commit-basic-functionality.sh | 83 +++++---- t/t7700-repack.sh | 125 ++++++++------ t/t9902-completion.sh | 6 + t/test-lib-functions.sh | 5 + t/test-lib.sh | 12 ++ 16 files changed, 458 insertions(+), 264 deletions(-)
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 1/27 lib-bash.sh: move `then` onto its own line
The code style for tests is to have statements on their own line if possible. Move the then onto its own line so that it conforms with the test style.
--- t/lib-bash.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
t/lib-bash.sh +2 -1
@@ -2,7 +2,8 @@ # to run under Bash; primarily intended for tests of the completion # script. -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then # we are in full-on bash mode true elif type bash >/dev/null 2>&1; then
Signature · 1 line
2.24.0.399.gf8350c9437
Re: [PATCH 01/27] lib-bash.sh: move `then` onto its own line
t/lib-bash.sh line 3
Quoted 11 lines · Denton Liu
The code style for tests is to have statements on their own line if possible. Move the
thenonto its own line so that it conforms with the test style.Signed-off-by Denton Liu <[email protected]>---
t/lib-bash.sh +2
-1@@ -2,7 +2,8 @@ -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then
Okay...
t/lib-bash.sh line 9
Quoted 3 lines
t/lib-bash.sh +0
-0# we are in full-on bash mode true elif type bash >/dev/null 2>&1; then
... but why not move this 'then' to its own line, as well?
Re: [PATCH 01/27] lib-bash.sh: move `then` onto its own line
Quoted 15 lines · Eric Sunshine
t/lib-bash.sh line 3
Quoted 11 lines · Denton Liu
The code style for tests is to have statements on their own line if possible. Move the
thenonto its own line so that it conforms with the test style.Signed-off-by Denton Liu <[email protected]>---
t/lib-bash.sh +2
-1@@ -2,7 +2,8 @@ -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +thenOkay...
Quoted 5 lines
t/lib-bash.sh line 9
Quoted 3 lines
t/lib-bash.sh +0
-0# we are in full-on bash mode true elif type bash >/dev/null 2>&1; then... but why not move this 'then' to its own line, as well?
Good eyes ;-)
PATCH 2/27 t0014: remove git command upstream of pipe
In reply to Denton LiuBefore, the git frotz command would fail but its return code was hidden since it was in the upstream of a pipe. Break the pipeline into two commands so that the return code is no longer lost. Also, mark git frotz with test_must_fail since it's supposed to fail.
--- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t0014-alias.sh +2 -2
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' ' #' test_expect_success 'run-command formats empty args properly' ' - GIT_TRACE=1 git frotz a "" b " " c 2>&1 | - sed -ne "/run_command:/s/.*trace: run_command: //p" >actual && + test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw && + sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual && echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect && test_cmp expect actual '
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 3/27 t0090: stop losing return codes of git commands
In reply to Denton LiuIn generate_expected_cache_tree_rec(), there are currently two instances of git ls-files in the upstream of a pipe. In the case where the upstream git command fails, its return code will be lost. Extract the git ls-files into its own call so that if it ever fails, its return code is not lost.
--- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
t/t0090-cache-tree.sh +3 -2
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () { 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 - subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && + 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=$(git ls-files|wc -l) && + entries=$(wc -l <files) && printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && for subtree in $subtrees do
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 4/27 t3301: 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.
This patch fixes a real buggy test: in 'copy note with "git notes copy"', git notes was mistyped as git note.
--- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-)
t/t3301-notes.sh +163 -67
@@ -54,7 +54,9 @@ test_expect_success 'create notes' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b4" = "$(git notes show)" && + echo b4 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b3" = "$(git notes show)" && + echo b3 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'show notes from treeish' ' - test "b3" = "$(git notes --ref commits^{tree} show)" && - test "b4" = "$(git notes --ref commits@{1} show)" + echo b3 >expect && + git notes --ref commits^{tree} show >actual && + test_cmp expect actual && + + echo b4 >expect && + git notes --ref commits@{1} show >actual && + test_cmp expect actual ' test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b3" = "$(git notes show)" && + echo b3 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b1" = "$(git notes show)" && + echo b1 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b2" = "$(git notes show)" && + echo b2 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b1" = "$(git notes show)" && + echo b1 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' ' Notes: ${indent}b1 EOF - ! (git cat-file commit HEAD | grep b1) && + git cat-file commit HEAD >commits && + ! grep b1 commits && git log -1 >actual && test_cmp expect actual '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' ' test_expect_success 'list notes with "git notes list"' ' commit_2=$(git rev-parse 2nd) && commit_3=$(git rev-parse 3rd) && + note_2=$(git rev-parse refs/notes/commits:$commit_2) && + note_3=$(git rev-parse refs/notes/commits:$commit_3) && sort -t" " -k2 >expect <<-EOF && - $(git rev-parse refs/notes/commits:$commit_2) $commit_2 - $(git rev-parse refs/notes/commits:$commit_3) $commit_3 + $note_2 $commit_2 + $note_3 $commit_3 EOF git notes list >actual && test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' ' ' test_expect_success 'list specific note with "git notes list <object>"' ' - cat >expect <<-EOF && - $(git rev-parse refs/notes/commits:$commit_3) - EOF + git rev-parse refs/notes/commits:$commit_3 >expect && git notes list HEAD^^ >actual && test_cmp expect actual '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' ' test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' commit_5=$(git rev-parse 5th) && + note_5=$(git rev-parse refs/notes/commits:$commit_5) && sort -t" " -k2 >expect_list <<-EOF && - $(git rev-parse refs/notes/commits:$commit_2) $commit_2 - $(git rev-parse refs/notes/commits:$commit_3) $commit_3 - $(git rev-parse refs/notes/commits:$commit_5) $commit_5 + $note_2 $commit_2 + $note_3 $commit_3 + $note_5 $commit_5 EOF git notes list >actual && test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' git notes show HEAD: >actual && test_cmp expect actual && echo "Note on a blob" >expect && - filename=$(git ls-tree --name-only HEAD | head -n1) && + git ls-tree --name-only HEAD >files && + filename=$(head -n1 files) && git notes add -m "Note on a blob" HEAD:$filename && git notes show HEAD:$filename >actual && test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' ' Notes: ${indent}order test EOF - git notes add -C $(git notes list HEAD^) && + note=$(git notes list HEAD^) && + git notes add -C $note && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i Notes: ${indent}This is a blob object EOF - blob=$(echo "This is a blob object" | git hash-object -w --stdin) && - git notes add -C $blob && + echo "This is a blob object" | git hash-object -w --stdin >blob && + git notes add -C $(cat blob) && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$blob" + git notes list HEAD >actual && + test_cmp blob actual ' test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' ' Notes: ${indent}yet another note EOF - MSG="yet another note" git notes add -c $(git notes list HEAD^^) && + note=$(git notes list HEAD^^) && + MSG="yet another note" git notes add -c $note && git log -1 >actual && test_cmp expect actual '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"' ${indent} ${indent}yet another note EOF - git notes append -C $(git notes list HEAD^) HEAD^ && + note=$(git notes list HEAD^) && + git notes append -C $note HEAD^ && git log -1 HEAD^ >actual && test_cmp expect actual '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' ' Notes: ${indent}other note EOF - MSG="other note" git notes append -c $(git notes list HEAD^) && + note=$(git notes list HEAD^) && + MSG="other note" git notes append -c $note && git log -1 >actual && test_cmp expect actual '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"' ${indent} ${indent}yet another note EOF - MSG="yet another note" git notes append -c $(git notes list HEAD) && + note=$(git notes list HEAD) && + MSG="yet another note" git notes append -c $note && git log -1 >actual && test_cmp expect actual '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' ' git notes copy 8th 4th && git log 3rd..4th >actual && test_cmp expect actual && - test "$(git note list 4th)" = "$(git note list 8th)" + git notes list 4th >expect && + git notes list 8th >actual && + test_cmp expect actual ' test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' ' git notes copy HEAD^ && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'prevent overwrite with "git notes copy"' ' test_must_fail git notes copy HEAD~2 HEAD && + cat >expect <<-EOF && + commit $commit + Author: A U Thor <[email protected]> + Date: Thu Apr 7 15:23:13 2005 -0700 + + ${indent}11th + + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' ' git notes copy -f HEAD~3 HEAD && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~3)" + git notes list HEAD~3 >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' ' git notes copy -f HEAD~2 && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" + git notes list HEAD~2 >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' ' ${indent} ${indent}yet another note EOF - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --stdin && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --stdin <copy && git log -2 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && - test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" + git notes list HEAD~2 >expect && + git notes list HEAD >actual && + test_cmp expect actual && + git notes list HEAD~3 >expect && + git notes list HEAD^ >actual && + test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' ${indent}14th EOF - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -2 >actual && test_cmp expect actual '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' ' EOF test_config notes.rewriteMode overwrite && test_config notes.rewriteRef "refs/notes/*" && - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -2 >actual && test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (disabled)' ' test_config notes.rewrite.bar false && - echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | - git notes copy --for-rewrite=bar && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=bar <copy && git log -2 >actual && test_cmp expect actual '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' ' git notes add -f -m"a fresh note" HEAD^ && test_config notes.rewriteMode overwrite && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' ' test_expect_success 'git notes copy --for-rewrite (ignore)' ' test_config notes.rewriteMode ignore && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' ' git notes add -f -m"another fresh note" HEAD^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' ' git notes add -f -m"append 2" HEAD^^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - (echo $(git rev-parse HEAD^) $(git rev-parse HEAD) && - echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD^^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' ' git notes remove HEAD^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && git notes add -f -m"replacement note 1" HEAD^ && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' ' git notes add -f -m"replacement note 2" HEAD^ && test_config notes.rewriteMode overwrite && test_unconfig notes.rewriteRef && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ - git notes copy --for-rewrite=foo && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' git notes add -f -m"replacement note 3" HEAD^ && test_config notes.rewriteMode overwrite && test_config notes.rewriteRef refs/notes/other && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && GIT_NOTES_REWRITE_REF=refs/notes/commits \ - git notes copy --for-rewrite=foo && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && grep "replacement note 3" actual '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' ' test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' ' test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && - test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master" + echo refs/notes/refs/heads/master >expect && + git notes --ref=refs/heads/master get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (no overrides)' ' test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && - test "$(git notes get-ref)" = "refs/notes/commits" + echo refs/notes/commits >expect && + git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (core.notesRef)' ' test_config core.notesRef refs/notes/foo && - test "$(git notes get-ref)" = "refs/notes/foo" + echo refs/notes/foo >expect && + git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' - test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" + echo refs/notes/bar >expect && + GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (--ref)' ' - test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" + echo refs/notes/baz >expect && + GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual && + test_cmp expect actual ' test_expect_success 'setup testing of empty notes' '
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 5/27 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.399.gf8350c9437
PATCH 6/27 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.399.gf8350c9437
PATCH 7/27 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.399.gf8350c9437
PATCH 8/27 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.399.gf8350c9437
PATCH 9/27 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.399.gf8350c9437
PATCH 10/27 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_must_fail 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_must_fail 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_must_fail 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_must_fail 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.399.gf8350c9437
Re: [PATCH 10/27] t4138: stop losing return codes of git commands
t/t4138-apply-ws-expansion.sh test_expect_success setup ' · line 18
Quoted 13 lines · Denton Liu
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 so that we will know if a command fails.
Signed-off-by Denton Liu <[email protected]>---
t/t4138-apply-ws-expansion.sh +2
-2@@ -17,8 +17,8 @@ test_expect_success setup ' - git diff --no-index before after | - sed -e "s/before/test-1/" -e "s/after/test-1/" >patch1.patch && + test_must_fail 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 &&
I think this is a semantically incorrect use of test_must_fail(). What you're interested here is that git-diff found differences (as opposed to not finding any), so you want to test its exit code which reflects whether or not the files were different. Hence, the following would be more appropriate:
test_expect_code 1 git diff --no-index before after >patch1.patch.raw &&
Same comment applies to remaining changes in this patch.
PATCH 11/27 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.399.gf8350c9437
PATCH 12/27 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.
--- 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.399.gf8350c9437
Re: [PATCH 12/27] t5317: use ! grep to check for no matching lines
Quoted 9 lines · Denton Liu
Several times in t5317, we would use
wc -lto 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.Signed-off-by Denton Liu <[email protected]>---
t/t5317-pack-objects-filter-objects.sh test_expect_success 'verify blob:none packfile has no blobs' ' · line 46
Quoted 8 lines
t/t5317-pack-objects-filter-objects.sh +1
-6@@ -45,12 +45,7 @@ test_expect_success 'verify blob:none packfile has no blobs' ' 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
It's curious that this and other tests were doing so much unnecessary extra work ('awk' and 'sort'). While it's clear that it's safe to drop the 'awk' and 'sed' invocations, nevertheless, as a reviewer, I had to spend extra time digging into it in order to understand why it was like this in the first place, since I wanted to convince myself that some earlier change hadn't broken the test in some unnoticed way.
It turns out that these tests were simply born this way[1], doing all this unnecessary work for no reason, probably due to copy/paste programming, and it seems no reviewer caught it. Likewise, the unnecessary work wasn't noticed even when the code was later touched for various cleanups[2,3].
To save future reviewers (and future readers of the commit history) the effort of having to convince themselves of the safety of this change, it might be a good idea to say something in the commit message about the code's history.
[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)
PATCH 13/27 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 | 52 +++++++++++++++++++----------- 1 file changed, 33 insertions(+), 19 deletions(-)
t/t5703-upload-pack-ref-in-want.sh +33 -19
@@ -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 '
@@ -312,9 +324,11 @@ inconsistency () { # repository appears to change during negotiation, for example, when # different servers in a load-balancing arrangement serve (stateless) # RPCs during a single negotiation. + oid1=$(git -C "$REPO" rev-parse $1) && + oid2=$(git -C "$REPO" rev-parse $2) && printf "s/%s/%s/" \ - $(git -C "$REPO" rev-parse $1 | tr -d "\n") \ - $(git -C "$REPO" rev-parse $2 | tr -d "\n") \ + $(echo "$oid1" | tr -d "\n") \ + $(echo "$oid2" | tr -d "\n") \ >"$HTTPD_ROOT_PATH/one-time-sed" }
Signature · 1 line
2.24.0.399.gf8350c9437
Re: [PATCH 13/27] t5703: stop losing return codes of git commands
t/t5703-upload-pack-ref-in-want.sh inconsistency () { · line 329
Quoted 12 lines · Denton Liu
Signed-off-by Denton Liu <[email protected]>---
t/t5703-upload-pack-ref-in-want.sh +4
-2@@ -312,9 +324,11 @@ inconsistency () { + oid1=$(git -C "$REPO" rev-parse $1) && + oid2=$(git -C "$REPO" rev-parse $2) && printf "s/%s/%s/" \ - $(git -C "$REPO" rev-parse $1 | tr -d "\n") \ - $(git -C "$REPO" rev-parse $2 | tr -d "\n") \ + $(echo "$oid1" | tr -d "\n") \ + $(echo "$oid2" | tr -d "\n") \ >"$HTTPD_ROOT_PATH/one-time-sed"
This code is rather odd. The $(...) substitution already takes care of stripping out newlines, so the 'tr' invocations in both the original and the revised code are superfluous. As this patch series incorporates various other cleanups, it would not be inappropriate to create a patch which removes the unnecessary 'tr' invocations preparatory to this patch. The final result should be a simple:
printf "s/%s/%s/" $oid1 $oid2 >"$HTTPD_ROOT_PATH/one-time-sed"
or even simpler:
printf "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
In fact, given the way the tests actually employ "one-time-sed" via $(cat one-time-sed) in t/lib-httpd/apply-one-time-sed.sh, it could even be as simple as:
echo "s/$oid1/$oid2/" >"$HTTPD_ROOT_PATH/one-time-sed"
which makes it consistent with the final "server loses a ref - ref in want" test, which does use 'echo' rather than 'printf'. (That change might also deserve its own patch.)
PATCH 14/27 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.399.gf8350c9437
PATCH 15/27 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.
--- 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.399.gf8350c9437
Re: [PATCH 15/27] t7501: stop losing return codes of git commands
Quoted 9 lines · Denton Liu
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 so that we will know if a command fails.
Signed-off-by Denton Liu <[email protected]>---
t/t7501-commit-basic-functionality.sh test_expect_success 'overriding author from command line' ' · line 288
Quoted 7 lines
t/t7501-commit-basic-functionality.sh +2
-3@@ -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 '
git-commit documentation does not talk about the command's exit code, so it's not immediately clear why this test should be using test_must_fail() for the invocation. The implementation of git-commit is more illuminating, showing that 1 is returned when there are no changes to commit, and 0 for a successful commit. So, that raises the question of whether this should be using "test_expect_code 1" rather than test_must_fail(), however, there is existing precedence which gives some guidance. In particular, the "nothing to commit" test of t7501-commit-basic-functionality.sh does use test_must_fail() when attempting to commit with no changes. It may make sense, therefore, to mention something about this in the commit message to save future readers from wondering why the command is "expected to fail".
PATCH 16/27 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.399.gf8350c9437
PATCH 17/27 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.399.gf8350c9437
PATCH 18/27 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.399.gf8350c9437
PATCH 19/27 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.399.gf8350c9437
PATCH 20/27 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 | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-)
t/t7700-repack.sh +38 -26
@@ -18,14 +18,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 - packsha1=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packsha1=$(grep file2 objs | 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/") && + git verify-pack -v pack-$packsha1.idx >packlist && + objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -33,7 +32,8 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -51,7 +51,8 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -69,7 +70,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git prune-packed && for p in .git/objects/pack/*.idx do - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
@@ -184,8 +196,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 | - egrep "^$csha1 " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! egrep "^$csha1 " packlist && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
@@ -201,8 +213,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 | - egrep "^$csha1 " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! egrep "^$csha1 " && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 21/27 t: define test_grep_return_success()
In reply to Denton LiuIn a future patch, we plan on running tests with set -o pipefail. However, since grep can return failure in the case that no lines are matched, this can trigger a failure in a pipe in the case where grep is being used as a filter.
Define the test_grep_return_success() function which acts as a wrapper around grep but always returns 0 so that it can be used in the situation described above.
--- t/test-lib-functions.sh | 5 +++++ 1 file changed, 5 insertions(+)
t/test-lib-functions.sh +5 -0
@@ -990,6 +990,11 @@ test_i18ngrep () { return 1 } +# Calls grep but returns zero even if no matching lines are found. +test_grep_return_success () { + grep "$@" || : +} + # Call any command "$@" but be more verbose about its # failure. This is handy for commands like "test" which do # not output anything when they fail.
Signature · 1 line
2.24.0.399.gf8350c9437
Re: [PATCH 21/27] t: define test_grep_return_success()
t/test-lib-functions.sh test_i18ngrep () { · line 996
Quoted 4 lines · Denton Liu
t/test-lib-functions.sh +4
-0+# Calls grep but returns zero even if no matching lines are found. +test_grep_return_success () { + grep "$@" || : +}
It makes sense to have a helper like this, but the name is quite a mouthful. I wonder if we can call it with a shorter name, e.g. "test_filter" or something.
PATCH 22/27 t0090: mask failing grep status
In reply to Denton LiuIn a future patch, we plan on running tests with set -o pipefail. However, since grep can return failure in the case that no lines are matched, this can trigger a failure in a pipe in the case where grep is being used as a filter.
Use test_grep_return_success() instead of grep so that we don't fail even if we have no matching lines.
--- t/t0090-cache-tree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
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_grep_return_success / 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" &&
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 23/27 t3600: mark git command as failing
In reply to Denton LiuIn a future patch, we plan on running tests with set -o pipefail. Since we intentionally induce SIGPIPE, before the return code was being masked away. However, now git rm will cause an error code to be returned because of the SIGPIPE.
Mark the failing command with test_must_fail ok=sigpipe so that failures induced by SIGPIPE don't propogate.
--- t/t3600-rm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t3600-rm.sh +1 -1
@@ -252,7 +252,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' 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_must_fail ok=sigpipe git rm -n "some-file-*" | : && test_path_is_missing .git/index.lock '
Signature · 1 line
2.24.0.399.gf8350c9437
Re: [PATCH 23/27] t3600: mark git command as failing
Quoted 7 lines · Denton Liu
In a future patch, we plan on running tests with
set -o pipefail. Since we intentionally induce SIGPIPE, before the return code was being masked away. However, nowgit rmwill cause an error code to be returned because of the SIGPIPE.Mark the failing command with
test_must_fail ok=sigpipeso that failures induced by SIGPIPE don't propogate.
Hmph, would this pipeline _always_ fail? I somehow thought that a process that writes into a pipe that is not being read would fail only if the downstream dies and closes before it write(2)s, and if the output from this "git rm -n" is small enough (say to fit within the pipe buffer) and downstream no-op is slow enough to die, the upstream may probably not notice and happily and successfully exit.
: with slow downstream
$ ( ( printf "%s\n" a b c d e); echo "my exit $?" 1>&2 ) |
( sleep 2; echo "downstream exit $?" ); echo "overall exit $?"
my exit 0
downstream exit 0
overall exit 0
: with slow upstream
$ ( (sleep 2; printf "%s\n" a b c d e); echo "my exit $?" 1>&2 ) |
( echo "downstream exit $?" ); echo "overall exit $?"
downstream exit 0
my exit 141
overall exit 0
So, no, I do not think this is a good idea. It would be racy.
Quoted 17 lines
Signed-off-by Denton Liu <[email protected]>--- t/t3600-rm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)t/t3600-rm.sh +1
-1@@ -252,7 +252,7 @@ test_expect_success 'choking "git rm" should not let it die with cruft' ' 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_must_fail ok=sigpipe git rm -n "some-file-*" | : && test_path_is_missing .git/index.lock '
PATCH 24/27 t5004: ignore SIGPIPE in zipinfo
In reply to Denton LiuIn a future patch, we plan on running tests with set -o pipefail. Since zipinfo is killed by SIGPIPE, it will return an error code which will propogate as a result of the pipefail.
Mask away the return code of zipinfo so that the failure as a result of the SIGPIPE does not propogate.
--- t/t5004-archive-corner-cases.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
t/t5004-archive-corner-cases.sh +3 -1
@@ -153,7 +153,9 @@ 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" many.zip || : + } | head -2 | sed -n "2s/.* //p" >actual && test_cmp expect actual '
Signature · 1 line
2.24.0.399.gf8350c9437
Re: [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo
Quoted 2 lines · Denton Liu
In a future patch, we plan on running tests with
set -o pipefail. Since zipinfo is killed by SIGPIPE, it will return an error code which
s/is killed/may be killed/ for the reasons I wrote for 23/27, I think.
Otherwise the idea behind the patch is good.
Thanks.
Quoted 24 lines
will propogate as a result of the pipefail.
Mask away the return code of zipinfo so that the failure as a result of the SIGPIPE does not propogate.
Signed-off-by Denton Liu <[email protected]>--- t/t5004-archive-corner-cases.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)t/t5004-archive-corner-cases.sh +3
-1@@ -153,7 +153,9 @@ 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" many.zip || : + } | head -2 | sed -n "2s/.* //p" >actual && test_cmp expect actual '
PATCH 25/27 t5703: mask failing grep status
In reply to Denton LiuIn a future patch, we plan on running tests with set -o pipefail. However, since grep can return failure in the case that no lines are matched, this can trigger a failure in a pipe in the case where grep is being used as a filter.
Use test_grep_return_success() instead of grep so that we don't fail even if we have no matching lines.
--- t/t5703-upload-pack-ref-in-want.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
t/t5703-upload-pack-ref-in-want.sh +1 -1
@@ -19,7 +19,7 @@ get_actual_commits () { }' <out | test-tool pkt-line unpack-sideband >o.pack && git index-pack o.pack && git verify-pack -v o.idx >objs && - grep commit objs | cut -c-40 | sort >actual_commits + test_grep_return_success commit objs | cut -c-40 | sort >actual_commits } check_output () {
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 26/27 t9902: disable pipefail
In reply to Denton LiuIn a future patch, we plan on running tests with set -o pipefail. However, these tests cannot run with pipefail. Since git-completion.bash is not a testing script, it does not follow the same return code conventions and it's expected that commands can fail within a pipeline.
Run set +o pipefail to disable pipefail in this script.
Note that this is being unconditionally run because this test will be skipped if its not running on Bash.
--- t/t9902-completion.sh | 6 ++++++ 1 file changed, 6 insertions(+)
t/t9902-completion.sh +6 -0
@@ -7,6 +7,12 @@ test_description='test bash completion' . ./lib-bash.sh +# These tests cannot run with pipefail. Since git-completion.bash is not +# a testing script, it does not follow the same return code conventions +# and it's expected that commands can fail within a pipeline. Ignore +# these failures. +set +o pipefail + complete () { # do nothing
Signature · 1 line
2.24.0.399.gf8350c9437
PATCH 27/27 t: run tests with `set -o pipefail` on Bash
In reply to Denton LiuThe current convention is to ensure that git commands are not placed in the upstream of a pipe. If they are, they could fail in an undetectable manner since a pipe's return code is the last command in the pipe. However, many old tests are still written with git commands in the upstream of a pipe.
In the spirit of catching these failures, run tests with set -o pipefail if the underlying shell is Bash. This way, we can catch failures of Git commands that may occur even in the middle of a pipeline.
In the future, more shells that support set -o pipefail may have it enabled but let's start small for now.
--- t/README | 4 ++++ t/test-lib.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+)
t/README +4 -0
@@ -415,6 +415,10 @@ GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS=<boolean>, when true (which is the default when running tests), errors out when an abbreviated option is used. +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 and false otherwise. + Naming Tests ------------
t/test-lib.sh +12 -0
@@ -64,6 +64,18 @@ then export GIT_TEST_DISALLOW_ABBREVIATED_OPTIONS fi +# Use set -o pipefail on platforms that support it +GIT_TEST_PIPEFAIL_DEFAULT=false +# TODO: detect more platforms that support `set -o pipefail` +if test -n "$BASH_VERSION" +then + GIT_TEST_PIPEFAIL_DEFAULT=true +fi +if git env--helper --type=bool --default="$GIT_TEST_PIPEFAIL_DEFAULT" --exit-code GIT_TEST_PIPEFAIL +then + set -o pipefail +fi + ################################################################ # It appears that people try to run tests without building... "${GIT_TEST_INSTALLED:-$GIT_BUILD_DIR}/git$X" >/dev/null
Signature · 1 line
2.24.0.399.gf8350c9437
Quoted 10 lines · Denton Liu
Patches 1-20 perform some general test cleanup to modernise the style. They should be relatively uncontroversial and can be merged earlier (or as a separate series) if desired. The reason these tests were identified for cleanup was because they failed under
set -o pipefail.Patches 21-27 should be considered RFC. In an attempt to catch git commands failing in the upstream of a pipe, we enable
set -o pipefailon Bash. This may result in some funny-looking shell script constructs (e.g. needing to wrapgrepsince it may "fail") but overall, I think it is an improvement since we catch failure in more cases.
Using pipefail can have unexpected consequences for other commands if they rely on SIGPIPE/EPIPE to signal the left-hand side of the pipe. E.g., this:
$ set -o pipefail $ yes | head >/dev/null $ echo $?
will consistently yield 141, since "yes" will always die to SIGPIPE after "head" stops reading from it.
But much worse, this can be racy. Take something like this (which is a real snippet in our test suite):
git status -s -b | head -1
The "head" process will quit after reading one line. What's the exit code of "git status"? It's either "0", if it managed to write everything into the pipe buffer before the simultaneously-running "head" closed the pipe. Or it's 141, if it didn't and got SIGPIPE.
You could argue that "git status" should not be on the left-hand side of a pipe, but the same holds for any command on the left-hand side. E.g., grepping in our test scripts yields some bits like:
t/t7003-filter-branch.sh: echo "$faux_gpg_tag" | sed -e s/XXXXXX/$sha1/ | head -n 6 > expect && t/t9400-git-cvsserver-server.sh: test "$(echo $(grep -v ^D cvswork/CVS/Entries|cut -d/ -f2,3,5 | head -n 1))" = "empty/1.1/" &&
And it's not just "head" that doesn't read all of its input. Another common one is "grep -q", which can quit as soon as it sees a match.
So I have a feeling that pipefail is going to create more headaches than it solves.
-Peff
cover tests: add a bash "set -o pipefail" test mode
There'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 v2 1/11 cache-tree tests: remove unused $2 parameter
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.
--- 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 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
Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection
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 + ) 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 02/11] cache-tree tests: use a sub-shell with less indirection
Quoted 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
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
Re: [PATCH v2 03/11] cache-tree tests: refactor overly complex function
Quoted 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 () {
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
Re: [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style
Quoted 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.
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 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
Re: [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges".
Quoted 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 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
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 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
Re: [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status
Quoted 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 () {
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
Re: [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header
Quoted 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
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 00/11] tests: add a bash "set -o pipefail" test mode
Quoted 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 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
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 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
Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash
Quoted 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...
v3 cover Miscellaneous "set -o pipefail"-related test cleanups
This 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
Re: [PATCH v3 01/10] cache-tree tests: refactor for modern test style
t/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?
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
Re: [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter
Quoted 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.
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
Re: [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection
Quoted 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.
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 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
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
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.
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
Re: [PATCH 1/6] test-lib: add tests for test_might_fail
t/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
PATCH 1/1 test-lib: add tests for test_might_fail
This 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
Re: [PATCH] test-lib: add tests for test_might_fail
Quoted 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
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
Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
Hi Æ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 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
Quoted 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 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe"
Quoted 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
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
Re: [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate
t/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 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate
Quoted 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
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
Re: [PATCH 5/6] tests: split up bash detection library
t/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...
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 6/6] tests: add a "set -o pipefail" for a patched bash
Quoted 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
v2 cover t: test cleanup stemming from experimentally enabling pipefail
In reply to Denton LiuThese patches perform some general test cleanup to modernise the style. They should be relatively uncontroversial. The reason these tests were identified for cleanup was because they failed under set -o pipefail.
I've gotten rid of the RFC part that actually enables set -o pipefail on supported platforms. As Peff pointed out, there are a lot of opportunities for racy SIGPIPE failures so that part still needs a lot of work to be ironed out.
Those changes shouldn't hold back the first part of the series, however. Let's try to get this test cleanup merged in sooner than later so that any new test cases done by copy-paste will have their changes represented.
Changes since v1:
* Removed the set -o pipefail changes
* Addressed Junio and Eric's comments on the first part of the series
Denton Liu (21):
lib-bash.sh: move then onto its own line
t0014: remove git command upstream of pipe
t0090: stop losing return codes of git commands
t3301: stop losing return codes of git commands
t3600: use test_line_count() where possible
t3600: stop losing return codes of git commands
t3600: comment on inducing SIGPIPE in git rm
t4015: stop losing return codes of git commands
t4015: use test_write_lines()
t4138: stop losing return codes of git commands
t5317: stop losing return codes of git commands
t5317: use ! grep to check for no matching lines
t5703: simplify one-time-sed generation logic
t5703: stop losing return codes of git commands
t7501: remove spaces after redirect operators
t7501: stop losing return codes of git commands
t7700: drop redirections to /dev/null
t7700: remove spaces after redirect operators
t7700: move keywords onto their own line
t7700: s/test -f/test_path_is_file/
t7700: stop losing return codes of git commands
t/lib-bash.sh | 6 +- t/t0014-alias.sh | 4 +- t/t0090-cache-tree.sh | 5 +- t/t3301-notes.sh | 230 ++++++++++++++++++------- t/t3600-rm.sh | 14 +- t/t4015-diff-whitespace.sh | 123 +++++++------ t/t4138-apply-ws-expansion.sh | 16 +- t/t5317-pack-objects-filter-objects.sh | 34 ++-- t/t5703-upload-pack-ref-in-want.sh | 53 +++--- t/t7501-commit-basic-functionality.sh | 83 +++++---- t/t7700-repack.sh | 125 ++++++++------ 11 files changed, 428 insertions(+), 265 deletions(-)
Range-diff against v1:
1: a1a1199254 ! 1: da6ff63918 lib-bash.sh: move then onto its own line
@@ t/lib-bash.sh
+then
# we are in full-on bash mode
true
- elif type bash >/dev/null 2>&1; then
+-elif type bash >/dev/null 2>&1; then
++elif type bash >/dev/null 2>&1
++then
+ # execute in full-on bash mode
+ unset POSIXLY_CORRECT
+ exec bash "$0" "$@"
2: 735d3fce93 = 2: c0a513145d t0014: remove git command upstream of pipe
3: c29a54880a = 3: 52d8933ac9 t0090: stop losing return codes of git commands
4: 5d634f8e5d = 4: e8eafa1551 t3301: stop losing return codes of git commands
5: 49069d12c0 = 5: 97ad3604dd t3600: use test_line_count() where possible
6: e4c43b686a = 6: e0152ff3c1 t3600: stop losing return codes of git commands
7: 91001a5be3 = 7: 54e9e78e03 t3600: comment on inducing SIGPIPE in `git rm`
8: 738e0f1c27 = 8: 7c9e9a4b81 t4015: stop losing return codes of git commands
9: 63b0028057 = 9: 9fb33ea04e t4015: use test_write_lines()
10: 8f9945bb16 ! 10: 6c91594492 t4138: stop losing return codes of git commands
@@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
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_must_fail git diff --no-index before after >patch1.patch.raw &&
++ 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 &&
@@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
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_must_fail git diff --no-index before after >patch2.patch.raw &&
++ 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 &&
@@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
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_must_fail git diff --no-index before after >patch3.patch.raw &&
++ 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 &&
@@ t/t4138-apply-ws-expansion.sh: test_expect_success setup '
done &&
- git diff --no-index before after |
- sed -e "s/before/test-4/" -e "s/after/test-4/" >patch4.patch &&
-+ test_must_fail git diff --no-index before after >patch4.patch.raw &&
++ 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 &&
11: 823ed38115 = 11: 04beafae8e t5317: stop losing return codes of git commands
12: 6342f480d5 ! 12: b24745bd60 t5317: use ! grep to check for no matching lines@@ Commit message
Several 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
+ return code! Use ! grep in the cases where we are ensuring that there
are no matching lines.
+ It turns out that these tests were simply born this way[1], doing all
+ this unnecessary work for no reason, probably due to copy/paste
+ programming, and it seems no reviewer caught it. Likewise, 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)
+
+ Helped-by: Eric Sunshine <[email protected]>
+
+ ## Notes ##
+ Thanks for your help, Eric. I shamelessly stole your message text for
+ the commit message.
+
## t/t5317-pack-objects-filter-objects.sh ##
@@ t/t5317-pack-objects-filter-objects.sh: test_expect_success 'verify blob:none packfile has no blobs' '
git -C r1 index-pack ../filter.pack &&
-: ---------- > 13: d5fb60be6b t5703: simplify one-time-sed generation logic
13: 89b68fc876 ! 14: 4071168d8b t5703: stop losing return codes of git commands
@@ t/t5703-upload-pack-ref-in-want.sh: test_expect_success 'fetching ref and exact
grep "want-ref refs/heads/master" log
'
-@@ t/t5703-upload-pack-ref-in-want.sh: inconsistency () {
- # repository appears to change during negotiation, for example, when
- # different servers in a load-balancing arrangement serve (stateless)
- # RPCs during a single negotiation.
-+ oid1=$(git -C "$REPO" rev-parse $1) &&
-+ oid2=$(git -C "$REPO" rev-parse $2) &&
- printf "s/%s/%s/" \
-- $(git -C "$REPO" rev-parse $1 | tr -d "\n") \
-- $(git -C "$REPO" rev-parse $2 | tr -d "\n") \
-+ $(echo "$oid1" | tr -d "\n") \
-+ $(echo "$oid2" | tr -d "\n") \
- >"$HTTPD_ROOT_PATH/one-time-sed"
- }
-
14: 6ab0dafb54 = 15: 63eebe1df6 t7501: remove spaces after redirect operators
15: 952d3fdfe4 ! 16: 4675d3dbc4 t7501: stop losing return codes of git commands @@ Commit message
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 ##
16: e30db4d20e = 17: 3cc6e4455c t7700: drop redirections to /dev/null 17: 664145360d = 18: 43f184dbd5 t7700: remove spaces after redirect operators 18: 6a63a98b1c = 19: 9389a74fe0 t7700: move keywords onto their own line 19: 4749dbcb88 = 20: 079a42c45b t7700: s/test -f/test_path_is_file/ 20: 6821af454c = 21: a455fbb625 t7700: stop losing return codes of git commands 21: 6d0243d9bc < -: ---------- t: define test_grep_return_success() 22: d56a851930 < -: ---------- t0090: mask failing grep status 23: df8fab5f1c < -: ---------- t3600: mark git command as failing 24: ca29fdaddd < -: ---------- t5004: ignore SIGPIPE in zipinfo 25: 4d3c28d90e < -: ---------- t5703: mask failing grep status 26: d89c2c24ae < -: ---------- t9902: disable pipefail 27: 7036c96fc7 < -: ---------- t: run tests with `set -o pipefail` on Bash
Signature · 1 line
2.24.0.450.g7a9a4598a9
PATCH v2 1/21 lib-bash.sh: move `then` onto its own line
The code style for tests is to have statements on their own line if possible. Move the then onto its own line so that it conforms with the test style.
--- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/lib-bash.sh +4 -2
@@ -2,10 +2,12 @@ # to run under Bash; primarily intended for tests of the completion # script. -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then # we are in full-on bash mode true -elif type bash >/dev/null 2>&1; then +elif type bash >/dev/null 2>&1 +then # execute in full-on bash mode unset POSIXLY_CORRECT exec bash "$0" "$@"
Signature · 1 line
2.24.0.450.g7a9a4598a9
PATCH v2 2/21 t0014: remove git command upstream of pipe
In reply to Denton LiuBefore, the git frotz command would fail but its return code was hidden since it was in the upstream of a pipe. Break the pipeline into two commands so that the return code is no longer lost. Also, mark git frotz with test_must_fail since it's supposed to fail.
--- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t0014-alias.sh +2 -2
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' ' #' test_expect_success 'run-command formats empty args properly' ' - GIT_TRACE=1 git frotz a "" b " " c 2>&1 | - sed -ne "/run_command:/s/.*trace: run_command: //p" >actual && + test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw && + sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual && echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect && test_cmp expect actual '
Signature · 1 line
2.24.0.450.g7a9a4598a9
PATCH v2 3/21 t0090: stop losing return codes of git commands
In reply to Denton LiuIn generate_expected_cache_tree_rec(), there are currently two instances of git ls-files in the upstream of a pipe. In the case where the upstream git command fails, its return code will be lost. Extract the git ls-files into its own call so that if it ever fails, its return code is not lost.
--- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
t/t0090-cache-tree.sh +3 -2
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () { 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 - subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && + 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=$(git ls-files|wc -l) && + entries=$(wc -l <files) && printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && for subtree in $subtrees do
Signature · 1 line
2.24.0.450.g7a9a4598a9
PATCH v2 4/21 t3301: 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.
This patch fixes a real buggy test: in 'copy note with "git notes copy"', git notes was mistyped as git note.
--- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-)
t/t3301-notes.sh +163 -67
@@ -54,7 +54,9 @@ test_expect_success 'create notes' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b4" = "$(git notes show)" && + echo b4 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b3" = "$(git notes show)" && + echo b3 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'show notes from treeish' ' - test "b3" = "$(git notes --ref commits^{tree} show)" && - test "b4" = "$(git notes --ref commits@{1} show)" + echo b3 >expect && + git notes --ref commits^{tree} show >actual && + test_cmp expect actual && + + echo b4 >expect && + git notes --ref commits@{1} show >actual && + test_cmp expect actual ' test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b3" = "$(git notes show)" && + echo b3 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b1" = "$(git notes show)" && + echo b1 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b2" = "$(git notes show)" && + echo b2 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b1" = "$(git notes show)" && + echo b1 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' ' Notes: ${indent}b1 EOF - ! (git cat-file commit HEAD | grep b1) && + git cat-file commit HEAD >commits && + ! grep b1 commits && git log -1 >actual && test_cmp expect actual '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' ' test_expect_success 'list notes with "git notes list"' ' commit_2=$(git rev-parse 2nd) && commit_3=$(git rev-parse 3rd) && + note_2=$(git rev-parse refs/notes/commits:$commit_2) && + note_3=$(git rev-parse refs/notes/commits:$commit_3) && sort -t" " -k2 >expect <<-EOF && - $(git rev-parse refs/notes/commits:$commit_2) $commit_2 - $(git rev-parse refs/notes/commits:$commit_3) $commit_3 + $note_2 $commit_2 + $note_3 $commit_3 EOF git notes list >actual && test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' ' ' test_expect_success 'list specific note with "git notes list <object>"' ' - cat >expect <<-EOF && - $(git rev-parse refs/notes/commits:$commit_3) - EOF + git rev-parse refs/notes/commits:$commit_3 >expect && git notes list HEAD^^ >actual && test_cmp expect actual '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' ' test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' commit_5=$(git rev-parse 5th) && + note_5=$(git rev-parse refs/notes/commits:$commit_5) && sort -t" " -k2 >expect_list <<-EOF && - $(git rev-parse refs/notes/commits:$commit_2) $commit_2 - $(git rev-parse refs/notes/commits:$commit_3) $commit_3 - $(git rev-parse refs/notes/commits:$commit_5) $commit_5 + $note_2 $commit_2 + $note_3 $commit_3 + $note_5 $commit_5 EOF git notes list >actual && test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' git notes show HEAD: >actual && test_cmp expect actual && echo "Note on a blob" >expect && - filename=$(git ls-tree --name-only HEAD | head -n1) && + git ls-tree --name-only HEAD >files && + filename=$(head -n1 files) && git notes add -m "Note on a blob" HEAD:$filename && git notes show HEAD:$filename >actual && test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' ' Notes: ${indent}order test EOF - git notes add -C $(git notes list HEAD^) && + note=$(git notes list HEAD^) && + git notes add -C $note && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i Notes: ${indent}This is a blob object EOF - blob=$(echo "This is a blob object" | git hash-object -w --stdin) && - git notes add -C $blob && + echo "This is a blob object" | git hash-object -w --stdin >blob && + git notes add -C $(cat blob) && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$blob" + git notes list HEAD >actual && + test_cmp blob actual ' test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' ' Notes: ${indent}yet another note EOF - MSG="yet another note" git notes add -c $(git notes list HEAD^^) && + note=$(git notes list HEAD^^) && + MSG="yet another note" git notes add -c $note && git log -1 >actual && test_cmp expect actual '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"' ${indent} ${indent}yet another note EOF - git notes append -C $(git notes list HEAD^) HEAD^ && + note=$(git notes list HEAD^) && + git notes append -C $note HEAD^ && git log -1 HEAD^ >actual && test_cmp expect actual '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' ' Notes: ${indent}other note EOF - MSG="other note" git notes append -c $(git notes list HEAD^) && + note=$(git notes list HEAD^) && + MSG="other note" git notes append -c $note && git log -1 >actual && test_cmp expect actual '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"' ${indent} ${indent}yet another note EOF - MSG="yet another note" git notes append -c $(git notes list HEAD) && + note=$(git notes list HEAD) && + MSG="yet another note" git notes append -c $note && git log -1 >actual && test_cmp expect actual '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' ' git notes copy 8th 4th && git log 3rd..4th >actual && test_cmp expect actual && - test "$(git note list 4th)" = "$(git note list 8th)" + git notes list 4th >expect && + git notes list 8th >actual && + test_cmp expect actual ' test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' ' git notes copy HEAD^ && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'prevent overwrite with "git notes copy"' ' test_must_fail git notes copy HEAD~2 HEAD && + cat >expect <<-EOF && + commit $commit + Author: A U Thor <[email protected]> + Date: Thu Apr 7 15:23:13 2005 -0700 + + ${indent}11th + + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' ' git notes copy -f HEAD~3 HEAD && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~3)" + git notes list HEAD~3 >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' ' git notes copy -f HEAD~2 && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" + git notes list HEAD~2 >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' ' ${indent} ${indent}yet another note EOF - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --stdin && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --stdin <copy && git log -2 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && - test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" + git notes list HEAD~2 >expect && + git notes list HEAD >actual && + test_cmp expect actual && + git notes list HEAD~3 >expect && + git notes list HEAD^ >actual && + test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' ${indent}14th EOF - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -2 >actual && test_cmp expect actual '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' ' EOF test_config notes.rewriteMode overwrite && test_config notes.rewriteRef "refs/notes/*" && - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -2 >actual && test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (disabled)' ' test_config notes.rewrite.bar false && - echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | - git notes copy --for-rewrite=bar && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=bar <copy && git log -2 >actual && test_cmp expect actual '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' ' git notes add -f -m"a fresh note" HEAD^ && test_config notes.rewriteMode overwrite && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' ' test_expect_success 'git notes copy --for-rewrite (ignore)' ' test_config notes.rewriteMode ignore && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' ' git notes add -f -m"another fresh note" HEAD^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' ' git notes add -f -m"append 2" HEAD^^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - (echo $(git rev-parse HEAD^) $(git rev-parse HEAD) && - echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD^^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' ' git notes remove HEAD^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && git notes add -f -m"replacement note 1" HEAD^ && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' ' git notes add -f -m"replacement note 2" HEAD^ && test_config notes.rewriteMode overwrite && test_unconfig notes.rewriteRef && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ - git notes copy --for-rewrite=foo && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' git notes add -f -m"replacement note 3" HEAD^ && test_config notes.rewriteMode overwrite && test_config notes.rewriteRef refs/notes/other && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && GIT_NOTES_REWRITE_REF=refs/notes/commits \ - git notes copy --for-rewrite=foo && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && grep "replacement note 3" actual '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' ' test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' ' test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && - test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master" + echo refs/notes/refs/heads/master >expect && + git notes --ref=refs/heads/master get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (no overrides)' ' test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && - test "$(git notes get-ref)" = "refs/notes/commits" + echo refs/notes/commits >expect && + git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (core.notesRef)' ' test_config core.notesRef refs/notes/foo && - test "$(git notes get-ref)" = "refs/notes/foo" + echo refs/notes/foo >expect && + git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' - test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" + echo refs/notes/bar >expect && + GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (--ref)' ' - test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" + echo refs/notes/baz >expect && + GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual && + test_cmp expect actual ' test_expect_success 'setup testing of empty notes' '
Signature · 1 line
2.24.0.450.g7a9a4598a9
PATCH v2 5/21 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.450.g7a9a4598a9
PATCH v2 6/21 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.450.g7a9a4598a9
PATCH v2 7/21 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.450.g7a9a4598a9
PATCH v2 8/21 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.450.g7a9a4598a9
PATCH v2 9/21 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.450.g7a9a4598a9
PATCH v2 10/21 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.450.g7a9a4598a9
PATCH v2 11/21 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.450.g7a9a4598a9
PATCH v2 12/21 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.
It turns out that these tests were simply born this way[1], doing all this unnecessary work for no reason, probably due to copy/paste programming, and it seems no reviewer caught it. Likewise, 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)
---
Notes:
Thanks for your help, Eric. I shamelessly stole your message text for the commit message.
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.450.g7a9a4598a9
Re: [PATCH v2 12/21] t5317: use ! grep to check for no matching lines
Quoted 11 lines · Denton Liu
Several times in t5317, we would use
wc -lto ensure that a grep result is empty. However, grep already has a way to do that... Its return code! Use! grepin the cases where we are ensuring that there are no matching lines.It turns out that these tests were simply born this way[1], doing all this unnecessary work for no reason, probably due to copy/paste programming, and it seems no reviewer caught it. Likewise, the unnecessary work wasn't noticed even when the code was later touched for various cleanups[2,3].
Quoted 4 lines
Signed-off-by Denton Liu <[email protected]>---
Thanks for your help, Eric. I shamelessly stole your message text for the commit message.
That's fine, but you ought to amend it a bit since it makes no sense when extracted verbatim from my longer review comment which provided needed context. In particular, the bit:
...doing all this unnecessary work for no reason...
is confusing since the reader doesn't know what "this unnecessary work" is. My review email had an entire preceding paragraph that provided context. It should at least be amended to say something along the lines of:
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], doing all the unnecessary work for no reason, probably due to copy/paste programming...
PATCH v2 13/21 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 command substitutions should already strip leading and trailing whitespace, including newlines.
Finally, convert the printf into an echo because it isn't necessary anymore.
--- 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.450.g7a9a4598a9
Re: [PATCH v2 13/21] t5703: simplify one-time-sed generation logic
Quoted 10 lines · Denton Liu
In
inconsistency(), we had twogit rev-parseinvocations 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 command substitutions should already strip leading and trailing whitespace, including newlines.
Saying that command substitution _should_ strip the whitespace leaves the reader in doubt as to whether there are situations in which it might or might not do so. More accurately, command substitution _does_ strip the whitespace, so please drop "should" from this sentence altogether.
Quoted 2 lines
Finally, convert the printf into an echo because it isn't necessary anymore.
This is quite misleading. 'printf' was _never_ necessary; 'echo' was an appropriate alternative even before the other changes made by this patch. Worse, though, this sentence provides no context about _why_ it is safe to change 'printf' to 'echo', so the reader is left with even more questions trying to understand the validity of this change than if you had merely omitted this sentence. My review email[1] provided exact reasoning about why this change is safe. Paraphrasing that explanation for this patch's commit message would go a long way toward convincing the reader that the change makes sense.
[1]: https://lore.kernel.org/git/CAPig+cTj5qOCFRoD4cZOg7BjVvetQWTgdRHzSvAfgtX2YgUXPg@mail.gmail.com/
Re: [PATCH v2 13/21] t5703: simplify one-time-sed generation logic
Hi Eric,
Quoted 9 lines · Eric Sunshine
Quoted 8 lines · Denton Liu
In
inconsistency(), we had twogit rev-parseinvocations 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.
Quoted 8 lines
Quoted 2 lines
Drop the pipe into tr because command substitutions should already strip leading and trailing whitespace, including newlines.
Saying that command substitution _should_ strip the whitespace leaves the reader in doubt as to whether there are situations in which it might or might not do so. More accurately, command substitution _does_ strip the whitespace, so please drop "should" from this sentence altogether.
Good point. I think in general, I have a very passive writing style so I'll make a note to write my commit messages more assertively.
Quoted 4 lines
Quoted 3 lines
Finally, convert the printf into an echo because it isn't necessary anymore.
Quoted 9 lines
This is quite misleading. 'printf' was _never_ necessary; 'echo' was an appropriate alternative even before the other changes made by this patch. Worse, though, this sentence provides no context about _why_ it is safe to change 'printf' to 'echo', so the reader is left with even more questions trying to understand the validity of this change than if you had merely omitted this sentence. My review email[1] provided exact reasoning about why this change is safe. Paraphrasing that explanation for this patch's commit message would go a long way toward convincing the reader that the change makes sense.
Will do.
Thanks,
Denton
PATCH v2 14/21 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.450.g7a9a4598a9
PATCH v2 15/21 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.450.g7a9a4598a9
PATCH v2 16/21 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.450.g7a9a4598a9
PATCH v2 17/21 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.450.g7a9a4598a9
PATCH v2 18/21 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.450.g7a9a4598a9
PATCH v2 19/21 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.450.g7a9a4598a9
PATCH v2 20/21 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.450.g7a9a4598a9
PATCH v2 21/21 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 | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-)
t/t7700-repack.sh +38 -26
@@ -18,14 +18,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 - packsha1=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packsha1=$(grep file2 objs | 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/") && + git verify-pack -v pack-$packsha1.idx >packlist && + objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -33,7 +32,8 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -51,7 +51,8 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -69,7 +70,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git prune-packed && for p in .git/objects/pack/*.idx do - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
@@ -184,8 +196,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 | - egrep "^$csha1 " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! egrep "^$csha1 " packlist && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
@@ -201,8 +213,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 | - egrep "^$csha1 " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! egrep "^$csha1 " && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
Signature · 1 line
2.24.0.450.g7a9a4598a9
v3 cover t: test cleanup stemming from experimentally enabling pipefail
In reply to Denton LiuThese patches perform some general test cleanup to modernise the style. They should be relatively uncontroversial. The reason these tests were identified for cleanup was because they failed under set -o pipefail.
I've gotten rid of the RFC part that actually enables set -o pipefail on supported platforms. As Peff pointed out, there are a lot of opportunities for racy SIGPIPE failures so that part still needs a lot of work to be ironed out.
Those changes shouldn't hold back the first part of the series, however. Let's try to get this test cleanup merged in sooner than later so that any new test cases done by copy-paste will have their changes represented.
Changes since v1:
* Removed the set -o pipefail changes
* Addressed Junio and Eric's comments on the first part of the series
Denton Liu (22):
lib-bash.sh: move then onto its own line apply-one-time-sed.sh: modernize style
t0014: remove git command upstream of pipe
t0090: stop losing return codes of git commands
t3301: stop losing return codes of git commands
t3600: use test_line_count() where possible
t3600: stop losing return codes of git commands
t3600: comment on inducing SIGPIPE in git rm
t4015: stop losing return codes of git commands
t4015: use test_write_lines()
t4138: stop losing return codes of git commands
t5317: stop losing return codes of git commands
t5317: use ! grep to check for no matching lines
t5703: simplify one-time-sed generation logic
t5703: stop losing return codes of git commands
t7501: remove spaces after redirect operators
t7501: stop losing return codes of git commands
t7700: drop redirections to /dev/null
t7700: remove spaces after redirect operators
t7700: move keywords onto their own line
t7700: s/test -f/test_path_is_file/
t7700: stop losing return codes of git commands
t/lib-bash.sh | 6 +- t/lib-httpd/apply-one-time-sed.sh | 8 +- t/t0014-alias.sh | 4 +- t/t0090-cache-tree.sh | 5 +- t/t3301-notes.sh | 230 ++++++++++++++++++------- t/t3600-rm.sh | 14 +- t/t4015-diff-whitespace.sh | 123 +++++++------ t/t4138-apply-ws-expansion.sh | 16 +- t/t5317-pack-objects-filter-objects.sh | 34 ++-- t/t5703-upload-pack-ref-in-want.sh | 53 +++--- t/t7501-commit-basic-functionality.sh | 83 +++++---- t/t7700-repack.sh | 125 ++++++++------ 12 files changed, 433 insertions(+), 268 deletions(-)
Range-diff against v2:
1: 9085cc00af = 1: 9085cc00af lib-bash.sh: move `then` onto its own line -: ---------- > 2: 1fddaab701 apply-one-time-sed.sh: modernize style 2: 9ec5244905 = 3: f69e5345ba t0014: remove git command upstream of pipe 3: 613a58491a = 4: 28ddc6c79d t0090: stop losing return codes of git commands 4: ee40bc972f = 5: 4d5f868e50 t3301: stop losing return codes of git commands 5: 702a25f328 = 6: 658db8866e t3600: use test_line_count() where possible 6: 6ebfed9234 = 7: a7d76f9cb9 t3600: stop losing return codes of git commands 7: 7ca9099fa7 = 8: d35c054344 t3600: comment on inducing SIGPIPE in `git rm` 8: 64ecf82b94 = 9: bd6f6487b9 t4015: stop losing return codes of git commands 9: 8d1f457d19 = 10: 6993316839 t4015: use test_write_lines() 10: 0a843a25c8 = 11: 5e88c755ed t4138: stop losing return codes of git commands 11: 4ace91a8b9 = 12: 56eebcc249 t5317: stop losing return codes of git commands 12: 7a15dd95f8 ! 13: 85c2f8ca27 t5317: use ! grep to check for no matching lines
@@ Commit message
return code! Use ! grep in the cases where we are ensuring that there are no matching lines.
- It turns out that these tests were simply born this way[1], doing all
- this unnecessary work for no reason, probably due to copy/paste
- programming, and it seems no reviewer caught it. Likewise, the
- unnecessary work wasn't noticed even when the code was later touched
- for various cleanups[2,3].
+ 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], doing all the unnecessary work for no
+ reason, probably due to copy/paste programming...
[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)
13: 439994027d ! 14: f7e8ae79fa t5703: simplify one-time-sed generation logic
@@ Commit message
Pull the command substitutions out into variable assignments so that their return codes are not lost.
- Drop the pipe into tr because command substitutions should already strip
- leading and trailing whitespace, including newlines.
+ 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, convert the printf into an echo because it isn't necessary
- anymore.
+ 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.
+
+ Helped-by: Eric Sunshine <[email protected]>
## t/t5703-upload-pack-ref-in-want.sh ##
@@ t/t5703-upload-pack-ref-in-want.sh: inconsistency () {
14: 859328b168 = 15: 28ef8f3a59 t5703: stop losing return codes of git commands 15: d5e5be76c2 = 16: 0824965707 t7501: remove spaces after redirect operators 16: d4154e621d = 17: 5058d21880 t7501: stop losing return codes of git commands 17: 2045c6e30e = 18: 297f383897 t7700: drop redirections to /dev/null 18: 20563779ee = 19: 2521ade74d t7700: remove spaces after redirect operators 19: 37a6d826bc = 20: 560f618334 t7700: move keywords onto their own line 20: ea4338a43a = 21: bd27805e4b t7700: s/test -f/test_path_is_file/ 21: 98aec252fc = 22: e9835b8542 t7700: stop losing return codes of git commands
Signature · 1 line
2.24.0.497.g17aadd8971
PATCH v3 1/22 lib-bash.sh: move `then` onto its own line
The code style for tests is to have statements on their own line if possible. Move the then onto its own line so that it conforms with the test style.
--- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/lib-bash.sh +4 -2
@@ -2,10 +2,12 @@ # to run under Bash; primarily intended for tests of the completion # script. -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then # we are in full-on bash mode true -elif type bash >/dev/null 2>&1; then +elif type bash >/dev/null 2>&1 +then # execute in full-on bash mode unset POSIXLY_CORRECT exec bash "$0" "$@"
Signature · 1 line
2.24.0.497.g17aadd8971
PATCH v3 2/22 apply-one-time-sed.sh: modernize style
In reply to Denton LiuConvert [ ... ] to use test.
Move the thens onto their own lines so that it conforms with the general test style.
Instead of redirecting input into sed, allow it to open its own input.
--- t/lib-httpd/apply-one-time-sed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
t/lib-httpd/apply-one-time-sed.sh +5 -3
@@ -7,11 +7,13 @@ # # This can be used to simulate the effects of the repository changing in # between HTTP request-response pairs. -if [ -e one-time-sed ]; then +if test -e one-time-sed +then "$GIT_EXEC_PATH/git-http-backend" >out - sed "$(cat one-time-sed)" <out >out_modified + sed "$(cat one-time-sed)" out >out_modified - if diff out out_modified >/dev/null; then + if diff out out_modified >/dev/null + then cat out else cat out_modified
Signature · 1 line
2.24.0.497.g17aadd8971
Re: [PATCH v3 02/22] apply-one-time-sed.sh: modernize style
Quoted 11 lines · Denton Liu
Convert
[ ... ]to usetest.Move the
thens onto their own lines so that it conforms with the general test style.Instead of redirecting input into sed, allow it to open its own input.
Signed-off-by Denton Liu <[email protected]>--- t/lib-httpd/apply-one-time-sed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-)
This one is new in this round. As a conversion to match the style guidelines, it looks OK, but the original feels a bit substandard in other ways, e.g. I would have said "if one-time-sed is a file", instead of "if one-time-sed exists as any kind of filesystem entity", and used "cmp -s out out_modified" instead of "diff", which is an overkill if you want to merely learn if two things are equal.
Wait. If we are to see if A and B are the same, and show A when they are the same and otherwise show B, wouldn't it be much simpler to do without comparison and always show B unconditionally instead?
What am I missing?
Ah, there is one extra command in the "else" clause that we cannot see in the post-context. So, sorry for the noise---don't wait ;-)
But all the other things before the "Wait" still stands.
Thanks.
Quoted 21 lines
t/lib-httpd/apply-one-time-sed.sh +5
-3@@ -7,11 +7,13 @@ # # This can be used to simulate the effects of the repository changing in # between HTTP request-response pairs. -if [ -e one-time-sed ]; then +if test -e one-time-sed +then "$GIT_EXEC_PATH/git-http-backend" >out - sed "$(cat one-time-sed)" <out >out_modified + sed "$(cat one-time-sed)" out >out_modified - if diff out out_modified >/dev/null; then + if diff out out_modified >/dev/null + then cat out else cat out_modified
PATCH v3 3/22 t0014: remove git command upstream of pipe
In reply to Denton LiuBefore, the git frotz command would fail but its return code was hidden since it was in the upstream of a pipe. Break the pipeline into two commands so that the return code is no longer lost. Also, mark git frotz with test_must_fail since it's supposed to fail.
--- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
t/t0014-alias.sh +2 -2
@@ -38,8 +38,8 @@ test_expect_success 'looping aliases - internal execution' ' #' test_expect_success 'run-command formats empty args properly' ' - GIT_TRACE=1 git frotz a "" b " " c 2>&1 | - sed -ne "/run_command:/s/.*trace: run_command: //p" >actual && + test_must_fail env GIT_TRACE=1 git frotz a "" b " " c 2>actual.raw && + sed -ne "/run_command:/s/.*trace: run_command: //p" actual.raw >actual && echo "git-frotz a '\'''\'' b '\'' '\'' c" >expect && test_cmp expect actual '
Signature · 1 line
2.24.0.497.g17aadd8971
PATCH v3 4/22 t0090: stop losing return codes of git commands
In reply to Denton LiuIn generate_expected_cache_tree_rec(), there are currently two instances of git ls-files in the upstream of a pipe. In the case where the upstream git command fails, its return code will be lost. Extract the git ls-files into its own call so that if it ever fails, its return code is not lost.
--- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
t/t0090-cache-tree.sh +3 -2
@@ -21,9 +21,10 @@ generate_expected_cache_tree_rec () { 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 - subtrees=$(git ls-files|grep /|cut -d / -f 1|uniq) && + 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=$(git ls-files|wc -l) && + entries=$(wc -l <files) && printf "SHA $dir (%d entries, %d subtrees)\n" "$entries" "$subtree_count" && for subtree in $subtrees do
Signature · 1 line
2.24.0.497.g17aadd8971
PATCH v3 5/22 t3301: 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.
This patch fixes a real buggy test: in 'copy note with "git notes copy"', git notes was mistyped as git note.
--- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-)
t/t3301-notes.sh +163 -67
@@ -54,7 +54,9 @@ test_expect_success 'create notes' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b4" = "$(git notes show)" && + echo b4 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -79,14 +81,21 @@ test_expect_success 'edit existing notes' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b3" = "$(git notes show)" && + echo b3 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ ' test_expect_success 'show notes from treeish' ' - test "b3" = "$(git notes --ref commits^{tree} show)" && - test "b4" = "$(git notes --ref commits@{1} show)" + echo b3 >expect && + git notes --ref commits^{tree} show >actual && + test_cmp expect actual && + + echo b4 >expect && + git notes --ref commits@{1} show >actual && + test_cmp expect actual ' test_expect_success 'cannot edit notes from non-ref' '
@@ -99,7 +108,9 @@ test_expect_success 'cannot "git notes add -m" where notes already exists' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b3" = "$(git notes show)" && + echo b3 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -109,7 +120,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f -m"' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b1" = "$(git notes show)" && + echo b1 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -119,7 +132,9 @@ test_expect_success 'add w/no options on existing note morphs into edit' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b2" = "$(git notes show)" && + echo b2 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -129,7 +144,9 @@ test_expect_success 'can overwrite existing note with "git notes add -f"' ' test_path_is_missing .git/NOTES_EDITMSG && git ls-tree -r refs/notes/commits >actual && test_line_count = 1 actual && - test "b1" = "$(git notes show)" && + echo b1 >expect && + git notes show >actual && + test_cmp expect actual && git show HEAD^ && test_must_fail git notes show HEAD^ '
@@ -146,7 +163,8 @@ test_expect_success 'show notes' ' Notes: ${indent}b1 EOF - ! (git cat-file commit HEAD | grep b1) && + git cat-file commit HEAD >commits && + ! grep b1 commits && git log -1 >actual && test_cmp expect actual '
@@ -472,9 +490,11 @@ test_expect_success 'removing with --stdin --ignore-missing' ' test_expect_success 'list notes with "git notes list"' ' commit_2=$(git rev-parse 2nd) && commit_3=$(git rev-parse 3rd) && + note_2=$(git rev-parse refs/notes/commits:$commit_2) && + note_3=$(git rev-parse refs/notes/commits:$commit_3) && sort -t" " -k2 >expect <<-EOF && - $(git rev-parse refs/notes/commits:$commit_2) $commit_2 - $(git rev-parse refs/notes/commits:$commit_3) $commit_3 + $note_2 $commit_2 + $note_3 $commit_3 EOF git notes list >actual && test_cmp expect actual
@@ -486,9 +506,7 @@ test_expect_success 'list notes with "git notes"' ' ' test_expect_success 'list specific note with "git notes list <object>"' ' - cat >expect <<-EOF && - $(git rev-parse refs/notes/commits:$commit_3) - EOF + git rev-parse refs/notes/commits:$commit_3 >expect && git notes list HEAD^^ >actual && test_cmp expect actual '
@@ -512,10 +530,11 @@ test_expect_success 'append to existing note with "git notes append"' ' test_expect_success '"git notes list" does not expand to "git notes list HEAD"' ' commit_5=$(git rev-parse 5th) && + note_5=$(git rev-parse refs/notes/commits:$commit_5) && sort -t" " -k2 >expect_list <<-EOF && - $(git rev-parse refs/notes/commits:$commit_2) $commit_2 - $(git rev-parse refs/notes/commits:$commit_3) $commit_3 - $(git rev-parse refs/notes/commits:$commit_5) $commit_5 + $note_2 $commit_2 + $note_3 $commit_3 + $note_5 $commit_5 EOF git notes list >actual && test_cmp expect_list actual
@@ -721,7 +740,8 @@ test_expect_success 'Allow notes on non-commits (trees, blobs, tags)' ' git notes show HEAD: >actual && test_cmp expect actual && echo "Note on a blob" >expect && - filename=$(git ls-tree --name-only HEAD | head -n1) && + git ls-tree --name-only HEAD >files && + filename=$(head -n1 files) && git notes add -m "Note on a blob" HEAD:$filename && git notes show HEAD:$filename >actual && test_cmp expect actual &&
@@ -745,10 +765,13 @@ test_expect_success 'create note from other note with "git notes add -C"' ' Notes: ${indent}order test EOF - git notes add -C $(git notes list HEAD^) && + note=$(git notes list HEAD^) && + git notes add -C $note && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'create note from non-existing note with "git notes add -C" fails' '
@@ -777,11 +800,12 @@ test_expect_success 'create note from blob with "git notes add -C" reuses blob i Notes: ${indent}This is a blob object EOF - blob=$(echo "This is a blob object" | git hash-object -w --stdin) && - git notes add -C $blob && + echo "This is a blob object" | git hash-object -w --stdin >blob && + git notes add -C $(cat blob) && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$blob" + git notes list HEAD >actual && + test_cmp blob actual ' test_expect_success 'create note from other note with "git notes add -c"' '
@@ -797,7 +821,8 @@ test_expect_success 'create note from other note with "git notes add -c"' ' Notes: ${indent}yet another note EOF - MSG="yet another note" git notes add -c $(git notes list HEAD^^) && + note=$(git notes list HEAD^^) && + MSG="yet another note" git notes add -c $note && git log -1 >actual && test_cmp expect actual '
@@ -822,7 +847,8 @@ test_expect_success 'append to note from other note with "git notes append -C"' ${indent} ${indent}yet another note EOF - git notes append -C $(git notes list HEAD^) HEAD^ && + note=$(git notes list HEAD^) && + git notes append -C $note HEAD^ && git log -1 HEAD^ >actual && test_cmp expect actual '
@@ -839,7 +865,8 @@ test_expect_success 'create note from other note with "git notes append -c"' ' Notes: ${indent}other note EOF - MSG="other note" git notes append -c $(git notes list HEAD^) && + note=$(git notes list HEAD^) && + MSG="other note" git notes append -c $note && git log -1 >actual && test_cmp expect actual '
@@ -858,7 +885,8 @@ test_expect_success 'append to note from other note with "git notes append -c"' ${indent} ${indent}yet another note EOF - MSG="yet another note" git notes append -c $(git notes list HEAD) && + note=$(git notes list HEAD) && + MSG="yet another note" git notes append -c $note && git log -1 >actual && test_cmp expect actual '
@@ -878,7 +906,9 @@ test_expect_success 'copy note with "git notes copy"' ' git notes copy 8th 4th && git log 3rd..4th >actual && test_cmp expect actual && - test "$(git note list 4th)" = "$(git note list 8th)" + git notes list 4th >expect && + git notes list 8th >actual && + test_cmp expect actual ' test_expect_success 'copy note with "git notes copy" with default' '
@@ -899,14 +929,30 @@ test_expect_success 'copy note with "git notes copy" with default' ' git notes copy HEAD^ && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'prevent overwrite with "git notes copy"' ' test_must_fail git notes copy HEAD~2 HEAD && + cat >expect <<-EOF && + commit $commit + Author: A U Thor <[email protected]> + Date: Thu Apr 7 15:23:13 2005 -0700 + + ${indent}11th + + Notes: + ${indent}other note + ${indent} + ${indent}yet another note + EOF git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD^)" + git notes list HEAD^ >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'allow overwrite with "git notes copy -f"' '
@@ -924,7 +970,9 @@ test_expect_success 'allow overwrite with "git notes copy -f"' ' git notes copy -f HEAD~3 HEAD && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~3)" + git notes list HEAD~3 >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'allow overwrite with "git notes copy -f" with default' '
@@ -944,7 +992,9 @@ test_expect_success 'allow overwrite with "git notes copy -f" with default' ' git notes copy -f HEAD~2 && git log -1 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" + git notes list HEAD~2 >expect && + git notes list HEAD >actual && + test_cmp expect actual ' test_expect_success 'cannot copy note from object without notes' '
@@ -979,13 +1029,21 @@ test_expect_success 'git notes copy --stdin' ' ${indent} ${indent}yet another note EOF - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --stdin && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --stdin <copy && git log -2 >actual && test_cmp expect actual && - test "$(git notes list HEAD)" = "$(git notes list HEAD~2)" && - test "$(git notes list HEAD^)" = "$(git notes list HEAD~3)" + git notes list HEAD~2 >expect && + git notes list HEAD >actual && + test_cmp expect actual && + git notes list HEAD~3 >expect && + git notes list HEAD^ >actual && + test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (unconfigured)' '
@@ -1006,9 +1064,13 @@ test_expect_success 'git notes copy --for-rewrite (unconfigured)' ' ${indent}14th EOF - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -2 >actual && test_cmp expect actual '
@@ -1041,17 +1103,23 @@ test_expect_success 'git notes copy --for-rewrite (enabled)' ' EOF test_config notes.rewriteMode overwrite && test_config notes.rewriteRef "refs/notes/*" && - (echo $(git rev-parse HEAD~3) $(git rev-parse HEAD^) && - echo $(git rev-parse HEAD~2) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD^) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD~2) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -2 >actual && test_cmp expect actual ' test_expect_success 'git notes copy --for-rewrite (disabled)' ' test_config notes.rewrite.bar false && - echo $(git rev-parse HEAD~3) $(git rev-parse HEAD) | - git notes copy --for-rewrite=bar && + from=$(git rev-parse HEAD~3) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=bar <copy && git log -2 >actual && test_cmp expect actual '
@@ -1071,8 +1139,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' ' git notes add -f -m"a fresh note" HEAD^ && test_config notes.rewriteMode overwrite && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1080,8 +1150,10 @@ test_expect_success 'git notes copy --for-rewrite (overwrite)' ' test_expect_success 'git notes copy --for-rewrite (ignore)' ' test_config notes.rewriteMode ignore && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1103,8 +1175,10 @@ test_expect_success 'git notes copy --for-rewrite (append)' ' git notes add -f -m"another fresh note" HEAD^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1131,9 +1205,13 @@ test_expect_success 'git notes copy --for-rewrite (append two to one)' ' git notes add -f -m"append 2" HEAD^^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - (echo $(git rev-parse HEAD^) $(git rev-parse HEAD) && - echo $(git rev-parse HEAD^^) $(git rev-parse HEAD)) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + from=$(git rev-parse HEAD^^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >>copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1142,8 +1220,10 @@ test_expect_success 'git notes copy --for-rewrite (append empty)' ' git notes remove HEAD^ && test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1163,8 +1243,10 @@ test_expect_success 'GIT_NOTES_REWRITE_MODE works' ' test_config notes.rewriteMode concatenate && test_config notes.rewriteRef "refs/notes/*" && git notes add -f -m"replacement note 1" HEAD^ && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | - GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo && + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && + GIT_NOTES_REWRITE_MODE=overwrite git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1184,9 +1266,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF works' ' git notes add -f -m"replacement note 2" HEAD^ && test_config notes.rewriteMode overwrite && test_unconfig notes.rewriteRef && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && GIT_NOTES_REWRITE_REF=refs/notes/commits:refs/notes/other \ - git notes copy --for-rewrite=foo && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && test_cmp expect actual '
@@ -1195,9 +1279,11 @@ test_expect_success 'GIT_NOTES_REWRITE_REF overrides config' ' git notes add -f -m"replacement note 3" HEAD^ && test_config notes.rewriteMode overwrite && test_config notes.rewriteRef refs/notes/other && - echo $(git rev-parse HEAD^) $(git rev-parse HEAD) | + from=$(git rev-parse HEAD^) && + to=$(git rev-parse HEAD) && + echo "$from" "$to" >copy && GIT_NOTES_REWRITE_REF=refs/notes/commits \ - git notes copy --for-rewrite=foo && + git notes copy --for-rewrite=foo <copy && git log -1 >actual && grep "replacement note 3" actual '
@@ -1212,26 +1298,36 @@ test_expect_success 'git notes copy diagnoses too many or too few parameters' ' test_expect_success 'git notes get-ref expands refs/heads/master to refs/notes/refs/heads/master' ' test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && - test "$(git notes --ref=refs/heads/master get-ref)" = "refs/notes/refs/heads/master" + echo refs/notes/refs/heads/master >expect && + git notes --ref=refs/heads/master get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (no overrides)' ' test_unconfig core.notesRef && sane_unset GIT_NOTES_REF && - test "$(git notes get-ref)" = "refs/notes/commits" + echo refs/notes/commits >expect && + git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (core.notesRef)' ' test_config core.notesRef refs/notes/foo && - test "$(git notes get-ref)" = "refs/notes/foo" + echo refs/notes/foo >expect && + git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (GIT_NOTES_REF)' ' - test "$(GIT_NOTES_REF=refs/notes/bar git notes get-ref)" = "refs/notes/bar" + echo refs/notes/bar >expect && + GIT_NOTES_REF=refs/notes/bar git notes get-ref >actual && + test_cmp expect actual ' test_expect_success 'git notes get-ref (--ref)' ' - test "$(GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref)" = "refs/notes/baz" + echo refs/notes/baz >expect && + GIT_NOTES_REF=refs/notes/bar git notes --ref=baz get-ref >actual && + test_cmp expect actual ' test_expect_success 'setup testing of empty notes' '
Signature · 1 line
2.24.0.497.g17aadd8971
PATCH v3 6/22 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.497.g17aadd8971
PATCH v3 7/22 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.497.g17aadd8971
PATCH v3 8/22 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.497.g17aadd8971
PATCH v3 9/22 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.497.g17aadd8971
PATCH v3 10/22 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.497.g17aadd8971
PATCH v3 11/22 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.497.g17aadd8971
PATCH v3 12/22 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.497.g17aadd8971
PATCH v3 13/22 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], doing all the unnecessary work for no reason, probably due to copy/paste programming...
[1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21)
--- 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.497.g17aadd8971
Re: [PATCH v3 13/22] t5317: use ! grep to check for no matching lines
Quoted 7 lines · Denton Liu
[...]
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], doing all the unnecessary work for no reason, probably due to copy/paste programming...
Taking this wording literally from my review comment[1] is (again) fine, but I ended the fragment intentionally with "..." with the expectation that you would fill in the remainder, not expecting you to copy/paste the fragment blindly. Without the remainder -- the part which is supposed to follow the "..." -- the reader if left hanging.
[1]: https://lore.kernel.org/git/CAPig+cQviTjwLSZ+QkC62B58mq6z3yDA-XhPVJQYRq0inEo9nA@mail.gmail.com/
Re: [PATCH v3 13/22] t5317: use ! grep to check for no matching lines
Hi Eric,
Quoted 9 lines · Eric Sunshine
Quoted 7 lines · Denton Liu
[...]
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], doing all the unnecessary work for no reason, probably due to copy/paste programming...
Quoted 5 lines
Taking this wording literally from my review comment[1] is (again) fine, but I ended the fragment intentionally with "..." with the expectation that you would fill in the remainder, not expecting you to copy/paste the fragment blindly. Without the remainder -- the part which is supposed to follow the "..." -- the reader if left hanging.
My mistake, I interpreted the "..." as a stylistic writing choice as opposed to an indication for me to fill it in. I'll fix it up for the next round.
Thanks,
Denton
PATCH v3 14/22 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.497.g17aadd8971
PATCH v3 15/22 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.497.g17aadd8971
PATCH v3 16/22 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.497.g17aadd8971
PATCH v3 17/22 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.497.g17aadd8971
PATCH v3 18/22 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.497.g17aadd8971
PATCH v3 19/22 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.497.g17aadd8971
PATCH v3 20/22 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.497.g17aadd8971
PATCH v3 21/22 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.497.g17aadd8971
PATCH v3 22/22 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 | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-)
t/t7700-repack.sh +38 -26
@@ -18,14 +18,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 - packsha1=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packsha1=$(grep file2 objs | 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/") && + git verify-pack -v pack-$packsha1.idx >packlist && + objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed &&
@@ -33,7 +32,8 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -51,7 +51,8 @@ test_expect_success 'writing bitmaps via command-line can duplicate .keep object do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -69,7 +70,8 @@ test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' do idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git prune-packed && for p in .git/objects/pack/*.idx do - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' '
@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' '
@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' '
@@ -184,8 +196,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 | - egrep "^$csha1 " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! egrep "^$csha1 " packlist && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
@@ -201,8 +213,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 | - egrep "^$csha1 " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! egrep "^$csha1 " && echo >.git/objects/info/alternates && test_must_fail git show $csha1 '
Signature · 1 line
2.24.0.497.g17aadd8971
Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
t/t7700-repack.sh test_expect_success 'objects in packs marked .keep are not repacked' ' · line 27
Quoted 4 lines · Denton Liu
t/t7700-repack.sh +2
-2- objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + git verify-pack -v pack-$packsha1.idx >packlist && + objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
We probably should lose reference to SHA-1 and use $OID_REGEX; this is obviously a #leftoverbits material that is outside the scope of this series.
t/t7700-repack.sh test_expect_success 'loose objects in alternate ODB are not repacked' ' · line 100
Quoted 10 lines
t/t7700-repack.sh +2
-1@@ -91,7 +93,8 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git prune-packed && for p in .git/objects/pack/*.idx do - if git verify-pack -v $p | egrep "^$objsha1" + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist then found_duplicate_object=1 echo "DUPLICATE OBJECT FOUND"
These egrep that try to match lines that begin with an object name can be a simple grep instead (again, outside the scope of this series).
t/t7700-repack.sh test_expect_success 'packed obs in alt ODB are repacked even when local repo is · line 117
Quoted 9 lines
t/t7700-repack.sh +3
-2@@ -109,15 +112,18 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" + done >packs &&
A misleading filename? The lines in this file are not pack files; rather the file has a list of objects in various packs.
t/t7700-repack.sh test_expect_success 'packed obs in alt ODB are repacked even when local repo is · line 127
Quoted 12 lines
t/t7700-repack.sh +4
-2+ git verify-pack -v $myidx >mypacklist && + while read sha1 rest do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs '
Again outside the scope of this series, but this looks O(n^2) to me.
If I were writing this today, I would prepare a sorted list of all object names (and nothing else on each line) in alt_objects/pack/ in one file (call it 'orig'), and prepare another file with a sorted list of all object names described in $myidx (call it 'dest'), and then run "comm -23 orig dest" and see if there is anything that is unique in the 'orig' file (i.e. something in 'orig' is missing from 'dest').
Quoted 11 lines
t/t7700-repack.sh +5
-2@@ -132,15 +138,18 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest
t/t7700-repack.sh test_expect_success 'packed obs in alt ODB are repacked when local repo has pack · line 153
Quoted 10 lines
t/t7700-repack.sh +2
-2do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs '
Likewise.
Quoted 11 lines
t/t7700-repack.sh +5
-2@@ -160,15 +169,18 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' 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 + git verify-pack -v $p >packlist || return $? + sed -n -e "/^[0-9a-f]\{40\}/p" packlist + done >packs && + git verify-pack -v $myidx >mypacklist && + while read sha1 rest
t/t7700-repack.sh test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' · line 184
Quoted 10 lines
t/t7700-repack.sh +2
-2do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) + if ! grep "^$sha1" mypacklist then echo "Missing object in local pack: $sha1" return 1 fi - done + done <packs '
Likewise.
Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
Hi Junio,
Quoted 10 lines · Junio C Hamano
t/t7700-repack.sh test_expect_success 'objects in packs marked .keep are not repacked' ' · line 27
Quoted 4 lines · Denton Liu
t/t7700-repack.sh +2
-2- objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + git verify-pack -v pack-$packsha1.idx >packlist && + objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&We probably should lose reference to SHA-1 and use $OID_REGEX; this is obviously a #leftoverbits material that is outside the scope of this series.
Since the theme of this series is test cleanup, I believe that it's probably appropriate to roll these changes (and the ones below that I omitted) into the current series. Since it isn't too much work, I'll send them out in my next reroll.
Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
Quoted 7 lines · Denton Liu
Quoted 6 lines · Junio C Hamano
Quoted 4 lines · Denton Liu
t/t7700-repack.sh +2
-2- objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + git verify-pack -v pack-$packsha1.idx >packlist && + objsha1=$(head -n 1 packlist | sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") &&
Quoted 8 lines
Quoted 3 lines
We probably should lose reference to SHA-1 and use $OID_REGEX; this is obviously a #leftoverbits material that is outside the scope of this series.
Since the theme of this series is test cleanup, I believe that it's probably appropriate to roll these changes (and the ones below that I omitted) into the current series. Since it isn't too much work, I'll send them out in my next reroll.
It may not be too much work for you to keep adding more (unrelated) changes to a series, but doing so increases the burden on reviewers unnecessarily, especially for a long patch series such as this one. Generally speaking, each iteration should help the series converge to the point at which it can finally land (be merged to "next"). Thus, ideally, each iteration should have fewer changes than the previous one.
When you add entirely new changes which are not directly related to the changes which begat the series, that iteration diverges (not converges). It creates extra work for reviewers (who are trying to help you land the series) and makes it less likely that people will want to review each new iteration since a series which diverges with each iteration makes the goal of landing the series a moving target (thus, represents never-ending review work).
Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
Quoted 7 lines · Eric Sunshine
It may not be too much work for you to keep adding more (unrelated) changes to a series, but doing so increases the burden on reviewers unnecessarily, especially for a long patch series such as this one. Generally speaking, each iteration should help the series converge to the point at which it can finally land (be merged to "next"). Thus, ideally, each iteration should have fewer changes than the previous one.
Yup. It is too easy to paint an ongoing series with a brush that is broader than necessary and say "this is to clean up", and fall into a never-ending run of scope expansion, as there always is yet another thing to clean up. The focus of the series has been to ensure that we catch error exit from "git" and that script conforms to the style guidelines, and does not include hash migration.
Let's resist the urge to expand the scope.
Thanks.
Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands
Hi Junio and Eric,
Quoted 9 lines · Junio C Hamano
Quoted 7 lines · Eric Sunshine
It may not be too much work for you to keep adding more (unrelated) changes to a series, but doing so increases the burden on reviewers unnecessarily, especially for a long patch series such as this one. Generally speaking, each iteration should help the series converge to the point at which it can finally land (be merged to "next"). Thus, ideally, each iteration should have fewer changes than the previous one.
Sorry for expanding the burden I've been putting on you. I really appreciate the effort both of you have been putting in reviewing my work and I'll make sure to not make it any harder than necessary for any reviewers in the future.
Quoted 9 lines
Yup. It is too easy to paint an ongoing series with a brush that is broader than necessary and say "this is to clean up", and fall into a never-ending run of scope expansion, as there always is yet another thing to clean up. The focus of the series has been to ensure that we catch error exit from "git" and that script conforms to the style guidelines, and does not include hash migration.
Let's resist the urge to expand the scope.
I see that Eric's already reviewed the changes from this round (thanks, Eric) so I don't want his work to go to waste. But I won't change the scope from this point forward.
Sorry again for the extra burden,
Denton
Quoted 4 lines
Thanks.
v4 cover t: test cleanup stemming from experimentally enabling pipefail
In reply to Denton LiuThese patches perform some general test cleanup to modernise the style. They should be relatively uncontroversial. The reason these tests were identified for cleanup was because they failed under set -o pipefail.
I've gotten rid of the RFC part that actually enables set -o pipefail on supported platforms. As Peff pointed out, there are a lot of opportunities for racy SIGPIPE failures so that part still needs a lot of work to be ironed out.
Those changes shouldn't hold back the first part of the series, however. Let's try to get this test cleanup merged in sooner than later so that any new test cases done by copy-paste will have their changes represented.
Changes since v3:
* More commit message update
* Clean up "apply-one-time-sed.sh: modernize style" more according to Junio's suggestions
* Clean up the t7700 leftover bits
Changes since v2:
* Update commit messages according to Eric's suggestions
* Add "apply-one-time-sed.sh: modernize style"
Changes since v1:
* Removed the set -o pipefail changes
* Addressed Junio and Eric's comments on the first part of the series
Denton Liu (27):
lib-bash.sh: move then onto its own line apply-one-time-sed.sh: modernize style
t0014: remove git command upstream of pipe
t0090: stop losing return codes of git commands
t3301: stop losing return codes of git commands
t3600: use test_line_count() where possible
t3600: stop losing return codes of git commands
t3600: comment on inducing SIGPIPE in git rm
t4015: stop losing return codes of git commands
t4015: use test_write_lines()
t4138: stop losing return codes of git commands
t5317: stop losing return codes of git commands
t5317: use ! grep to check for no matching lines
t5703: simplify one-time-sed generation logic
t5703: stop losing return codes of git commands
t7501: remove spaces after redirect operators
t7501: stop losing return codes of git commands
t7700: drop redirections to /dev/null
t7700: remove spaces after redirect operators
t7700: move keywords onto their own line
t7700: s/test -f/test_path_is_file/
t7700: consolidate code into test_no_missing_in_packs() squash! 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/lib-bash.sh | 6 +- t/lib-httpd/apply-one-time-sed.sh | 8 +- t/t0014-alias.sh | 4 +- t/t0090-cache-tree.sh | 5 +- t/t3301-notes.sh | 230 ++++++++++++++++++------- t/t3600-rm.sh | 14 +- t/t4015-diff-whitespace.sh | 123 +++++++------ t/t4138-apply-ws-expansion.sh | 16 +- t/t5317-pack-objects-filter-objects.sh | 34 ++-- t/t5703-upload-pack-ref-in-want.sh | 53 +++--- t/t7501-commit-basic-functionality.sh | 83 +++++---- t/t7700-repack.sh | 172 ++++++++---------- 12 files changed, 425 insertions(+), 323 deletions(-)
Range-diff against v3:
1: 9085cc00af = 1: 9085cc00af lib-bash.sh: move `then` onto its own line 2: ac4164374d ! 2: 86f625c65e apply-one-time-sed.sh: modernize style
@@ Metadata
## Commit message ##
apply-one-time-sed.sh: modernize style
- Convert [ ... ] to use test.
+ Convert [ ... ] to use test and test for the existence of a regular
+ file (-f) instead of any file (-e).
Move the thens onto their own lines so that it conforms with the general test style.
Instead of redirecting input into sed, allow it to open its own input.
+ Use cmp -s instead of diff since we only care about whether the two
+ files are equal and diff is overkill for this.
+
## t/lib-httpd/apply-one-time-sed.sh ##
@@
#
# This can be used to simulate the effects of the repository changing in # between HTTP request-response pairs.
-if [ -e one-time-sed ]; then
-+if test -e one-time-sed
++if test -f one-time-sed
+then
"$GIT_EXEC_PATH/git-http-backend" >out
- sed "$(cat one-time-sed)" <out >out_modified
+ sed "$(cat one-time-sed)" out >out_modified
- if diff out out_modified >/dev/null; then
-+ if diff out out_modified >/dev/null
++ if cmp -s out out_modified
+ then
cat out
else
3: b90d68829b = 3: 3844e00367 t0014: remove git command upstream of pipe 4: 51eaffb283 = 4: 7d33586b21 t0090: stop losing return codes of git commands 5: 3c6bb9b2f2 = 5: df6b3393c4 t3301: stop losing return codes of git commands 6: 7925fa3e43 = 6: d541a8d4d4 t3600: use test_line_count() where possible 7: 36be4d0ec1 = 7: a8aeca6795 t3600: stop losing return codes of git commands 8: 01fc8518bf = 8: e3db06578d t3600: comment on inducing SIGPIPE in `git rm` 9: b6f6d47c00 = 9: 22ea5d736e t4015: stop losing return codes of git commands 10: 58a1ae76c0 = 10: a44dd28b4d t4015: use test_write_lines() 11: 07822e3b4c = 11: d512319be0 t4138: stop losing return codes of git commands 12: d892a7b181 = 12: 1e08c2b68b t5317: stop losing return codes of git commands 13: 140de46f80 ! 13: fa238be28b t5317: use ! grep to check for no matching lines
@@ Commit message
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
+ 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], doing all the unnecessary work for no
- reason, probably due to copy/paste programming...
+ 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)
14: 6be0d0388d = 14: 291caf9bc1 t5703: simplify one-time-sed generation logic 15: 3844e7372c = 15: edf7af76ae t5703: stop losing return codes of git commands 16: d47bb4c9f6 = 16: 5eb7117fbe t7501: remove spaces after redirect operators 17: 9e5ede8eac = 17: bad732adc8 t7501: stop losing return codes of git commands 18: 18031e67c7 = 18: c50c192429 t7700: drop redirections to /dev/null 19: 40cd07a57a = 19: 58ae066d12 t7700: remove spaces after redirect operators 20: 049405b49d = 20: 82bf24d06a t7700: move keywords onto their own line 21: 133171522d = 21: 251de77677 t7700: s/test -f/test_path_is_file/ 22: d653869ead < -: ---------- t7700: stop losing return codes of git commands -: ---------- > 22: c98a2a1509 t7700: consolidate code into test_no_missing_in_packs() -: ---------- > 23: e4ba198483 squash! t7700: consolidate code into test_no_missing_in_packs() -: ---------- > 24: fa38d7e8f6 t7700: consolidate code into test_has_duplicate_object() -: ---------- > 25: 4f02c00bd1 t7700: replace egrep with grep -: ---------- > 26: a747fbd08b t7700: make references to SHA-1 generic -: ---------- > 27: fb614f4385 t7700: stop losing return codes of git commands
Signature · 1 line
2.24.0.504.g3cd56eb17d
PATCH v4 1/27 lib-bash.sh: move `then` onto its own line
The code style for tests is to have statements on their own line if possible. Move the then onto its own line so that it conforms with the test style.
--- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-)
t/lib-bash.sh +4 -2
@@ -2,10 +2,12 @@ # to run under Bash; primarily intended for tests of the completion # script. -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" +then # we are in full-on bash mode true -elif type bash >/dev/null 2>&1; then +elif type bash >/dev/null 2>&1 +then # execute in full-on bash mode unset POSIXLY_CORRECT exec bash "$0" "$@"
Signature · 1 line
2.24.0.504.g3cd56eb17d