* [PATCH 00/27] t: general test cleanup + `set -o pipefail` @ 2019-11-15 1:00 Denton Liu 2019-11-15 1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu ` (28 more replies) 0 siblings, 29 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List 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(-) -- 2.24.0.399.gf8350c9437 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 01/27] lib-bash.sh: move `then` onto its own line 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 18:22 ` Eric Sunshine 2019-11-15 1:00 ` [PATCH 02/27] t0014: remove git command upstream of pipe Denton Liu ` (27 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-bash.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 2be955fafb..6a2c21cd24 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 01/27] lib-bash.sh: move `then` onto its own line 2019-11-15 1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu @ 2019-11-15 18:22 ` Eric Sunshine 2019-11-16 2:50 ` Junio C Hamano 0 siblings, 1 reply; 228+ messages in thread From: Eric Sunshine @ 2019-11-15 18:22 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List On Thu, Nov 14, 2019 at 8:00 PM Denton Liu <liu.denton@gmail.com> wrote: > 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. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > diff --git a/t/lib-bash.sh b/t/lib-bash.sh > @@ -2,7 +2,8 @@ > -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then > +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" > +then Okay... > # 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? ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH 01/27] lib-bash.sh: move `then` onto its own line 2019-11-15 18:22 ` Eric Sunshine @ 2019-11-16 2:50 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2019-11-16 2:50 UTC (permalink / raw) To: Eric Sunshine; +Cc: Denton Liu, Git Mailing List Eric Sunshine <sunshine@sunshineco.com> writes: > On Thu, Nov 14, 2019 at 8:00 PM Denton Liu <liu.denton@gmail.com> wrote: >> 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. >> >> Signed-off-by: Denton Liu <liu.denton@gmail.com> >> --- >> diff --git a/t/lib-bash.sh b/t/lib-bash.sh >> @@ -2,7 +2,8 @@ >> -if test -n "$BASH" && test -z "$POSIXLY_CORRECT"; then >> +if test -n "$BASH" && test -z "$POSIXLY_CORRECT" >> +then > > Okay... > >> # 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 ;-) ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 02/27] t0014: remove git command upstream of pipe 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu 2019-11-15 1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 03/27] t0090: stop losing return codes of git commands Denton Liu ` (26 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Before, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 2694c81afd..8d3d9144c0 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 03/27] t0090: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu 2019-11-15 1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-15 1:00 ` [PATCH 02/27] t0014: remove git command upstream of pipe Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 04/27] t3301: " Denton Liu ` (25 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index ce9a4a5f32..5a633690bf 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 04/27] t3301: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (2 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 03/27] t0090: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 05/27] t3600: use test_line_count() where possible Denton Liu ` (24 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Currently, 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`. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d66a5f6faa..8f43303007 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -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 <author@example.com> + 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' ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 05/27] t3600: use test_line_count() where possible 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (3 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 04/27] t3301: " Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 06/27] t3600: stop losing return codes of git commands Denton Liu ` (23 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 8c8cca5bfb..f6e659b7e9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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" ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 06/27] t3600: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (4 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 05/27] t3600: use test_line_count() where possible Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu ` (22 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List When 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f6e659b7e9..0c3bf10edd 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 && -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm` 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (5 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 06/27] t3600: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 08/27] t4015: stop losing return codes of git commands Denton Liu ` (21 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Add 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0c3bf10edd..0ea858d652 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 08/27] t4015: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (6 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 09/27] t4015: use test_write_lines() Denton Liu ` (20 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index eadaf57262..7fb83c8eff 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 09/27] t4015: use test_write_lines() 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (7 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 08/27] t4015: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu ` (19 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Instead of rolling our own method to write out some lines into a file, use the existing test_write_lines(). Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 7fb83c8eff..4c540b1d70 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 10/27] t4138: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (8 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 09/27] t4015: use test_write_lines() Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-16 9:00 ` Eric Sunshine 2019-11-15 1:00 ` [PATCH 11/27] t5317: " Denton Liu ` (18 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List 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 <liu.denton@gmail.com> --- t/t4138-apply-ws-expansion.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 3b636a63a3..60435d6d41 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 10/27] t4138: stop losing return codes of git commands 2019-11-15 1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu @ 2019-11-16 9:00 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-16 9:00 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote: > 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 <liu.denton@gmail.com> > --- > diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh > @@ -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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 11/27] t5317: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (9 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-15 1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu ` (17 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 2d2f5d0229..a8bbad74e2 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 12/27] t5317: use ! grep to check for no matching lines 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (10 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 11/27] t5317: " Denton Liu @ 2019-11-15 1:00 ` Denton Liu 2019-11-16 9:27 ` Eric Sunshine 2019-11-15 1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu ` (16 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:00 UTC (permalink / raw) To: Git Mailing List 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 are no matching lines. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index a8bbad74e2..dc0446574b 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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' ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 12/27] t5317: use ! grep to check for no matching lines 2019-11-15 1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-16 9:27 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-16 9:27 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote: > 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 > are no matching lines. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh > @@ -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) ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 13/27] t5703: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (11 preceding siblings ...) 2019-11-15 1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-16 10:11 ` Eric Sunshine 2019-11-15 1:01 ` [PATCH 14/27] t7501: remove spaces after redirect operators Denton Liu ` (15 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 52 +++++++++++++++++++----------- 1 file changed, 33 insertions(+), 19 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 3a2c143c6d..9f6d837720 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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" } -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 13/27] t5703: stop losing return codes of git commands 2019-11-15 1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu @ 2019-11-16 10:11 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-16 10:11 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote: > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh > @@ -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.) ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 14/27] t7501: remove spaces after redirect operators 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (12 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu ` (14 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index f1349af56e..5765d33c53 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 && -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 15/27] t7501: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (13 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 14/27] t7501: remove spaces after redirect operators Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-16 10:35 ` Eric Sunshine 2019-11-15 1:01 ` [PATCH 16/27] t7700: drop redirections to /dev/null Denton Liu ` (13 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List 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 <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 5765d33c53..110b4bf459 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 15/27] t7501: stop losing return codes of git commands 2019-11-15 1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu @ 2019-11-16 10:35 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-16 10:35 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List On Thu, Nov 14, 2019 at 8:01 PM Denton Liu <liu.denton@gmail.com> wrote: > 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 <liu.denton@gmail.com> > --- > diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh > @@ -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". ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 16/27] t7700: drop redirections to /dev/null 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (14 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 17/27] t7700: remove spaces after redirect operators Denton Liu ` (12 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4e855bc21b..e1a689d6a9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 17/27] t7700: remove spaces after redirect operators 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (15 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 16/27] t7700: drop redirections to /dev/null Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 18/27] t7700: move keywords onto their own line Denton Liu ` (11 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index e1a689d6a9..8936928387 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 18/27] t7700: move keywords onto their own line 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (16 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 17/27] t7700: remove spaces after redirect operators Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 19/27] t7700: s/test -f/test_path_is_file/ Denton Liu ` (10 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List The 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 8936928387..a96e876c4e 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 19/27] t7700: s/test -f/test_path_is_file/ 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (17 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 18/27] t7700: move keywords onto their own line Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 20/27] t7700: stop losing return codes of git commands Denton Liu ` (9 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a96e876c4e..1d14ddcbdb 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 20/27] t7700: stop losing return codes of git commands 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (18 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 19/27] t7700: s/test -f/test_path_is_file/ Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu ` (8 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List 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 <liu.denton@gmail.com> --- t/t7700-repack.sh | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddcbdb..ff50722e26 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 21/27] t: define test_grep_return_success() 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (19 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 20/27] t7700: stop losing return codes of git commands Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 5:26 ` Junio C Hamano 2019-11-15 1:01 ` [PATCH 22/27] t0090: mask failing grep status Denton Liu ` (7 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/test-lib-functions.sh | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index b299ecc326..dddc4cc3b1 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -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. -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 21/27] t: define test_grep_return_success() 2019-11-15 1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu @ 2019-11-15 5:26 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2019-11-15 5:26 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List Denton Liu <liu.denton@gmail.com> writes: > +# 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 22/27] t0090: mask failing grep status 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (20 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu ` (6 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0090-cache-tree.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 5a633690bf..b0f3b69d1d 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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" && -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 23/27] t3600: mark git command as failing 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (21 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 22/27] t0090: mask failing grep status Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 5:35 ` Junio C Hamano 2019-11-15 1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu ` (5 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List 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, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0ea858d652..d1b3703edb 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 23/27] t3600: mark git command as failing 2019-11-15 1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu @ 2019-11-15 5:35 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2019-11-15 5:35 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List Denton Liu <liu.denton@gmail.com> writes: > 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, 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. 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. > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > t/t3600-rm.sh | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh > index 0ea858d652..d1b3703edb 100755 > --- a/t/t3600-rm.sh > +++ b/t/t3600-rm.sh > @@ -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 > ' ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (22 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 5:36 ` Junio C Hamano 2019-11-15 1:01 ` [PATCH 25/27] t5703: mask failing grep status Denton Liu ` (4 subsequent siblings) 28 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List 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 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 <liu.denton@gmail.com> --- t/t5004-archive-corner-cases.sh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 3e7b23cb32..4c6d42d474 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -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 ' -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo 2019-11-15 1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu @ 2019-11-15 5:36 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2019-11-15 5:36 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List Denton Liu <liu.denton@gmail.com> writes: > 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. > 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 <liu.denton@gmail.com> > --- > t/t5004-archive-corner-cases.sh | 4 +++- > 1 file changed, 3 insertions(+), 1 deletion(-) > > diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh > index 3e7b23cb32..4c6d42d474 100755 > --- a/t/t5004-archive-corner-cases.sh > +++ b/t/t5004-archive-corner-cases.sh > @@ -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 > ' ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 25/27] t5703: mask failing grep status 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (23 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 26/27] t9902: disable pipefail Denton Liu ` (3 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 9f6d837720..c4f9698398 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 () { -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 26/27] t9902: disable pipefail 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (24 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 25/27] t5703: mask failing grep status Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 1:01 ` [PATCH 27/27] t: run tests with `set -o pipefail` on Bash Denton Liu ` (2 subsequent siblings) 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t9902-completion.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index e90ac565e1..75a512669e 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 27/27] t: run tests with `set -o pipefail` on Bash 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (25 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 26/27] t9902: disable pipefail Denton Liu @ 2019-11-15 1:01 ` Denton Liu 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 28 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-15 1:01 UTC (permalink / raw) To: Git Mailing List The 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/README | 4 ++++ t/test-lib.sh | 12 ++++++++++++ 2 files changed, 16 insertions(+) diff --git a/t/README b/t/README index 60d5b77bcc..ba96b6d113 100644 --- a/t/README +++ b/t/README @@ -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 ------------ diff --git a/t/test-lib.sh b/t/test-lib.sh index 46c4440843..c0c43dfce9 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -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 -- 2.24.0.399.gf8350c9437 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 00/27] t: general test cleanup + `set -o pipefail` 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (26 preceding siblings ...) 2019-11-15 1:01 ` [PATCH 27/27] t: run tests with `set -o pipefail` on Bash Denton Liu @ 2019-11-15 4:09 ` Jeff King 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (6 more replies) 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 28 siblings, 7 replies; 228+ messages in thread From: Jeff King @ 2019-11-15 4:09 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List On Thu, Nov 14, 2019 at 05:00:29PM -0800, Denton Liu wrote: > 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. 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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 0/6] tests: add a bash "set -o pipefail" test mode 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason ` (11 more replies) 2021-01-14 23:35 ` [PATCH 1/6] test-lib: add tests for test_might_fail Ævar Arnfjörð Bjarmason ` (5 subsequent siblings) 6 siblings, 12 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason 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/cover.1573779465.git.liu.denton@gmail.com/ Æ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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 00/11] tests: add a bash "set -o pipefail" test mode 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 21:50 ` Junio C Hamano 2021-01-17 16:50 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 01/11] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason ` (10 subsequent siblings) 11 siblings, 2 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. But this was confusing and relied on a side-quest to change the test_{must,might}_fail helpers. See https://lore.kernel.org/git/YAFntgQE3NZ3yQx5@coredump.intra.peff.net/ 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/cover.1573779465.git.liu.denton@gmail.com/ @@ 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' ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 00/11] tests: add a bash "set -o pipefail" test mode 2021-01-16 15:35 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason @ 2021-01-16 21:50 ` Junio C Hamano 2021-01-17 16:50 ` Jeff King 1 sibling, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-16 21:50 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > 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. > > But this was confusing and relied on a side-quest to change the > test_{must,might}_fail helpers. See > https://lore.kernel.org/git/YAFntgQE3NZ3yQx5@coredump.intra.peff.net/ > > 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 00/11] tests: add a bash "set -o pipefail" test mode 2021-01-16 15:35 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason 2021-01-16 21:50 ` Junio C Hamano @ 2021-01-17 16:50 ` Jeff King 1 sibling, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-17 16:50 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Sat, Jan 16, 2021 at 04:35:43PM +0100, Ævar Arnfjörð Bjarmason wrote: > 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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 01/11] cache-tree tests: remove unused $2 parameter 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason ` (9 subsequent siblings) 11 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 5a633690bf..354b7f15f7 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 () { -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 01/11] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-17 16:55 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 03/11] cache-tree tests: refactor overly complex function Ævar Arnfjörð Bjarmason ` (8 subsequent siblings) 11 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. 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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 354b7f15f7..2e3efeb80e 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 } -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection 2021-01-16 15:35 ` [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason @ 2021-01-17 16:55 ` Jeff King 2021-01-17 22:23 ` Eric Sunshine 2021-01-17 23:37 ` Junio C Hamano 0 siblings, 2 replies; 228+ messages in thread From: Jeff King @ 2021-01-17 16:55 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Sat, Jan 16, 2021 at 04:35:45PM +0100, Ævar Arnfjörð Bjarmason wrote: > diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh > index 354b7f15f7..2e3efeb80e 100755 > --- a/t/t0090-cache-tree.sh > +++ b/t/t0090-cache-tree.sh > @@ -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 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. > -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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection 2021-01-17 16:55 ` Jeff King @ 2021-01-17 22:23 ` Eric Sunshine 2021-01-17 23:37 ` Junio C Hamano 1 sibling, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2021-01-17 22:23 UTC (permalink / raw) To: Jeff King Cc: Ævar Arnfjörð Bjarmason, Git List, Junio C Hamano, Denton Liu On Sun, Jan 17, 2021 at 11:55 AM Jeff King <peff@peff.net> wrote: > On Sat, Jan 16, 2021 at 04:35:45PM +0100, Ævar Arnfjörð Bjarmason wrote: > > for subtree in $subtrees > > do > > + ( > > + 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? I'd say "yes". > 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. 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. [1]: https://lore.kernel.org/git/20150325052952.GE31924@peff.net/ ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection 2021-01-17 16:55 ` Jeff King 2021-01-17 22:23 ` Eric Sunshine @ 2021-01-17 23:37 ` Junio C Hamano 1 sibling, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-17 23:37 UTC (permalink / raw) To: Jeff King Cc: Ævar Arnfjörð Bjarmason, git, Denton Liu, Eric Sunshine Jeff King <peff@peff.net> writes: > On Sat, Jan 16, 2021 at 04:35:45PM +0100, Ævar Arnfjörð Bjarmason wrote: > >> diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh >> index 354b7f15f7..2e3efeb80e 100755 >> --- a/t/t0090-cache-tree.sh >> +++ b/t/t0090-cache-tree.sh >> @@ -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 > > 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 Thanks, I missed that bogus/confusing return. > > might be more obvious. > >> -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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 03/11] cache-tree tests: refactor overly complex function 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (2 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason ` (7 subsequent siblings) 11 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Refactor 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) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 2e3efeb80e..f1b0a6a679 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 () { -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 03/11] cache-tree tests: refactor overly complex function 2021-01-16 15:35 ` [PATCH v2 03/11] cache-tree tests: refactor overly complex function Ævar Arnfjörð Bjarmason @ 2021-01-16 21:51 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-16 21:51 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > Refactor overly complex code added in 9c4d6c0297 (cache-tree: Write > updated cache-tree after commit, 2014-07-13). OK. > 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. > 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. > I'm also removing the comment, because I think now that this code is > trivial to understand it's not needed anymore. OK. Thanks. > 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 <avarab@gmail.com> > --- > t/t0090-cache-tree.sh | 16 ++++++---------- > 1 file changed, 6 insertions(+), 10 deletions(-) > > diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh > index 2e3efeb80e..f1b0a6a679 100755 > --- a/t/t0090-cache-tree.sh > +++ b/t/t0090-cache-tree.sh > @@ -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 () { ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (3 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 03/11] cache-tree tests: refactor overly complex function Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 05/11] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty Ævar Arnfjörð Bjarmason ` (6 subsequent siblings) 11 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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 <avarab@gmail.com> --- t/t9151-svn-mergeinfo.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 4f6c06ecb2..59c5847c5f 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style 2021-01-16 15:35 ` [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason @ 2021-01-16 21:51 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-16 21:51 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > 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 <avarab@gmail.com> > --- > t/t9151-svn-mergeinfo.sh | 16 ++++++++-------- > 1 file changed, 8 insertions(+), 8 deletions(-) > > diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh > index 4f6c06ecb2..59c5847c5f 100755 > --- a/t/t9151-svn-mergeinfo.sh > +++ b/t/t9151-svn-mergeinfo.sh > @@ -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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 05/11] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (4 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason ` (5 subsequent siblings) 11 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Refactor some old-style test code to use test_must_be_empty instead of "test -z". This makes a follow-up commit easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t9151-svn-mergeinfo.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 59c5847c5f..806eff4023 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges". 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (5 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 05/11] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano 2021-01-17 16:47 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 07/11] rm tests: actually test for SIGPIPE in SIGPIPE test Ævar Arnfjörð Bjarmason ` (4 subsequent siblings) 11 siblings, 2 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason From: Jeff King <peff@peff.net> 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 <peff@peff.net> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Commit-message-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t9151-svn-mergeinfo.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 806eff4023..c33bae91fb 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges". 2021-01-16 15:35 ` [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason @ 2021-01-16 21:51 ` Junio C Hamano 2021-01-17 16:47 ` Jeff King 1 sibling, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-16 21:51 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > From: Jeff King <peff@peff.net> > > 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 <peff@peff.net> > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > Commit-message-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> 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 <peff@peff.net> Rewrite a brittle ... Signed-off-by: Jeff King <peff@peff.net> [ÆAB: wrote commit message] Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> e.g. cf. 155067ab4f, a9ecaa06a723, 567ad2c0f9 Thanks. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges". 2021-01-16 15:35 ` [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano @ 2021-01-17 16:47 ` Jeff King 1 sibling, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-17 16:47 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Sat, Jan 16, 2021 at 04:35:49PM +0100, Ævar Arnfjörð Bjarmason wrote: > From: Jeff King <peff@peff.net> > > 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 <peff@peff.net> > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > Commit-message-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> 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: Signed-off-by: Jeff King <peff@peff.net> -Peff ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 07/11] rm tests: actually test for SIGPIPE in SIGPIPE test 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (6 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason ` (3 subsequent siblings) 11 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Change 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). Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t3600-rm.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index efec8d13b6..4f7e62d05c 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (7 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 07/11] rm tests: actually test for SIGPIPE in SIGPIPE test Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 21:48 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason ` (2 subsequent siblings) 11 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index eab966985b..420cf2bbde 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 () { -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status 2021-01-16 15:35 ` [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason @ 2021-01-16 21:48 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-16 21:48 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > 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? > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > --- > t/t5703-upload-pack-ref-in-want.sh | 6 +++++- > 1 file changed, 5 insertions(+), 1 deletion(-) > > diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh > index eab966985b..420cf2bbde 100755 > --- a/t/t5703-upload-pack-ref-in-want.sh > +++ b/t/t5703-upload-pack-ref-in-want.sh > @@ -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 () { ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (8 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-17 17:08 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 10/11] tests: split up bash detection library Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 11 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t5004-archive-corner-cases.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 3e7b23cb32..2d32d0ed12 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -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 ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header 2021-01-16 15:35 ` [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason @ 2021-01-17 17:08 ` Jeff King 0 siblings, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-17 17:08 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Sat, Jan 16, 2021 at 04:35:52PM +0100, Ævar Arnfjörð Bjarmason wrote: > 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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 10/11] tests: split up bash detection library 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (9 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 11 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Split 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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- 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 diff --git a/t/lib-bash-detection.sh b/t/lib-bash-detection.sh new file mode 100644 index 0000000000..8fbdae1d52 --- /dev/null +++ b/t/lib-bash-detection.sh @@ -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 diff --git a/t/lib-bash.sh b/t/lib-bash.sh index b0b6060929..8fd06d2e58 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason ` (10 preceding siblings ...) 2021-01-16 15:35 ` [PATCH v2 10/11] tests: split up bash detection library Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 ` Ævar Arnfjörð Bjarmason 2021-01-20 13:04 ` SZEDER Gábor 2021-01-23 3:46 ` Junio C Hamano 11 siblings, 2 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 15:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. 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/cover.1573779465.git.liu.denton@gmail.com/ 3. https://lore.kernel.org/git/20191115040909.GA21654@sigill.intra.peff.net/ 4. https://github.com/bminor/bash/compare/master...avar:avar/ignore-sigterm-and-sigpipe-on-pipe-fail Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- 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(-) diff --git a/t/README b/t/README index c730a70770..cecc00442d 100644 --- a/t/README +++ b/t/README @@ -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 ------------ diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f4ba2e8c85..38e04b9ce0 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -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 diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh index 4c214bd11c..cc5784a274 100755 --- a/t/t0005-signals.sh +++ b/t/t0005-signals.sh @@ -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" ' diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 4f7e62d05c..7b5d92add5 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 3ebb0d3b65..3adcbce84c 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -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 diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index c4a7758409..947294bebb 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -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 diff --git a/t/test-lib.sh b/t/test-lib.sh index 9fa7c1d0f6..118dc80ffc 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash 2021-01-16 15:35 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason @ 2021-01-20 13:04 ` SZEDER Gábor 2021-01-23 3:46 ` Junio C Hamano 1 sibling, 0 replies; 228+ messages in thread From: SZEDER Gábor @ 2021-01-20 13:04 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine On Sat, Jan 16, 2021 at 04:35:54PM +0100, Ævar Arnfjörð Bjarmason wrote: > 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. > > 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". I'm not sure about adding code to our test framework that only works with a patched shell. > 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/cover.1573779465.git.liu.denton@gmail.com/ > 3. https://lore.kernel.org/git/20191115040909.GA21654@sigill.intra.peff.net/ > 4. https://github.com/bminor/bash/compare/master...avar:avar/ignore-sigterm-and-sigpipe-on-pipe-fail > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> > diff --git a/t/test-lib.sh b/t/test-lib.sh > index 9fa7c1d0f6..118dc80ffc 100644 > --- a/t/test-lib.sh > +++ b/t/test-lib.sh > @@ -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" \ 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 > + --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 > -- > 2.29.2.222.g5d2a92d10f8 > ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash 2021-01-16 15:35 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 2021-01-20 13:04 ` SZEDER Gábor @ 2021-01-23 3:46 ` Junio C Hamano 2021-01-23 7:37 ` Junio C Hamano 2021-01-23 9:40 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 1 sibling, 2 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-23 3:46 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > -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 > diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh > index 4f7e62d05c..7b5d92add5 100755 > --- a/t/t3600-rm.sh > +++ b/t/t3600-rm.sh > @@ -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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash 2021-01-23 3:46 ` Junio C Hamano @ 2021-01-23 7:37 ` Junio C Hamano 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason 2021-01-23 9:40 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 1 sibling, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2021-01-23 7:37 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Denton Liu, Jeff King, Eric Sunshine Junio C Hamano <gitster@pobox.com> writes: > ... > The above have already !MINGW > >> diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh >> index 4f7e62d05c..7b5d92add5 100755 >> --- a/t/t3600-rm.sh >> +++ b/t/t3600-rm.sh >> @@ -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. 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash 2021-01-23 7:37 ` Junio C Hamano @ 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 00/10] Miscellaneous "set -o pipefail"-related test cleanups Ævar Arnfjörð Bjarmason ` (10 more replies) 0 siblings, 11 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 9:32 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Denton Liu, Jeff King, Eric Sunshine On Sat, Jan 23 2021, Junio C Hamano wrote: > Junio C Hamano <gitster@pobox.com> writes: > >> ... >> The above have already !MINGW >> >>> diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh >>> index 4f7e62d05c..7b5d92add5 100755 >>> --- a/t/t3600-rm.sh >>> +++ b/t/t3600-rm.sh >>> @@ -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. > > 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. 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).... > 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... ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 00/10] Miscellaneous "set -o pipefail"-related test cleanups 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 01/10] cache-tree tests: refactor for modern test style Ævar Arnfjörð Bjarmason ` (9 subsequent siblings) 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason This started as an attempt to add a bash "set -o pipefail" test mode, but now comes without that. Junio suggested dropping it in <xmqq5z3o5n8c.fsf@gitster.c.googlers.com>. 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 <87sg6s6lrs.fsf@evledraar.gmail.com>. 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/20150325052952.GE31924@peff.net/ + 3. https://lore.kernel.org/git/YARsCsgXuiXr4uFX@coredump.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> ## 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 <avarab@gmail.com> ## 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. Signed-off-by: Jeff King <peff@peff.net> + [ÆAB: wrote commit message] Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> - Commit-message-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> ## 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/xmqqzh18o8o6.fsf@gitster.c.googlers.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> @@ 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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 01/10] cache-tree tests: refactor for modern test style 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 00/10] Miscellaneous "set -o pipefail"-related test cleanups Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 21:34 ` Junio C Hamano 2021-01-23 13:00 ` [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason ` (8 subsequent siblings) 10 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason Refactor the cache-tree test file to use our current recommended patterns. This makes a subsequent meaningful change easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 5a633690bf..45e1cc82ed 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v3 01/10] cache-tree tests: refactor for modern test style 2021-01-23 13:00 ` [PATCH v3 01/10] cache-tree tests: refactor for modern test style Ævar Arnfjörð Bjarmason @ 2021-01-23 21:34 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-23 21:34 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Jeff King, Denton Liu, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh > index 5a633690bf..45e1cc82ed 100755 > --- a/t/t0090-cache-tree.sh > +++ b/t/t0090-cache-tree.sh > @@ -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. > @@ -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 > ' Why remove only 'before' and not 'expect' in when-finished handler? ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 00/10] Miscellaneous "set -o pipefail"-related test cleanups Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 01/10] cache-tree tests: refactor for modern test style Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 21:35 ` Junio C Hamano 2021-01-23 13:00 ` [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason ` (7 subsequent siblings) 10 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Æ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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 45e1cc82ed..7ff7f04719 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 () { -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter 2021-01-23 13:00 ` [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason @ 2021-01-23 21:35 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-23 21:35 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Jeff King, Denton Liu, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (2 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 21:35 ` Junio C Hamano 2021-01-23 13:00 ` [PATCH v3 04/10] cache-tree tests: explicitly test HEAD and index differences Ævar Arnfjörð Bjarmason ` (6 subsequent siblings) 10 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Æ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. 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/20150325052952.GE31924@peff.net/ 3. https://lore.kernel.org/git/YARsCsgXuiXr4uFX@coredump.intra.peff.net/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 7ff7f04719..5bb4f75443 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection 2021-01-23 13:00 ` [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason @ 2021-01-23 21:35 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2021-01-23 21:35 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Jeff King, Denton Liu, Eric Sunshine Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 04/10] cache-tree tests: explicitly test HEAD and index differences 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (3 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 05/10] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason ` (5 subsequent siblings) 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason 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. 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) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0090-cache-tree.sh | 45 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 5bb4f75443..9bf66c9e68 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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' ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 05/10] git svn mergeinfo tests: modernize redirection & quoting style 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (4 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 04/10] cache-tree tests: explicitly test HEAD and index differences Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 06/10] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty Ævar Arnfjörð Bjarmason ` (4 subsequent siblings) 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Æ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 <avarab@gmail.com> --- t/t9151-svn-mergeinfo.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 4f6c06ecb2..59c5847c5f 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 06/10] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (5 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 05/10] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 07/10] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason ` (3 subsequent siblings) 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason Refactor some old-style test code to use test_must_be_empty instead of "test -z". This makes a follow-up commit easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t9151-svn-mergeinfo.sh | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 59c5847c5f..806eff4023 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 07/10] git-svn tests: rewrite brittle tests to use "--[no-]merges". 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (6 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 06/10] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 08/10] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason ` (2 subsequent siblings) 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason From: Jeff King <peff@peff.net> 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 <peff@peff.net> [ÆAB: wrote commit message] Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t9151-svn-mergeinfo.sh | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 806eff4023..c33bae91fb 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 08/10] upload-pack tests: avoid a non-zero "grep" exit status 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (7 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 07/10] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 09/10] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 10/10] rm tests: actually test for SIGPIPE in SIGPIPE test Ævar Arnfjörð Bjarmason 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason Continue 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/xmqqzh18o8o6.fsf@gitster.c.googlers.com/ Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index eab966985b..5d825b1781 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 () { -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 09/10] archive tests: use a cheaper "zipinfo -h" invocation to get header 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (8 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 08/10] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 10/10] rm tests: actually test for SIGPIPE in SIGPIPE test Ævar Arnfjörð Bjarmason 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Æ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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t5004-archive-corner-cases.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/t/t5004-archive-corner-cases.sh b/t/t5004-archive-corner-cases.sh index 3e7b23cb32..2d32d0ed12 100755 --- a/t/t5004-archive-corner-cases.sh +++ b/t/t5004-archive-corner-cases.sh @@ -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 ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 10/10] rm tests: actually test for SIGPIPE in SIGPIPE test 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason ` (9 preceding siblings ...) 2021-01-23 13:00 ` [PATCH v3 09/10] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 ` Ævar Arnfjörð Bjarmason 10 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 13:00 UTC (permalink / raw) To: git Cc: Junio C Hamano, Jeff King, Denton Liu, Eric Sunshine, Ævar Arnfjörð Bjarmason Change 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/xmqq1rec5ckf.fsf@gitster.c.googlers.com/ 2. 0693f9ddad (Make sure lockfiles are unlocked when dying on SIGPIPE, 2008-12-18) Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t3600-rm.sh | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index efec8d13b6..185e39c390 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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" && -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash 2021-01-23 3:46 ` Junio C Hamano 2021-01-23 7:37 ` Junio C Hamano @ 2021-01-23 9:40 ` Ævar Arnfjörð Bjarmason 1 sibling, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-23 9:40 UTC (permalink / raw) To: Junio C Hamano; +Cc: git, Denton Liu, Jeff King, Eric Sunshine On Sat, Jan 23 2021, Junio C Hamano wrote: > Ævar Arnfjörð Bjarmason <avarab@gmail.com> writes: > >> -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 > >> diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh >> index 4f7e62d05c..7b5d92add5 100755 >> --- a/t/t3600-rm.sh >> +++ b/t/t3600-rm.sh >> @@ -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. I think that makes sense, once I fix the breakage on 07/11 you noted downthread. > 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. > [...]---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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 1/6] test-lib: add tests for test_might_fail 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-15 9:36 ` Jeff King 2021-01-14 23:35 ` [PATCH 2/6] test-lib: add ok=* support to test_might_fail Ævar Arnfjörð Bjarmason ` (4 subsequent siblings) 6 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason 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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0000-basic.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f4ba2e8c85..f90c375fe9 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 1/6] test-lib: add tests for test_might_fail 2021-01-14 23:35 ` [PATCH 1/6] test-lib: add tests for test_might_fail Ævar Arnfjörð Bjarmason @ 2021-01-15 9:36 ` Jeff King 2021-01-16 14:41 ` [PATCH] " Ævar Arnfjörð Bjarmason 0 siblings, 1 reply; 228+ messages in thread From: Jeff King @ 2021-01-15 9:36 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Fri, Jan 15, 2021 at 12:35:10AM +0100, Ævar Arnfjörð Bjarmason wrote: > +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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH] test-lib: add tests for test_might_fail 2021-01-15 9:36 ` Jeff King @ 2021-01-16 14:41 ` Ævar Arnfjörð Bjarmason 2021-01-17 16:48 ` Jeff King 0 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-16 14:41 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason 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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- On Fri, Jan 15 2021, Jeff King wrote: > On Fri, Jan 15, 2021 at 12:35:10AM +0100, Ævar Arnfjörð Bjarmason wrote: > >> +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. 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(+) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f4ba2e8c85..efaf7ec4d9 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH] test-lib: add tests for test_might_fail 2021-01-16 14:41 ` [PATCH] " Ævar Arnfjörð Bjarmason @ 2021-01-17 16:48 ` Jeff King 0 siblings, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-17 16:48 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Sat, Jan 16, 2021 at 03:41:47PM +0100, Ævar Arnfjörð Bjarmason wrote: > > 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. > > 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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 2/6] test-lib: add ok=* support to test_might_fail 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 1/6] test-lib: add tests for test_might_fail Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" Ævar Arnfjörð Bjarmason ` (3 subsequent siblings) 6 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Add the same ok=* support to test_might_fail as its test_must_fail sibling. This will be used to make it accept "sigpipe" failures. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0000-basic.sh | 5 +++++ t/test-lib-functions.sh | 12 +++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index f90c375fe9..fd6cb8d5d3 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -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 diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index 999982fe4a..e01761f7ba 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King ` (2 preceding siblings ...) 2021-01-14 23:35 ` [PATCH 2/6] test-lib: add ok=* support to test_might_fail Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-15 8:15 ` Denton Liu 2021-01-14 23:35 ` [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate Ævar Arnfjörð Bjarmason ` (2 subsequent siblings) 6 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason As 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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- t/t0000-basic.sh | 13 +++++++++++++ t/test-lib-functions.sh | 12 ++++++++++++ 2 files changed, 25 insertions(+) diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index fd6cb8d5d3..930cf9d1b7 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -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 diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index e01761f7ba..f10bd6170a 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" 2021-01-14 23:35 ` [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" Ævar Arnfjörð Bjarmason @ 2021-01-15 8:15 ` Denton Liu 2021-01-15 9:39 ` Ævar Arnfjörð Bjarmason 0 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2021-01-15 8:15 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Jeff King, Eric Sunshine Hi Ævar, First of all, thanks for reviving this series! I hope that Bash accepts your proposed patch because it would definitely be helpful. On Fri, Jan 15, 2021 at 12:35:12AM +0100, Ævar Arnfjörð Bjarmason wrote: > As 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. 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 [0]: https://lore.kernel.org/git/3f79d23b40c0586d0351f4d721097be4f7ba26b8.1573779465.git.liu.denton@gmail.com/ > 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. > > Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" 2021-01-15 8:15 ` Denton Liu @ 2021-01-15 9:39 ` Ævar Arnfjörð Bjarmason 2021-01-15 10:00 ` Jeff King 0 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-15 9:39 UTC (permalink / raw) To: Denton Liu; +Cc: git, Junio C Hamano, Jeff King, Eric Sunshine On Fri, Jan 15 2021, Denton Liu wrote: > 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* > On Fri, Jan 15, 2021 at 12:35:12AM +0100, Ævar Arnfjörð Bjarmason wrote: >> As 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. > > 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 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. > [0]: https://lore.kernel.org/git/3f79d23b40c0586d0351f4d721097be4f7ba26b8.1573779465.git.liu.denton@gmail.com/ > >> 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. >> >> Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" 2021-01-15 9:39 ` Ævar Arnfjörð Bjarmason @ 2021-01-15 10:00 ` Jeff King 0 siblings, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-15 10:00 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: Denton Liu, git, Junio C Hamano, Eric Sunshine On Fri, Jan 15, 2021 at 10:39:17AM +0100, Ævar Arnfjörð Bjarmason wrote: > > Compare > > > > some | test_might_fail ok=sigpipe grep | commands | here > > > > to > > > > 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. 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). > 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 | here > 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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King ` (3 preceding siblings ...) 2021-01-14 23:35 ` [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-15 9:14 ` Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 5/6] tests: split up bash detection library Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 6 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Change 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". Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- 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(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index 5a633690bf..2e69ab138b 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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" && diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index eab966985b..44238b7409 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 () { diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 4f6c06ecb2..dc8491c14a 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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" ] ' -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate 2021-01-14 23:35 ` [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate Ævar Arnfjörð Bjarmason @ 2021-01-15 9:14 ` Ævar Arnfjörð Bjarmason 2021-01-15 9:48 ` Jeff King 0 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-15 9:14 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason On Fri, Jan 15 2021, Ævar Arnfjörð Bjarmason wrote: > 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" ") && > [...] > - 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate 2021-01-15 9:14 ` Ævar Arnfjörð Bjarmason @ 2021-01-15 9:48 ` Jeff King 0 siblings, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-15 9:48 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Fri, Jan 15, 2021 at 10:14:40AM +0100, Ævar Arnfjörð Bjarmason wrote: > > On Fri, Jan 15 2021, Ævar Arnfjörð Bjarmason wrote: > > > 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" ") && > > [...] > > - 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.: diff --git a/t/t9151-svn-mergeinfo.sh b/t/t9151-svn-mergeinfo.sh index 4f6c06ecb2..20dd62c5c4 100755 --- a/t/t9151-svn-mergeinfo.sh +++ b/t/t9151-svn-mergeinfo.sh @@ -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 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH 5/6] tests: split up bash detection library 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King ` (4 preceding siblings ...) 2021-01-14 23:35 ` [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-15 9:42 ` Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 6 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason Split 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. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- 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 diff --git a/t/lib-bash-detection.sh b/t/lib-bash-detection.sh new file mode 100644 index 0000000000..8fbdae1d52 --- /dev/null +++ b/t/lib-bash-detection.sh @@ -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 diff --git a/t/lib-bash.sh b/t/lib-bash.sh index b0b6060929..8fd06d2e58 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 5/6] tests: split up bash detection library 2021-01-14 23:35 ` [PATCH 5/6] tests: split up bash detection library Ævar Arnfjörð Bjarmason @ 2021-01-15 9:42 ` Ævar Arnfjörð Bjarmason 0 siblings, 0 replies; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-15 9:42 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Ævar Arnfjörð Bjarmason On Fri, Jan 15 2021, Ævar Arnfjörð Bjarmason wrote: > +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... ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King ` (5 preceding siblings ...) 2021-01-14 23:35 ` [PATCH 5/6] tests: split up bash detection library Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 ` Ævar Arnfjörð Bjarmason 2021-01-15 10:04 ` Jeff King 6 siblings, 1 reply; 228+ messages in thread From: Ævar Arnfjörð Bjarmason @ 2021-01-14 23:35 UTC (permalink / raw) To: git Cc: Junio C Hamano, Denton Liu, Jeff King, Eric Sunshine, Æ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. 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/cover.1573779465.git.liu.denton@gmail.com/ 3. https://lore.kernel.org/git/20191115040909.GA21654@sigill.intra.peff.net/ 4. https://github.com/bminor/bash/compare/master...avar:avar/ignore-sigterm-and-sigpipe-on-pipe-fail Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> --- 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(-) diff --git a/t/README b/t/README index c730a70770..d9f65bfa6b 100644 --- a/t/README +++ b/t/README @@ -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 ------------ diff --git a/t/t0000-basic.sh b/t/t0000-basic.sh index 930cf9d1b7..e70cc37139 100755 --- a/t/t0000-basic.sh +++ b/t/t0000-basic.sh @@ -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 diff --git a/t/t0005-signals.sh b/t/t0005-signals.sh index 4c214bd11c..cc5784a274 100755 --- a/t/t0005-signals.sh +++ b/t/t0005-signals.sh @@ -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" ' diff --git a/t/t5000-tar-tree.sh b/t/t5000-tar-tree.sh index 3ebb0d3b65..3adcbce84c 100755 --- a/t/t5000-tar-tree.sh +++ b/t/t5000-tar-tree.sh @@ -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 diff --git a/t/t9902-completion.sh b/t/t9902-completion.sh index a1c4f1f6d4..3414ac56f4 100755 --- a/t/t9902-completion.sh +++ b/t/t9902-completion.sh @@ -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 diff --git a/t/test-lib.sh b/t/test-lib.sh index 9fa7c1d0f6..118dc80ffc 100644 --- a/t/test-lib.sh +++ b/t/test-lib.sh @@ -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 -- 2.29.2.222.g5d2a92d10f8 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash 2021-01-14 23:35 ` [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason @ 2021-01-15 10:04 ` Jeff King 0 siblings, 0 replies; 228+ messages in thread From: Jeff King @ 2021-01-15 10:04 UTC (permalink / raw) To: Ævar Arnfjörð Bjarmason Cc: git, Junio C Hamano, Denton Liu, Eric Sunshine On Fri, Jan 15, 2021 at 12:35:15AM +0100, Ævar Arnfjörð Bjarmason wrote: > 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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu ` (27 preceding siblings ...) 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King @ 2019-11-21 0:45 ` Denton Liu 2019-11-21 0:45 ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu ` (21 more replies) 28 siblings, 22 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:45 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King These 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 <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> + + ## 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. + Signed-off-by: Denton Liu <liu.denton@gmail.com> ## 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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu @ 2019-11-21 0:45 ` Denton Liu 2019-11-21 0:45 ` [PATCH v2 02/21] t0014: remove git command upstream of pipe Denton Liu ` (20 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:45 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 2be955fafb..b0b6060929 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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" "$@" -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 02/21] t0014: remove git command upstream of pipe 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-21 0:45 ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu @ 2019-11-21 0:45 ` Denton Liu 2019-11-21 0:45 ` [PATCH v2 03/21] t0090: stop losing return codes of git commands Denton Liu ` (19 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:45 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Before, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 2694c81afd..8d3d9144c0 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -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 ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 03/21] t0090: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-21 0:45 ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-21 0:45 ` [PATCH v2 02/21] t0014: remove git command upstream of pipe Denton Liu @ 2019-11-21 0:45 ` Denton Liu 2019-11-21 0:45 ` [PATCH v2 04/21] t3301: " Denton Liu ` (18 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:45 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index ce9a4a5f32..5a633690bf 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 04/21] t3301: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (2 preceding siblings ...) 2019-11-21 0:45 ` [PATCH v2 03/21] t0090: stop losing return codes of git commands Denton Liu @ 2019-11-21 0:45 ` Denton Liu 2019-11-21 0:45 ` [PATCH v2 05/21] t3600: use test_line_count() where possible Denton Liu ` (17 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:45 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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`. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d66a5f6faa..8f43303007 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -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 <author@example.com> + 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' ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 05/21] t3600: use test_line_count() where possible 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (3 preceding siblings ...) 2019-11-21 0:45 ` [PATCH v2 04/21] t3301: " Denton Liu @ 2019-11-21 0:45 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 06/21] t3600: stop losing return codes of git commands Denton Liu ` (16 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:45 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 8c8cca5bfb..f6e659b7e9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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" ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 06/21] t3600: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (4 preceding siblings ...) 2019-11-21 0:45 ` [PATCH v2 05/21] t3600: use test_line_count() where possible Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu ` (15 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King When 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f6e659b7e9..0c3bf10edd 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 && -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm` 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (5 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 06/21] t3600: stop losing return codes of git commands Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 08/21] t4015: stop losing return codes of git commands Denton Liu ` (14 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Add 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0c3bf10edd..0ea858d652 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 08/21] t4015: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (6 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 09/21] t4015: use test_write_lines() Denton Liu ` (13 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index eadaf57262..7fb83c8eff 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 09/21] t4015: use test_write_lines() 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (7 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 08/21] t4015: stop losing return codes of git commands Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 10/21] t4138: stop losing return codes of git commands Denton Liu ` (12 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Instead of rolling our own method to write out some lines into a file, use the existing test_write_lines(). Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 7fb83c8eff..4c540b1d70 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 10/21] t4138: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (8 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 09/21] t4015: use test_write_lines() Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 11/21] t5317: " Denton Liu ` (11 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t4138-apply-ws-expansion.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 3b636a63a3..b19faeb67a 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 11/21] t5317: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (9 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 10/21] t4138: stop losing return codes of git commands Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu ` (10 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 2d2f5d0229..a8bbad74e2 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 12/21] t5317: use ! grep to check for no matching lines 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (10 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 11/21] t5317: " Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 12:59 ` Eric Sunshine 2019-11-21 0:46 ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu ` (9 subsequent siblings) 21 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 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 <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- 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(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index a8bbad74e2..dc0446574b 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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' ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 12/21] t5317: use ! grep to check for no matching lines 2019-11-21 0:46 ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-21 12:59 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-21 12:59 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King On Wed, Nov 20, 2019 at 7:46 PM Denton Liu <liu.denton@gmail.com> wrote: > 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 > 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]. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > 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... ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 13/21] t5703: simplify one-time-sed generation logic 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (11 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 13:12 ` Eric Sunshine 2019-11-21 0:46 ` [PATCH v2 14/21] t5703: stop losing return codes of git commands Denton Liu ` (8 subsequent siblings) 21 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 3a2c143c6d..88338c4e09 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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' ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v2 13/21] t5703: simplify one-time-sed generation logic 2019-11-21 0:46 ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu @ 2019-11-21 13:12 ` Eric Sunshine 2019-11-21 23:22 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Eric Sunshine @ 2019-11-21 13:12 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King On Wed, Nov 20, 2019 at 7:46 PM Denton Liu <liu.denton@gmail.com> wrote: > In 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. 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. > 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/ ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v2 13/21] t5703: simplify one-time-sed generation logic 2019-11-21 13:12 ` Eric Sunshine @ 2019-11-21 23:22 ` Denton Liu 0 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 23:22 UTC (permalink / raw) To: Eric Sunshine; +Cc: Git Mailing List, Junio C Hamano, Jeff King Hi Eric, On Thu, Nov 21, 2019 at 08:12:00AM -0500, Eric Sunshine wrote: > On Wed, Nov 20, 2019 at 7:46 PM Denton Liu <liu.denton@gmail.com> wrote: > > In 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. > > 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. > > > 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. Will do. Thanks, Denton > > [1]: https://lore.kernel.org/git/CAPig+cTj5qOCFRoD4cZOg7BjVvetQWTgdRHzSvAfgtX2YgUXPg@mail.gmail.com/ ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v2 14/21] t5703: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (12 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 15/21] t7501: remove spaces after redirect operators Denton Liu ` (7 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 88338c4e09..1424fabd4a 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 15/21] t7501: remove spaces after redirect operators 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (13 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 14/21] t5703: stop losing return codes of git commands Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 16/21] t7501: stop losing return codes of git commands Denton Liu ` (6 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index f1349af56e..5765d33c53 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 && -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 16/21] t7501: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (14 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 15/21] t7501: remove spaces after redirect operators Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 17/21] t7700: drop redirections to /dev/null Denton Liu ` (5 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 5765d33c53..110b4bf459 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 17/21] t7700: drop redirections to /dev/null 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (15 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 16/21] t7501: stop losing return codes of git commands Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 18/21] t7700: remove spaces after redirect operators Denton Liu ` (4 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4e855bc21b..e1a689d6a9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 18/21] t7700: remove spaces after redirect operators 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (16 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 17/21] t7700: drop redirections to /dev/null Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 19/21] t7700: move keywords onto their own line Denton Liu ` (3 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index e1a689d6a9..8936928387 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 19/21] t7700: move keywords onto their own line 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (17 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 18/21] t7700: remove spaces after redirect operators Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/ Denton Liu ` (2 subsequent siblings) 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 8936928387..a96e876c4e 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/ 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (18 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 19/21] t7700: move keywords onto their own line Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 21/21] t7700: stop losing return codes of git commands Denton Liu 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a96e876c4e..1d14ddcbdb 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v2 21/21] t7700: stop losing return codes of git commands 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (19 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/ Denton Liu @ 2019-11-21 0:46 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 21 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-21 0:46 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t7700-repack.sh | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddcbdb..ff50722e26 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 ' -- 2.24.0.450.g7a9a4598a9 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (20 preceding siblings ...) 2019-11-21 0:46 ` [PATCH v2 21/21] t7700: stop losing return codes of git commands Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu ` (22 more replies) 21 siblings, 23 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King These 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) Helped-by: Eric Sunshine <sunshine@sunshineco.com> 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 <sunshine@sunshineco.com> ## 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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu ` (21 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 2be955fafb..b0b6060929 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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" "$@" -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 02/22] apply-one-time-sed.sh: modernize style 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-22 18:59 ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-23 1:32 ` Junio C Hamano 2019-11-22 18:59 ` [PATCH v3 03/22] t0014: remove git command upstream of pipe Denton Liu ` (20 subsequent siblings) 22 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Convert `[ ... ]` to use `test`. Move the `then`s 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 <liu.denton@gmail.com> --- t/lib-httpd/apply-one-time-sed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh index fcef728925..3e9a615311 100644 --- a/t/lib-httpd/apply-one-time-sed.sh +++ b/t/lib-httpd/apply-one-time-sed.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v3 02/22] apply-one-time-sed.sh: modernize style 2019-11-22 18:59 ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu @ 2019-11-23 1:32 ` Junio C Hamano 0 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2019-11-23 1:32 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: > Convert `[ ... ]` to use `test`. > > Move the `then`s 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 <liu.denton@gmail.com> > --- > 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. > diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh > index fcef728925..3e9a615311 100644 > --- a/t/lib-httpd/apply-one-time-sed.sh > +++ b/t/lib-httpd/apply-one-time-sed.sh > @@ -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 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 03/22] t0014: remove git command upstream of pipe 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-22 18:59 ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-22 18:59 ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 04/22] t0090: stop losing return codes of git commands Denton Liu ` (19 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Before, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 2694c81afd..8d3d9144c0 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -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 ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 04/22] t0090: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (2 preceding siblings ...) 2019-11-22 18:59 ` [PATCH v3 03/22] t0014: remove git command upstream of pipe Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 05/22] t3301: " Denton Liu ` (18 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index ce9a4a5f32..5a633690bf 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 05/22] t3301: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (3 preceding siblings ...) 2019-11-22 18:59 ` [PATCH v3 04/22] t0090: stop losing return codes of git commands Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 06/22] t3600: use test_line_count() where possible Denton Liu ` (17 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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`. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d66a5f6faa..8f43303007 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -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 <author@example.com> + 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' ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 06/22] t3600: use test_line_count() where possible 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (4 preceding siblings ...) 2019-11-22 18:59 ` [PATCH v3 05/22] t3301: " Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 18:59 ` [PATCH v3 07/22] t3600: stop losing return codes of git commands Denton Liu ` (16 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 8c8cca5bfb..f6e659b7e9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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" ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 07/22] t3600: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (5 preceding siblings ...) 2019-11-22 18:59 ` [PATCH v3 06/22] t3600: use test_line_count() where possible Denton Liu @ 2019-11-22 18:59 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu ` (15 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 18:59 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King When 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f6e659b7e9..0c3bf10edd 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 && -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm` 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (6 preceding siblings ...) 2019-11-22 18:59 ` [PATCH v3 07/22] t3600: stop losing return codes of git commands Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 09/22] t4015: stop losing return codes of git commands Denton Liu ` (14 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Add 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0c3bf10edd..0ea858d652 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 09/22] t4015: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (7 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 10/22] t4015: use test_write_lines() Denton Liu ` (13 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index eadaf57262..7fb83c8eff 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 10/22] t4015: use test_write_lines() 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (8 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 09/22] t4015: stop losing return codes of git commands Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 11/22] t4138: stop losing return codes of git commands Denton Liu ` (12 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Instead of rolling our own method to write out some lines into a file, use the existing test_write_lines(). Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 7fb83c8eff..4c540b1d70 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 11/22] t4138: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (9 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 10/22] t4015: use test_write_lines() Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 12/22] t5317: " Denton Liu ` (11 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t4138-apply-ws-expansion.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 3b636a63a3..b19faeb67a 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 12/22] t5317: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (10 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 11/22] t4138: stop losing return codes of git commands Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu ` (10 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 2d2f5d0229..a8bbad74e2 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 13/22] t5317: use ! grep to check for no matching lines 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (11 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 12/22] t5317: " Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-23 6:21 ` Eric Sunshine 2019-11-22 19:00 ` [PATCH v3 14/22] t5703: simplify one-time-sed generation logic Denton Liu ` (9 subsequent siblings) 22 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 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) Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index a8bbad74e2..dc0446574b 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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' ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v3 13/22] t5317: use ! grep to check for no matching lines 2019-11-22 19:00 ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-23 6:21 ` Eric Sunshine 2019-11-25 21:43 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Eric Sunshine @ 2019-11-23 6:21 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King On Fri, Nov 22, 2019 at 2:00 PM Denton Liu <liu.denton@gmail.com> wrote: > [...] > 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/ ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v3 13/22] t5317: use ! grep to check for no matching lines 2019-11-23 6:21 ` Eric Sunshine @ 2019-11-25 21:43 ` Denton Liu 0 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-25 21:43 UTC (permalink / raw) To: Eric Sunshine; +Cc: Git Mailing List, Junio C Hamano, Jeff King Hi Eric, On Sat, Nov 23, 2019 at 01:21:29AM -0500, Eric Sunshine wrote: > On Fri, Nov 22, 2019 at 2:00 PM Denton Liu <liu.denton@gmail.com> wrote: > > [...] > > 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. 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 > > [1]: https://lore.kernel.org/git/CAPig+cQviTjwLSZ+QkC62B58mq6z3yDA-XhPVJQYRq0inEo9nA@mail.gmail.com/ ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v3 14/22] t5703: simplify one-time-sed generation logic 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (12 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 15/22] t5703: stop losing return codes of git commands Denton Liu ` (8 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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`. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 3a2c143c6d..88338c4e09 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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' ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 15/22] t5703: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (13 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 14/22] t5703: simplify one-time-sed generation logic Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 16/22] t7501: remove spaces after redirect operators Denton Liu ` (7 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 88338c4e09..1424fabd4a 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 16/22] t7501: remove spaces after redirect operators 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (14 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 15/22] t5703: stop losing return codes of git commands Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 17/22] t7501: stop losing return codes of git commands Denton Liu ` (6 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index f1349af56e..5765d33c53 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 && -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 17/22] t7501: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (15 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 16/22] t7501: remove spaces after redirect operators Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 18/22] t7700: drop redirections to /dev/null Denton Liu ` (5 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 5765d33c53..110b4bf459 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 18/22] t7700: drop redirections to /dev/null 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (16 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 17/22] t7501: stop losing return codes of git commands Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 19/22] t7700: remove spaces after redirect operators Denton Liu ` (4 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4e855bc21b..e1a689d6a9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 19/22] t7700: remove spaces after redirect operators 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (17 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 18/22] t7700: drop redirections to /dev/null Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 20/22] t7700: move keywords onto their own line Denton Liu ` (3 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index e1a689d6a9..8936928387 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 20/22] t7700: move keywords onto their own line 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (18 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 19/22] t7700: remove spaces after redirect operators Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/ Denton Liu ` (2 subsequent siblings) 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 8936928387..a96e876c4e 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/ 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (19 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 20/22] t7700: move keywords onto their own line Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 22 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a96e876c4e..1d14ddcbdb 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v3 22/22] t7700: stop losing return codes of git commands 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (20 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/ Denton Liu @ 2019-11-22 19:00 ` Denton Liu 2019-11-23 1:49 ` Junio C Hamano 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 22 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-22 19:00 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t7700-repack.sh | 64 ++++++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 26 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddcbdb..ff50722e26 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 ' -- 2.24.0.497.g17aadd8971 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands 2019-11-22 19:00 ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu @ 2019-11-23 1:49 ` Junio C Hamano 2019-11-25 23:57 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-11-23 1:49 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: > - 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. > @@ -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). > @@ -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. > + 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'). > @@ -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 > ' Likewise. > @@ -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 > ' Likewise. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands 2019-11-23 1:49 ` Junio C Hamano @ 2019-11-25 23:57 ` Denton Liu 2019-11-26 0:58 ` Eric Sunshine 0 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-25 23:57 UTC (permalink / raw) To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King Hi Junio, On Sat, Nov 23, 2019 at 10:49:44AM +0900, Junio C Hamano wrote: > Denton Liu <liu.denton@gmail.com> writes: > > > - 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands 2019-11-25 23:57 ` Denton Liu @ 2019-11-26 0:58 ` Eric Sunshine 2019-11-26 1:34 ` Junio C Hamano 0 siblings, 1 reply; 228+ messages in thread From: Eric Sunshine @ 2019-11-26 0:58 UTC (permalink / raw) To: Denton Liu; +Cc: Junio C Hamano, Git Mailing List, Jeff King On Mon, Nov 25, 2019 at 6:57 PM Denton Liu <liu.denton@gmail.com> wrote: > On Sat, Nov 23, 2019 at 10:49:44AM +0900, Junio C Hamano wrote: > > Denton Liu <liu.denton@gmail.com> writes: > > > - 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. 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). ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands 2019-11-26 0:58 ` Eric Sunshine @ 2019-11-26 1:34 ` Junio C Hamano 2019-11-26 4:47 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-11-26 1:34 UTC (permalink / raw) To: Eric Sunshine; +Cc: Denton Liu, Git Mailing List, Jeff King Eric Sunshine <sunshine@sunshineco.com> writes: > 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. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v3 22/22] t7700: stop losing return codes of git commands 2019-11-26 1:34 ` Junio C Hamano @ 2019-11-26 4:47 ` Denton Liu 0 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 4:47 UTC (permalink / raw) To: Junio C Hamano; +Cc: Eric Sunshine, Git Mailing List, Jeff King Hi Junio and Eric, On Tue, Nov 26, 2019 at 10:34:48AM +0900, Junio C Hamano wrote: > Eric Sunshine <sunshine@sunshineco.com> writes: > > > 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. > > 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 > > Thanks. > > ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (21 preceding siblings ...) 2019-11-22 19:00 ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu ` (27 more replies) 22 siblings, 28 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King These 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 `then`s 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) Helped-by: Eric Sunshine <sunshine@sunshineco.com> 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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 02/27] apply-one-time-sed.sh: modernize style Denton Liu ` (26 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 2be955fafb..b0b6060929 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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" "$@" -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 02/27] apply-one-time-sed.sh: modernize style 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-26 1:17 ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 03/27] t0014: remove git command upstream of pipe Denton Liu ` (25 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Convert `[ ... ]` to use `test` and test for the existence of a regular file (`-f`) instead of any file (`-e`). Move the `then`s 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-httpd/apply-one-time-sed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh index fcef728925..bf7689d020 100644 --- a/t/lib-httpd/apply-one-time-sed.sh +++ b/t/lib-httpd/apply-one-time-sed.sh @@ -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 -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 cmp -s out out_modified + then cat out else cat out_modified -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 03/27] t0014: remove git command upstream of pipe 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-26 1:17 ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-26 1:17 ` [PATCH v4 02/27] apply-one-time-sed.sh: modernize style Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 04/27] t0090: stop losing return codes of git commands Denton Liu ` (24 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Before, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 2694c81afd..8d3d9144c0 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 04/27] t0090: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (2 preceding siblings ...) 2019-11-26 1:17 ` [PATCH v4 03/27] t0014: remove git command upstream of pipe Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 05/27] t3301: " Denton Liu ` (23 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index ce9a4a5f32..5a633690bf 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 05/27] t3301: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (3 preceding siblings ...) 2019-11-26 1:17 ` [PATCH v4 04/27] t0090: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 06/27] t3600: use test_line_count() where possible Denton Liu ` (22 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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`. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d66a5f6faa..8f43303007 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -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 <author@example.com> + 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' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 06/27] t3600: use test_line_count() where possible 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (4 preceding siblings ...) 2019-11-26 1:17 ` [PATCH v4 05/27] t3301: " Denton Liu @ 2019-11-26 1:17 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 07/27] t3600: stop losing return codes of git commands Denton Liu ` (21 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:17 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 8c8cca5bfb..f6e659b7e9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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" ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 07/27] t3600: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (5 preceding siblings ...) 2019-11-26 1:17 ` [PATCH v4 06/27] t3600: use test_line_count() where possible Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu ` (20 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King When 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f6e659b7e9..0c3bf10edd 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 && -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm` 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (6 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 07/27] t3600: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 09/27] t4015: stop losing return codes of git commands Denton Liu ` (19 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Add 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0c3bf10edd..0ea858d652 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 09/27] t4015: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (7 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 10/27] t4015: use test_write_lines() Denton Liu ` (18 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index eadaf57262..7fb83c8eff 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 10/27] t4015: use test_write_lines() 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (8 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 09/27] t4015: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 11/27] t4138: stop losing return codes of git commands Denton Liu ` (17 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Instead of rolling our own method to write out some lines into a file, use the existing test_write_lines(). Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 7fb83c8eff..4c540b1d70 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 11/27] t4138: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (9 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 10/27] t4015: use test_write_lines() Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 12/27] t5317: " Denton Liu ` (16 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t4138-apply-ws-expansion.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 3b636a63a3..b19faeb67a 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 12/27] t5317: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (10 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 11/27] t4138: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 13/27] t5317: use ! grep to check for no matching lines Denton Liu ` (15 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 2d2f5d0229..a8bbad74e2 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 13/27] t5317: use ! grep to check for no matching lines 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (11 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 12/27] t5317: " Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 14/27] t5703: simplify one-time-sed generation logic Denton Liu ` (14 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 are no matching lines. While at it, drop unnecessary invocations of `awk` and `sort` in each affected test since those commands do not influence the outcome. It's not clear why that extra work was being done in the first place, and the code's history doesn't shed any light on the matter since these tests were simply born this way[1], likely due to copy-paste programming. The unnecessary work wasn't noticed even when the code was later touched for various cleanups[2][3]. [1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21) [2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05) [3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05) Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index a8bbad74e2..dc0446574b 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 14/27] t5703: simplify one-time-sed generation logic 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (12 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 13/27] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 15/27] t5703: stop losing return codes of git commands Denton Liu ` (13 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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`. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 3a2c143c6d..88338c4e09 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 15/27] t5703: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (13 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 14/27] t5703: simplify one-time-sed generation logic Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 16/27] t7501: remove spaces after redirect operators Denton Liu ` (12 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 88338c4e09..1424fabd4a 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 16/27] t7501: remove spaces after redirect operators 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (14 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 15/27] t5703: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 17/27] t7501: stop losing return codes of git commands Denton Liu ` (11 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index f1349af56e..5765d33c53 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 && -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 17/27] t7501: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (15 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 16/27] t7501: remove spaces after redirect operators Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 18/27] t7700: drop redirections to /dev/null Denton Liu ` (10 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 5765d33c53..110b4bf459 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 18/27] t7700: drop redirections to /dev/null 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (16 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 17/27] t7501: stop losing return codes of git commands Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 19/27] t7700: remove spaces after redirect operators Denton Liu ` (9 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4e855bc21b..e1a689d6a9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 19/27] t7700: remove spaces after redirect operators 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (17 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 18/27] t7700: drop redirections to /dev/null Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 20/27] t7700: move keywords onto their own line Denton Liu ` (8 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index e1a689d6a9..8936928387 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 20/27] t7700: move keywords onto their own line 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (18 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 19/27] t7700: remove spaces after redirect operators Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/ Denton Liu ` (7 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 8936928387..a96e876c4e 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/ 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (19 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 20/27] t7700: move keywords onto their own line Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu ` (6 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a96e876c4e..1d14ddcbdb 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (20 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/ Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 2:35 ` Eric Sunshine 2019-11-26 1:18 ` [PATCH v4 23/27] squash! " Denton Liu ` (5 subsequent siblings) 27 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead. Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to use sort the files then use `comm -23` so that finding missing lines from the original file is done more efficiently. While we're at it, add a space to `commit_and_pack ()` for style. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 59 +++++++++++++++-------------------------------- 1 file changed, 19 insertions(+), 40 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddcbdb..a6c3d34277 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -4,12 +4,27 @@ test_description='git repack works correctly' . ./test-lib.sh -commit_and_pack() { +commit_and_pack () { test_commit "$@" 1>&2 && SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && echo pack-${SHA1}.pack } +test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && + for p in alt_objects/pack/*.idx + do + git verify-pack -v $p >packlist || return $? + grep "^[0-9a-f]\{40\}" packlist + done >orig.raw && + cut -d" " -f1 orig.raw | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && + test_must_be_empty missing +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 && @@ -105,19 +120,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is mkdir alt_objects/pack && mv .git/objects/pack/* alt_objects/pack && git repack -a && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' ' @@ -128,19 +131,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git commit -m more_content && git repack && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' @@ -156,19 +147,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' fi done && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() 2019-11-26 1:18 ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu @ 2019-11-26 2:35 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-26 2:35 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King On Mon, Nov 25, 2019 at 8:21 PM Denton Liu <liu.denton@gmail.com> wrote: > The code to test that objects were not missing from the packfile was > duplicated many times. Extract the duplicated code into > test_no_missing_in_packs() and use that instead. > > Refactor the resulting extraction so that if any git commands fail, > their return codes are not silently lost. > > We were using sed to filter lines. Although not incorrect, this is > exactly what grep is built for. Replace this invocation of sed with grep > so that we use the correct tool for the job. > > The original testing construct was O(n^2): it used a grep in a loop to > test whether any objects were missing in the packfile. Rewrite this to > use sort the files then use `comm -23` so that finding missing lines s/use sort/sort/ > from the original file is done more efficiently. > > While we're at it, add a space to `commit_and_pack ()` for style. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v4 23/27] squash! t7700: consolidate code into test_no_missing_in_packs() 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (21 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object() Denton Liu ` (4 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- Notes: We should probably squash this in but before we do this, I'd like some confirmation that doing this doesn't have any negative impacts. t/t7700-repack.sh | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a6c3d34277..4bcd9fcc80 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -13,12 +13,8 @@ commit_and_pack () { test_no_missing_in_packs () { myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p >packlist || return $? - grep "^[0-9a-f]\{40\}" packlist - done >orig.raw && - cut -d" " -f1 orig.raw | sort >orig && + git verify-pack -v alt_objects/pack/*.idx >orig.raw && + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object() 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (22 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 23/27] squash! " Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 25/27] t7700: replace egrep with grep Denton Liu ` (3 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead. Refactor the resulting extraction so that if the git command fails, the return code is not silently lost. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 71 +++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4bcd9fcc80..5bbed02fe5 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -21,6 +21,25 @@ test_no_missing_in_packs () { test_must_be_empty missing } +# we expect $packsha1 and $objsha1 to be defined +test_has_duplicate_object () { + want_duplicate_object="$1" + found_duplicate_object=false + for p in .git/objects/pack/*.idx + do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist + then + found_duplicate_object=true + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$want_duplicate_object" = "$found_duplicate_object" +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 && @@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git repack -Adbl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'loose objects in alternate ODB are not repacked' ' @@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git commit -m commit_file3 && git repack -a -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 25/27] t7700: replace egrep with grep 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (23 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object() Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 1:18 ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu ` (2 subsequent siblings) 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The egrep expressions in this test suite were of the form `^$variable`. Although egrep works just fine, it's overkill since we're not using any extended regex. Replace egrep invocations with grep so that we aren't swatting flies with a sledgehammer. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 5bbed02fe5..2493cc4e9b 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -30,7 +30,7 @@ test_has_duplicate_object () { idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if egrep "^$objsha1" packlist + if grep "^$objsha1" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' @@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v4 26/27] t7700: make references to SHA-1 generic 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (24 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 25/27] t7700: replace egrep with grep Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-26 3:15 ` Eric Sunshine 2019-11-26 1:18 ` [PATCH v4 27/27] t7700: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 27 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Make the test more hash-agnostic by renaming variables from "sha1" to "oid" (case-insensitively). Also, replace the regex, `[0-9a-f]\{40\}` with `$OID_REGEX`. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 2493cc4e9b..d96b1a5949 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -6,31 +6,31 @@ test_description='git repack works correctly' commit_and_pack () { test_commit "$@" 1>&2 && - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && - echo pack-${SHA1}.pack + OID=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && + echo pack-${OID}.pack } test_no_missing_in_packs () { myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && git verify-pack -v alt_objects/pack/*.idx >orig.raw && - grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && + grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && test_must_be_empty missing } -# we expect $packsha1 and $objsha1 to be defined +# we expect $packoid and $objoid to be defined test_has_duplicate_object () { want_duplicate_object="$1" found_duplicate_object=false for p in .git/objects/pack/*.idx do idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue + test "pack-$packoid.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if grep "^$objsha1" packlist + if grep "^$objoid" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git rev-list --objects --all | grep -v file2 | git pack-objects pack && # The second pack will contain the excluded object - packsha1=$(git rev-list --objects --all | grep file2 | + packoid=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - >pack-$packsha1.keep && - objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + >pack-$packoid.keep && + objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 | + sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && @@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $objoid, $packoid, and .keep state from previous git repack -Adbl && test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $objoid, $packoid, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_has_duplicate_object true ' @@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo $(pwd)/alt_objects >.git/objects/info/alternates && echo content3 >file3 && - objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && + objoid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick && git commit -m commit_file3 && @@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f alt_objects/pack/*.keep && mv .git/objects/pack/* alt_objects/pack/ && - csha1=$(git rev-parse HEAD^{commit}) && + coid=$(git rev-parse HEAD^{commit}) && git reset --hard HEAD^ && test_tick && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && @@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' echo $(pwd)/alt_objects >.git/objects/info/alternates && - echo "$csha1" | git pack-objects --non-empty --all --reflog pack && + echo "$coid" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && # The pack-objects call on the next line is equivalent to @@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'objects made unreachable by grafts only are kept' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v4 26/27] t7700: make references to SHA-1 generic 2019-11-26 1:18 ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu @ 2019-11-26 3:15 ` Eric Sunshine 0 siblings, 0 replies; 228+ messages in thread From: Eric Sunshine @ 2019-11-26 3:15 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Junio C Hamano, Jeff King On Mon, Nov 25, 2019 at 8:22 PM Denton Liu <liu.denton@gmail.com> wrote: > Make the test more hash-agnostic by renaming variables from "sha1" to > "oid" (case-insensitively). Also, replace the regex, `[0-9a-f]\{40\}` > with `$OID_REGEX`. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > --- > diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh > @@ -6,31 +6,31 @@ test_description='git repack works correctly' > commit_and_pack () { > test_commit "$@" 1>&2 && > - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && > - echo pack-${SHA1}.pack > + OID=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && > + echo pack-${OID}.pack > } Meh. OID stands for "object ID". However, in this context, SHA1 is a computed hash value -- a checksum -- not the ID of an object. So, calling this an OID is confusing (IMHO). By the way, the uppercase "SHA1" gives the impression that this value is global to the script, but it is, in fact, used only in this function, so it would be clearer to downcase the entire name, implying by convention that it is a local variable. Taking both observations into consideration, a better name might be "packid". > -# we expect $packsha1 and $objsha1 to be defined > +# we expect $packoid and $objoid to be defined Likewise. By using "oid" in these names, you're calling these values "pack object ID" and "object object ID", respectively, which doesn't make much sense. Perhaps "packid" and simply "oid" would be better names. Same comment applies to remaining changes in this patch. > @@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' > test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' > rm -f alt_objects/pack/*.keep && > mv .git/objects/pack/* alt_objects/pack/ && > - csha1=$(git rev-parse HEAD^{commit}) && > + coid=$(git rev-parse HEAD^{commit}) && This is indeed an object ID, so replacing literal "sha1" with "oid" makes sense. ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v4 27/27] t7700: stop losing return codes of git commands 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (25 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu @ 2019-11-26 1:18 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 27 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-26 1:18 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t7700-repack.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index d96b1a5949..93b20bb7a8 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git commit -m initial_commit && # Create two packs # The first pack will contain all of the objects except one - git rev-list --objects --all | grep -v file2 | - git pack-objects pack && + git rev-list --objects --all >objs && + grep -v file2 objs | git pack-objects pack && # The second pack will contain the excluded object - packoid=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packoid=$(grep file2 objs | git pack-objects pack) && >pack-$packoid.keep && - objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 | - sed -e "s/^\($OID_REGEX\).*/\1/") && + git verify-pack -v pack-$packoid.idx >packlist && + objoid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && @@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " packlist && echo >.git/objects/info/alternates && test_must_fail git show $coid ' @@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " && echo >.git/objects/info/alternates && test_must_fail git show $coid ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (26 preceding siblings ...) 2019-11-26 1:18 ` [PATCH v4 27/27] t7700: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu ` (25 more replies) 27 siblings, 26 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King These 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 v4: * Squash in "squash! t7700: consolidate code into test_no_missing_in_packs()" * Fix typo in "t7700: consolidate code into test_no_missing_in_packs()" * Use "oid" and "packid" instead of "objoid" and "packoid" in "t7700: make references to SHA-1 generic" 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 (26): 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() 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 v4: 1: d5e769af39 = 1: 9085cc00af lib-bash.sh: move `then` onto its own line 2: 31434dfb4b = 2: 86f625c65e apply-one-time-sed.sh: modernize style 3: e4443a6358 = 3: 3844e00367 t0014: remove git command upstream of pipe 4: 712354f90c = 4: 7d33586b21 t0090: stop losing return codes of git commands 5: adef902872 = 5: df6b3393c4 t3301: stop losing return codes of git commands 6: a79cfe261a = 6: d541a8d4d4 t3600: use test_line_count() where possible 7: bfbb8bde3a = 7: a8aeca6795 t3600: stop losing return codes of git commands 8: 714da9e618 = 8: e3db06578d t3600: comment on inducing SIGPIPE in `git rm` 9: 4d5f40f3b0 = 9: 22ea5d736e t4015: stop losing return codes of git commands 10: 68ed9ba7b6 = 10: a44dd28b4d t4015: use test_write_lines() 11: c1ce767a98 = 11: d512319be0 t4138: stop losing return codes of git commands 12: b5fa2ddb87 = 12: 1e08c2b68b t5317: stop losing return codes of git commands 13: 000126915e = 13: fa238be28b t5317: use ! grep to check for no matching lines 14: e18ab06152 = 14: 291caf9bc1 t5703: simplify one-time-sed generation logic 15: 42b63b4735 = 15: edf7af76ae t5703: stop losing return codes of git commands 16: e816d6e18d = 16: 5eb7117fbe t7501: remove spaces after redirect operators 17: 6147ec6e8f = 17: bad732adc8 t7501: stop losing return codes of git commands 18: 7013c3a3c7 = 18: c50c192429 t7700: drop redirections to /dev/null 19: f421b35adb = 19: 58ae066d12 t7700: remove spaces after redirect operators 20: 7b8d5767fb = 20: 82bf24d06a t7700: move keywords onto their own line 21: dafc8da2d2 = 21: 251de77677 t7700: s/test -f/test_path_is_file/ 22: 1e8f239080 ! 22: a99a45cb6f t7700: consolidate code into test_no_missing_in_packs() @@ Commit message exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job. + Instead of verifying each file of `alt_objects/pack/*.idx` individually + in a for-loop, batch them together into one verification step. + The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to - use sort the files then use `comm -23` so that finding missing lines - from the original file is done more efficiently. + sort the files then use `comm -23` so that finding missing lines from + the original file is done more efficiently. While we're at it, add a space to `commit_and_pack ()` for style. @@ t/t7700-repack.sh: test_description='git repack works correctly' +test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && -+ for p in alt_objects/pack/*.idx -+ do -+ git verify-pack -v $p >packlist || return $? -+ grep "^[0-9a-f]\{40\}" packlist -+ done >orig.raw && -+ cut -d" " -f1 orig.raw | sort >orig && ++ git verify-pack -v alt_objects/pack/*.idx >orig.raw && ++ grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && 23: 4b70b92e1d < -: ---------- squash! t7700: consolidate code into test_no_missing_in_packs() 24: b0e58908d9 = 23: f79240e937 t7700: consolidate code into test_has_duplicate_object() 25: 6bd266035f = 24: 632a62f6e9 t7700: replace egrep with grep 26: 8193fee859 ! 25: bf70cc5a0d t7700: make references to SHA-1 generic @@ Commit message t7700: make references to SHA-1 generic Make the test more hash-agnostic by renaming variables from "sha1" to - "oid" (case-insensitively). Also, replace the regex, `[0-9a-f]\{40\}` - with `$OID_REGEX`. + some variation of "oid" or "packid". Also, replace the regex, + `[0-9a-f]\{40\}` with `$OID_REGEX`. + + A better name for "incrpackid" (incremental pack-id) might have been + just "packid". However, later in the test suite, we have other uses of + "packid". Although the scopes of these variables don't conflict, a + future developer may think that commit_and_pack() and + test_has_duplicate_object() are semantically related somehow since they + share the same variable name. Give them distinct names so that it's + clear these uses are unrelated. ## t/t7700-repack.sh ## @@ t/t7700-repack.sh: test_description='git repack works correctly' @@ t/t7700-repack.sh: test_description='git repack works correctly' test_commit "$@" 1>&2 && - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && - echo pack-${SHA1}.pack -+ OID=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && -+ echo pack-${OID}.pack ++ incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && ++ echo pack-${incrpackid}.pack } test_no_missing_in_packs () { @@ t/t7700-repack.sh: test_description='git repack works correctly' } -# we expect $packsha1 and $objsha1 to be defined -+# we expect $packoid and $objoid to be defined ++# we expect $packid and $oid to be defined test_has_duplicate_object () { want_duplicate_object="$1" found_duplicate_object=false @@ t/t7700-repack.sh: test_description='git repack works correctly' do idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue -+ test "pack-$packoid.idx" = "$idx" && continue ++ test "pack-$packid.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if grep "^$objsha1" packlist -+ if grep "^$objoid" packlist ++ if grep "^$oid" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ t/t7700-repack.sh: test_expect_success 'objects in packs marked .keep are not re git pack-objects pack && # The second pack will contain the excluded object - packsha1=$(git rev-list --objects --all | grep file2 | -+ packoid=$(git rev-list --objects --all | grep file2 | ++ packid=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - >pack-$packsha1.keep && - objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && -+ >pack-$packoid.keep && -+ objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 | ++ >pack-$packid.keep && ++ oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | + sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && @@ t/t7700-repack.sh: test_expect_success 'objects in packs marked .keep are not re test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous -+ # build on $objoid, $packoid, and .keep state from previous ++ # build on $oid, $packid, and .keep state from previous git repack -Adbl && test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous -+ # build on $objoid, $packoid, and .keep state from previous ++ # build on $oid, $packid, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_has_duplicate_object true ' @@ t/t7700-repack.sh: test_expect_success 'loose objects in alternate ODB are not r echo $(pwd)/alt_objects >.git/objects/info/alternates && echo content3 >file3 && - objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && -+ objoid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && ++ oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick && git commit -m commit_file3 && 27: 456aeaa506 ! 26: 1f6d9a80ad t7700: stop losing return codes of git commands @@ t/t7700-repack.sh: test_expect_success 'objects in packs marked .keep are not re + git rev-list --objects --all >objs && + grep -v file2 objs | git pack-objects pack && # The second pack will contain the excluded object -- packoid=$(git rev-list --objects --all | grep file2 | +- packid=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && -+ packoid=$(grep file2 objs | git pack-objects pack) && - >pack-$packoid.keep && -- objoid=$(git verify-pack -v pack-$packoid.idx | head -n 1 | ++ packid=$(grep file2 objs | git pack-objects pack) && + >pack-$packid.keep && +- oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | - sed -e "s/^\($OID_REGEX\).*/\1/") && -+ git verify-pack -v pack-$packoid.idx >packlist && -+ objoid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && ++ git verify-pack -v pack-$packid.idx >packlist && ++ oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 02/26] apply-one-time-sed.sh: modernize style Denton Liu ` (24 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-bash.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 2be955fafb..b0b6060929 100644 --- a/t/lib-bash.sh +++ b/t/lib-bash.sh @@ -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" "$@" -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 02/26] apply-one-time-sed.sh: modernize style 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-27 19:53 ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 03/26] t0014: remove git command upstream of pipe Denton Liu ` (23 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Convert `[ ... ]` to use `test` and test for the existence of a regular file (`-f`) instead of any file (`-e`). Move the `then`s 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/lib-httpd/apply-one-time-sed.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh index fcef728925..bf7689d020 100644 --- a/t/lib-httpd/apply-one-time-sed.sh +++ b/t/lib-httpd/apply-one-time-sed.sh @@ -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 -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 cmp -s out out_modified + then cat out else cat out_modified -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 03/26] t0014: remove git command upstream of pipe 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-27 19:53 ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-27 19:53 ` [PATCH v5 02/26] apply-one-time-sed.sh: modernize style Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 04/26] t0090: stop losing return codes of git commands Denton Liu ` (22 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Before, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0014-alias.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 2694c81afd..8d3d9144c0 100755 --- a/t/t0014-alias.sh +++ b/t/t0014-alias.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 04/26] t0090: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (2 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 03/26] t0014: remove git command upstream of pipe Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 05/26] t3301: " Denton Liu ` (21 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t0090-cache-tree.sh | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index ce9a4a5f32..5a633690bf 100755 --- a/t/t0090-cache-tree.sh +++ b/t/t0090-cache-tree.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 05/26] t3301: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (3 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 04/26] t0090: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 06/26] t3600: use test_line_count() where possible Denton Liu ` (20 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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`. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3301-notes.sh | 230 +++++++++++++++++++++++++++++++++-------------- 1 file changed, 163 insertions(+), 67 deletions(-) diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d66a5f6faa..8f43303007 100755 --- a/t/t3301-notes.sh +++ b/t/t3301-notes.sh @@ -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 <author@example.com> + 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' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 06/26] t3600: use test_line_count() where possible 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (4 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 05/26] t3301: " Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 07/26] t3600: stop losing return codes of git commands Denton Liu ` (19 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 8c8cca5bfb..f6e659b7e9 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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" ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 07/26] t3600: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (5 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 06/26] t3600: use test_line_count() where possible Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu ` (18 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King When 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f6e659b7e9..0c3bf10edd 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 && -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm` 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (6 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 07/26] t3600: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 09/26] t4015: stop losing return codes of git commands Denton Liu ` (17 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Add 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t3600-rm.sh | 1 + 1 file changed, 1 insertion(+) diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0c3bf10edd..0ea858d652 100755 --- a/t/t3600-rm.sh +++ b/t/t3600-rm.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 09/26] t4015: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (7 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 10/26] t4015: use test_write_lines() Denton Liu ` (16 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 119 ++++++++++++++++++++++--------------- 1 file changed, 72 insertions(+), 47 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index eadaf57262..7fb83c8eff 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 10/26] t4015: use test_write_lines() 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (8 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 09/26] t4015: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 11/26] t4138: stop losing return codes of git commands Denton Liu ` (15 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Instead of rolling our own method to write out some lines into a file, use the existing test_write_lines(). Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t4015-diff-whitespace.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 7fb83c8eff..4c540b1d70 100755 --- a/t/t4015-diff-whitespace.sh +++ b/t/t4015-diff-whitespace.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 11/26] t4138: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (9 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 10/26] t4015: use test_write_lines() Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 12/26] t5317: " Denton Liu ` (14 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t4138-apply-ws-expansion.sh | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 3b636a63a3..b19faeb67a 100755 --- a/t/t4138-apply-ws-expansion.sh +++ b/t/t4138-apply-ws-expansion.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 12/26] t5317: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (10 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 11/26] t4138: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 13/26] t5317: use ! grep to check for no matching lines Denton Liu ` (13 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 2d2f5d0229..a8bbad74e2 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 13/26] t5317: use ! grep to check for no matching lines 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (11 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 12/26] t5317: " Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 14/26] t5703: simplify one-time-sed generation logic Denton Liu ` (12 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 are no matching lines. While at it, drop unnecessary invocations of `awk` and `sort` in each affected test since those commands do not influence the outcome. It's not clear why that extra work was being done in the first place, and the code's history doesn't shed any light on the matter since these tests were simply born this way[1], likely due to copy-paste programming. The unnecessary work wasn't noticed even when the code was later touched for various cleanups[2][3]. [1]: 9535ce7337 (pack-objects: add list-objects filtering, 2017-11-21) [2]: bdbc17e86a (tests: standardize pipe placement, 2018-10-05) [3]: 61de0ff695 (tests: don't swallow Git errors upstream of pipes, 2018-10-05) Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5317-pack-objects-filter-objects.sh | 21 +++------------------ 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index a8bbad74e2..dc0446574b 100755 --- a/t/t5317-pack-objects-filter-objects.sh +++ b/t/t5317-pack-objects-filter-objects.sh @@ -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' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 14/26] t5703: simplify one-time-sed generation logic 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (12 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 13/26] t5317: use ! grep to check for no matching lines Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 15/26] t5703: stop losing return codes of git commands Denton Liu ` (11 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King In 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`. Helped-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 3a2c143c6d..88338c4e09 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 15/26] t5703: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (13 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 14/26] t5703: simplify one-time-sed generation logic Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 16/26] t7501: remove spaces after redirect operators Denton Liu ` (10 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Currently, 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t5703-upload-pack-ref-in-want.sh | 46 +++++++++++++++++++----------- 1 file changed, 29 insertions(+), 17 deletions(-) diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 88338c4e09..1424fabd4a 100755 --- a/t/t5703-upload-pack-ref-in-want.sh +++ b/t/t5703-upload-pack-ref-in-want.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 16/26] t7501: remove spaces after redirect operators 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (14 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 15/26] t5703: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 17/26] t7501: stop losing return codes of git commands Denton Liu ` (9 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index f1349af56e..5765d33c53 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 && -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 17/26] t7501: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (15 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 16/26] t7501: remove spaces after redirect operators Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 18/26] t7700: drop redirections to /dev/null Denton Liu ` (8 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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. 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7501-commit-basic-functionality.sh | 69 +++++++++++++++------------ 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 5765d33c53..110b4bf459 100755 --- a/t/t7501-commit-basic-functionality.sh +++ b/t/t7501-commit-basic-functionality.sh @@ -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 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 18/26] t7700: drop redirections to /dev/null 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (16 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 17/26] t7501: stop losing return codes of git commands Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 19/26] t7700: remove spaces after redirect operators Denton Liu ` (7 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4e855bc21b..e1a689d6a9 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 19/26] t7700: remove spaces after redirect operators 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (17 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 18/26] t7700: drop redirections to /dev/null Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 20/26] t7700: move keywords onto their own line Denton Liu ` (6 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King For 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index e1a689d6a9..8936928387 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 20/26] t7700: move keywords onto their own line 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (18 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 19/26] t7700: remove spaces after redirect operators Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/ Denton Liu ` (5 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 8936928387..a96e876c4e 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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 -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/ 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (19 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 20/26] t7700: move keywords onto their own line Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu ` (4 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Since 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. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a96e876c4e..1d14ddcbdb 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -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" -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (20 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/ Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-29 21:39 ` Junio C Hamano 2019-11-27 19:53 ` [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object() Denton Liu ` (3 subsequent siblings) 25 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead. Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job. Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use `comm -23` so that finding missing lines from the original file is done more efficiently. While we're at it, add a space to `commit_and_pack ()` for style. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 55 +++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddcbdb..4bcd9fcc80 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -4,12 +4,23 @@ test_description='git repack works correctly' . ./test-lib.sh -commit_and_pack() { +commit_and_pack () { test_commit "$@" 1>&2 && SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && echo pack-${SHA1}.pack } +test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && + git verify-pack -v alt_objects/pack/*.idx >orig.raw && + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && + test_must_be_empty missing +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 && @@ -105,19 +116,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is mkdir alt_objects/pack && mv .git/objects/pack/* alt_objects/pack && git repack -a && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' ' @@ -128,19 +127,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git commit -m more_content && git repack && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' @@ -156,19 +143,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' fi done && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-11-27 19:53 ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu @ 2019-11-29 21:39 ` Junio C Hamano 2019-12-02 20:50 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-11-29 21:39 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: > The code to test that objects were not missing from the packfile was > duplicated many times. Extract the duplicated code into > test_no_missing_in_packs() and use that instead. > > Refactor the resulting extraction so that if any git commands fail, > their return codes are not silently lost. > > We were using sed to filter lines. Although not incorrect, this is > exactly what grep is built for. Replace this invocation of sed with grep > so that we use the correct tool for the job. Well, $ sed -n -e 's/required match/desired part of the line/p' is much much more approirate than $ grep -e "requred match" | extract desired part of the line "grep" is better only if the original were $ sed -n -e '/required match/p' but everybody would write it with grep to begin with ;-) So, I dunno about this part of the conversion. > Instead of verifying each file of `alt_objects/pack/*.idx` individually > in a for-loop, batch them together into one verification step. Do you mean this one? git verify-pack -v alt_objects/pack/*.idx where we may pass 1 or more .idx file to the command? At first my reading was interrupted by a "Huh?", but that does look good. We'd need to be a bit careful to make sure that we have at least 1 .idx file, as the shell will happily feed a file whose name is "*.idx", which verify-pack would be unhappy about. > The original testing construct was O(n^2): it used a grep in a loop to > test whether any objects were missing in the packfile. Rewrite this to > sort the files then use `comm -23` so that finding missing lines from > the original file is done more efficiently. OK. If we an show measurable speedups, it would be great, but the loop structure does look O(n^2) and unnecessary costly. > +test_no_missing_in_packs () { > + myidx=$(ls -1 .git/objects/pack/*.idx) && > + test_path_is_file "$myidx" && If there are 2 or more .idx files, or if there is none, $myidx would hopefully be a concatenation of these filenames or a string that ends with asterisk-dot-idx and would fail path_is_file. Sounds OK. Ah, I do not have to review this part---these are repeated patterns in the original. > + git verify-pack -v alt_objects/pack/*.idx >orig.raw && > + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && If output from 'grep' can be used as-is, it is worth doing, but if you have to pipe it to cut, the original that used sed to filter and edit the line would probably be a better way to write it. > + git verify-pack -v $myidx >dest.raw && This part does not quote $myidx" (inherited from the original); it probably is OK, as any potentially problematic value in $myidx would have been caught as an error much earlier in this test. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-11-29 21:39 ` Junio C Hamano @ 2019-12-02 20:50 ` Denton Liu 2019-12-02 22:53 ` Junio C Hamano 0 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-12-02 20:50 UTC (permalink / raw) To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King Hi Junio, On Fri, Nov 29, 2019 at 01:39:30PM -0800, Junio C Hamano wrote: > Denton Liu <liu.denton@gmail.com> writes: > > > The code to test that objects were not missing from the packfile was > > duplicated many times. Extract the duplicated code into > > test_no_missing_in_packs() and use that instead. > > > > Refactor the resulting extraction so that if any git commands fail, > > their return codes are not silently lost. > > > > We were using sed to filter lines. Although not incorrect, this is > > exactly what grep is built for. Replace this invocation of sed with grep > > so that we use the correct tool for the job. > > Well, > > $ sed -n -e 's/required match/desired part of the line/p' > > is much much more approirate than > > $ grep -e "requred match" | > extract desired part of the line > > "grep" is better only if the original were > > $ sed -n -e '/required match/p' > > but everybody would write it with grep to begin with ;-) This was what I was intending. It was originally written like the above and it made sense to convert it to use grep. I guess "filter lines" in my commit message is a little bit vague. Could we change this to "filter matching lines" perhaps? > > So, I dunno about this part of the conversion. > > > Instead of verifying each file of `alt_objects/pack/*.idx` individually > > in a for-loop, batch them together into one verification step. > > Do you mean this one? > > git verify-pack -v alt_objects/pack/*.idx > > where we may pass 1 or more .idx file to the command? At first my > reading was interrupted by a "Huh?", but that does look good. We'd > need to be a bit careful to make sure that we have at least 1 .idx > file, as the shell will happily feed a file whose name is "*.idx", > which verify-pack would be unhappy about. > > > The original testing construct was O(n^2): it used a grep in a loop to > > test whether any objects were missing in the packfile. Rewrite this to > > sort the files then use `comm -23` so that finding missing lines from > > the original file is done more efficiently. > > OK. If we an show measurable speedups, it would be great, but the > loop structure does look O(n^2) and unnecessary costly. > > > +test_no_missing_in_packs () { > > + myidx=$(ls -1 .git/objects/pack/*.idx) && > > + test_path_is_file "$myidx" && > > If there are 2 or more .idx files, or if there is none, $myidx would > hopefully be a concatenation of these filenames or a string that > ends with asterisk-dot-idx and would fail path_is_file. Sounds OK. > > Ah, I do not have to review this part---these are repeated patterns > in the original. > > > + git verify-pack -v alt_objects/pack/*.idx >orig.raw && > > + grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && > > If output from 'grep' can be used as-is, it is worth doing, but if > you have to pipe it to cut, the original that used sed to filter and > edit the line would probably be a better way to write it. The original sed actually only filtered the line; no editing done. The cut invocation was a consequence of using comm. Previously, in the while loop, we would separate the line into `sha1` and `rest` components and only match using the `sha1`. Since we use comm now, we have to use cut to grab the sha1 and omit the rest of the line. We could rewrite it with sed like this: sed -n -e "/^[0-9a-f]\{40\}/s/^\($[0-9a-f]\{40\}\).*/\1/" orig.raw but I believe that breaking it into grep and cut makes the intent much more clear. What do you think? (By the way, if I were to reroll this series, should I keep sending out the entire patchset? It feels very noisy to send out 20-something emails every reroll when I'm just making a small one or two line change.) Thanks, Denton > > > + git verify-pack -v $myidx >dest.raw && > > This part does not quote $myidx" (inherited from the original); it > probably is OK, as any potentially problematic value in $myidx would > have been caught as an error much earlier in this test. > ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-12-02 20:50 ` Denton Liu @ 2019-12-02 22:53 ` Junio C Hamano 2019-12-02 23:28 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-12-02 22:53 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: > Hi Junio, > ... >> "grep" is better only if the original were >> >> $ sed -n -e '/required match/p' >> >> but everybody would write it with grep to begin with ;-) > > This was what I was intending. It was originally written like the above > and it made sense to convert it to use grep. I guess "filter lines" in > my commit message is a little bit vague. Could we change this to "filter > matching lines" perhaps? Ah, I see. I somehow thought that some of the "sed" invocation in the original version were doing "find lines and filter its contents" (i.e. "-n -e 's/find/munge/p'"), but all three of them are just "find lines" (i.e. "-n -e '/find/p'"). So I think the change made by the patch is OK. I think I was reacting to the output of "grep" being piped to "cut". IOW, the original ... | sed -n -e '/find/p' | while read sha1 garbage do ... use sha1 ... were rewritten to ... >raw && grep -e 'find' raw | cut -d" " -f1 >orig ... use orig as a list of sha1s ... But the "grep piped to cut" can be a single process ... >raw && sed -n -e 's/\(find\).*/\1/p' raw >orig ... use orig as a list of sha1s ... So in the tiniest picture, turning "sed -n -e /find/p" into "grep" is not wrong per-se, but if you step back a bit and see a larger picture, using "sed" a bit more effectively turns out to be still a better rewrite. ... and I wrote the above before I read the remainder of your response, where you considered which one is easier to read between "grep piped to cut" and "sed" ;-) > (By the way, if I were to reroll this series, should I keep sending out > the entire patchset? It feels very noisy to send out 20-something emails > every reroll when I'm just making a small one or two line change.) Especially if it is near the end of the series, just a single step is OK. But is there anything that is glaringly wrong that needs a reroll? Or would it be "this is good enough, so let's have them cook in 'next' and graduate to 'master'---further clean-up can be done after all the dust settles"? I have an impression that we reached the latter by now. Thanks. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-12-02 22:53 ` Junio C Hamano @ 2019-12-02 23:28 ` Denton Liu 2019-12-03 15:41 ` Junio C Hamano 0 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-12-02 23:28 UTC (permalink / raw) To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King Hi Junio, On Mon, Dec 02, 2019 at 02:53:09PM -0800, Junio C Hamano wrote: > > (By the way, if I were to reroll this series, should I keep sending out > > the entire patchset? It feels very noisy to send out 20-something emails > > every reroll when I'm just making a small one or two line change.) > > Especially if it is near the end of the series, just a single step > is OK. But is there anything that is glaringly wrong that needs a > reroll? Or would it be "this is good enough, so let's have them > cook in 'next' and graduate to 'master'---further clean-up can be > done after all the dust settles"? I have an impression that we > reached the latter by now. Perhaps the log message could use some improvement to document the discussion we had? I don't know if that's worth a reroll, though. Aside from that, I agree that it's ready for 'next'. > > Thanks. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-12-02 23:28 ` Denton Liu @ 2019-12-03 15:41 ` Junio C Hamano 2019-12-04 7:24 ` Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-12-03 15:41 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: >> Especially if it is near the end of the series, just a single step >> is OK. But is there anything that is glaringly wrong that needs a >> reroll? Or would it be "this is good enough, so let's have them >> cook in 'next' and graduate to 'master'---further clean-up can be >> done after all the dust settles"? I have an impression that we >> reached the latter by now. > > Perhaps the log message could use some improvement to document the > discussion we had? I don't know if that's worth a reroll, though. Aside > from that, I agree that it's ready for 'next'. Sure, let's see what you have in mind. Thanks for working on this. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-12-03 15:41 ` Junio C Hamano @ 2019-12-04 7:24 ` Denton Liu 2019-12-04 18:13 ` Junio C Hamano 0 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-12-04 7:24 UTC (permalink / raw) To: Junio C Hamano; +Cc: Git Mailing List, Eric Sunshine, Jeff King Hi Junio, On Tue, Dec 03, 2019 at 07:41:19AM -0800, Junio C Hamano wrote: > Denton Liu <liu.denton@gmail.com> writes: > > >> Especially if it is near the end of the series, just a single step > >> is OK. But is there anything that is glaringly wrong that needs a > >> reroll? Or would it be "this is good enough, so let's have them > >> cook in 'next' and graduate to 'master'---further clean-up can be > >> done after all the dust settles"? I have an impression that we > >> reached the latter by now. > > > > Perhaps the log message could use some improvement to document the > > discussion we had? I don't know if that's worth a reroll, though. Aside > > from that, I agree that it's ready for 'next'. > > Sure, let's see what you have in mind. Here's a complete replacement for the commit message: t7700: consolidate code into test_no_missing_in_packs() The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead. Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. We were using sed to filter lines. Although not incorrect, this is exactly what grep is built for. Replace this invocation of sed with grep so that we use the correct tool for the job. Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to sort the files then use `comm -23` so that finding missing lines from the original file is done more efficiently. The result of this is that we end up with a `grep | cut | sort` pipeline. Previously, we were extracting the `sha1` as part of the `while read sha1 rest` loop. Since we removed the while-loop, we need to use `cut` to extract the `sha1` field. Note that we could have chosen to combine the `grep | cut` into a single `sed` invocation but we consciously leave it separate as it makes the intent more clear. While we're at it, add a space to `commit_and_pack ()` for style. Signed-off-by: Denton Liu <liu.denton@gmail.com> The only change between this and the old commit message is the addition of the "The result of this..." paragraph. Thanks, Denton > > Thanks for working on this. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() 2019-12-04 7:24 ` Denton Liu @ 2019-12-04 18:13 ` Junio C Hamano 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-12-04 18:13 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: >> Sure, let's see what you have in mind. > > Here's a complete replacement for the commit message: > > t7700: consolidate code into test_no_missing_in_packs() > > The code to test that objects were not missing from the packfile was > duplicated many times. Extract the duplicated code into > test_no_missing_in_packs() and use that instead. > > Refactor the resulting extraction so that if any git commands fail, > their return codes are not silently lost. > > We were using sed to filter lines. Although not incorrect, this is > exactly what grep is built for. Replace this invocation of sed with grep > so that we use the correct tool for the job. > > Instead of verifying each file of `alt_objects/pack/*.idx` individually > in a for-loop, batch them together into one verification step. > > The original testing construct was O(n^2): it used a grep in a loop to > test whether any objects were missing in the packfile. Rewrite this to > sort the files then use `comm -23` so that finding missing lines from > the original file is done more efficiently. > > The result of this is that we end up with a `grep | cut | sort` > pipeline. Previously, we were extracting the `sha1` as part of the > `while read sha1 rest` loop. Since we removed the while-loop, we need to > use `cut` to extract the `sha1` field. Note that we could have chosen to > combine the `grep | cut` into a single `sed` invocation but we > consciously leave it separate as it makes the intent more clear. > > While we're at it, add a space to `commit_and_pack ()` for style. > > Signed-off-by: Denton Liu <liu.denton@gmail.com> > > The only change between this and the old commit message is the addition > of the "The result of this..." paragraph. Ah, you were planning to only update the log message? Then let's not bother. I do not think we would want to encourage "grep piped to cut" as a good pattern for others to follow and a single sed that finds the relevant lines and munges the content of these lines into what is desired conveys the intent clearly and more concisely (I was hoping that that was what you had in mind for a reroll). ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail 2019-12-04 18:13 ` Junio C Hamano @ 2019-12-04 22:03 ` Denton Liu 2019-12-04 22:03 ` [PATCH v6 1/5] t7700: consolidate code into test_no_missing_in_packs() Denton Liu ` (5 more replies) 0 siblings, 6 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 22:03 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Hi Junio, Sorry for the confusion. Looking it over, I see that the sed expression you proposed indeed makes the intent a lot clearer. Here's a replacement series for the last five commits of the branch. I would've opted to send out a single replacement patch but this change causes some minor textual conflicts in 4/5 so this should make your life a little easier ;) Denton Liu (5): t7700: consolidate code into test_no_missing_in_packs() t7700: consolidate code into test_has_duplicate_object() t7700: replace egrep with grep t7700: make references to SHA-1 generic t7700: stop losing return codes of git commands t/t7700-repack.sh | 165 ++++++++++++++++------------------------------ 1 file changed, 57 insertions(+), 108 deletions(-) Range-diff against v5: 1: a99a45cb6f ! 1: 3008ce8deb t7700: consolidate code into test_no_missing_in_packs() @@ Commit message Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. - We were using sed to filter lines. Although not incorrect, this is - exactly what grep is built for. Replace this invocation of sed with grep - so that we use the correct tool for the job. - Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to - sort the files then use `comm -23` so that finding missing lines from - the original file is done more efficiently. + extract the hash using sed or cut, sort the files, then use `comm -23` + so that finding missing lines from the original file is done more + efficiently. While we're at it, add a space to `commit_and_pack ()` for style. @@ t/t7700-repack.sh: test_description='git repack works correctly' + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && + git verify-pack -v alt_objects/pack/*.idx >orig.raw && -+ grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && ++ sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && 2: f79240e937 = 2: f3a0470edc t7700: consolidate code into test_has_duplicate_object() 3: 632a62f6e9 = 3: c34477a5a9 t7700: replace egrep with grep 4: bf70cc5a0d ! 4: 113f375192 t7700: make references to SHA-1 generic @@ t/t7700-repack.sh: test_description='git repack works correctly' myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && git verify-pack -v alt_objects/pack/*.idx >orig.raw && -- grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && -+ grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig && +- sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && ++ sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && 5: 1f6d9a80ad = 5: ab653bd76f t7700: stop losing return codes of git commands -- 2.24.0.578.g4820254054 ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v6 1/5] t7700: consolidate code into test_no_missing_in_packs() 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu @ 2019-12-04 22:03 ` Denton Liu 2019-12-04 22:03 ` [PATCH v6 2/5] t7700: consolidate code into test_has_duplicate_object() Denton Liu ` (4 subsequent siblings) 5 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 22:03 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead. Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to extract the hash using sed or cut, sort the files, then use `comm -23` so that finding missing lines from the original file is done more efficiently. While we're at it, add a space to `commit_and_pack ()` for style. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 55 +++++++++++++---------------------------------- 1 file changed, 15 insertions(+), 40 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddcbdb..5fb9e99f34 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -4,12 +4,23 @@ test_description='git repack works correctly' . ./test-lib.sh -commit_and_pack() { +commit_and_pack () { test_commit "$@" 1>&2 && SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && echo pack-${SHA1}.pack } +test_no_missing_in_packs () { + myidx=$(ls -1 .git/objects/pack/*.idx) && + test_path_is_file "$myidx" && + git verify-pack -v alt_objects/pack/*.idx >orig.raw && + sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && + git verify-pack -v $myidx >dest.raw && + cut -d" " -f1 dest.raw | sort >dest && + comm -23 orig dest >missing && + test_must_be_empty missing +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 && @@ -105,19 +116,7 @@ test_expect_success 'packed obs in alt ODB are repacked even when local repo is mkdir alt_objects/pack && mv .git/objects/pack/* alt_objects/pack && git repack -a && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alt ODB are repacked when local repo has packs' ' @@ -128,19 +127,7 @@ test_expect_success 'packed obs in alt ODB are repacked when local repo has pack git commit -m more_content && git repack && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' @@ -156,19 +143,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' fi done && git repack -a -d && - myidx=$(ls -1 .git/objects/pack/*.idx) && - test_path_is_file "$myidx" && - for p in alt_objects/pack/*.idx - do - git verify-pack -v $p | sed -n -e "/^[0-9a-f]\{40\}/p" - done | while read sha1 rest - do - if ! ( git verify-pack -v $myidx | grep "^$sha1" ) - then - echo "Missing object in local pack: $sha1" - return 1 - fi - done + test_no_missing_in_packs ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' -- 2.24.0.578.g4820254054 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v6 2/5] t7700: consolidate code into test_has_duplicate_object() 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-12-04 22:03 ` [PATCH v6 1/5] t7700: consolidate code into test_no_missing_in_packs() Denton Liu @ 2019-12-04 22:03 ` Denton Liu 2019-12-04 22:03 ` [PATCH v6 3/5] t7700: replace egrep with grep Denton Liu ` (3 subsequent siblings) 5 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 22:03 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead. Refactor the resulting extraction so that if the git command fails, the return code is not silently lost. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 71 +++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 5fb9e99f34..80ded48088 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -21,6 +21,25 @@ test_no_missing_in_packs () { test_must_be_empty missing } +# we expect $packsha1 and $objsha1 to be defined +test_has_duplicate_object () { + want_duplicate_object="$1" + found_duplicate_object=false + for p in .git/objects/pack/*.idx + do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist + then + found_duplicate_object=true + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$want_duplicate_object" = "$found_duplicate_object" +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 && @@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git repack -Adbl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'loose objects in alternate ODB are not repacked' ' @@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git commit -m commit_file3 && git repack -a -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' -- 2.24.0.578.g4820254054 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v6 3/5] t7700: replace egrep with grep 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-12-04 22:03 ` [PATCH v6 1/5] t7700: consolidate code into test_no_missing_in_packs() Denton Liu 2019-12-04 22:03 ` [PATCH v6 2/5] t7700: consolidate code into test_has_duplicate_object() Denton Liu @ 2019-12-04 22:03 ` Denton Liu 2019-12-04 22:03 ` [PATCH v6 4/5] t7700: make references to SHA-1 generic Denton Liu ` (2 subsequent siblings) 5 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 22:03 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The egrep expressions in this test suite were of the form `^$variable`. Although egrep works just fine, it's overkill since we're not using any extended regex. Replace egrep invocations with grep so that we aren't swatting flies with a sledgehammer. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 80ded48088..bfef5888a2 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -30,7 +30,7 @@ test_has_duplicate_object () { idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if egrep "^$objsha1" packlist + if grep "^$objsha1" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' @@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' -- 2.24.0.578.g4820254054 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v6 4/5] t7700: make references to SHA-1 generic 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (2 preceding siblings ...) 2019-12-04 22:03 ` [PATCH v6 3/5] t7700: replace egrep with grep Denton Liu @ 2019-12-04 22:03 ` Denton Liu 2019-12-04 22:03 ` [PATCH v6 5/5] t7700: stop losing return codes of git commands Denton Liu 2019-12-04 22:07 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Junio C Hamano 5 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 22:03 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Make the test more hash-agnostic by renaming variables from "sha1" to some variation of "oid" or "packid". Also, replace the regex, `[0-9a-f]\{40\}` with `$OID_REGEX`. A better name for "incrpackid" (incremental pack-id) might have been just "packid". However, later in the test suite, we have other uses of "packid". Although the scopes of these variables don't conflict, a future developer may think that commit_and_pack() and test_has_duplicate_object() are semantically related somehow since they share the same variable name. Give them distinct names so that it's clear these uses are unrelated. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index bfef5888a2..5229999d77 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -6,31 +6,31 @@ test_description='git repack works correctly' commit_and_pack () { test_commit "$@" 1>&2 && - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && - echo pack-${SHA1}.pack + incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && + echo pack-${incrpackid}.pack } test_no_missing_in_packs () { myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && git verify-pack -v alt_objects/pack/*.idx >orig.raw && - sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && + sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && test_must_be_empty missing } -# we expect $packsha1 and $objsha1 to be defined +# we expect $packid and $oid to be defined test_has_duplicate_object () { want_duplicate_object="$1" found_duplicate_object=false for p in .git/objects/pack/*.idx do idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue + test "pack-$packid.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if grep "^$objsha1" packlist + if grep "^$oid" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git rev-list --objects --all | grep -v file2 | git pack-objects pack && # The second pack will contain the excluded object - packsha1=$(git rev-list --objects --all | grep file2 | + packid=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - >pack-$packsha1.keep && - objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + >pack-$packid.keep && + oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | + sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && @@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git repack -Adbl && test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_has_duplicate_object true ' @@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo $(pwd)/alt_objects >.git/objects/info/alternates && echo content3 >file3 && - objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && + oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick && git commit -m commit_file3 && @@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f alt_objects/pack/*.keep && mv .git/objects/pack/* alt_objects/pack/ && - csha1=$(git rev-parse HEAD^{commit}) && + coid=$(git rev-parse HEAD^{commit}) && git reset --hard HEAD^ && test_tick && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && @@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' echo $(pwd)/alt_objects >.git/objects/info/alternates && - echo "$csha1" | git pack-objects --non-empty --all --reflog pack && + echo "$coid" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && # The pack-objects call on the next line is equivalent to @@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'objects made unreachable by grafts only are kept' ' -- 2.24.0.578.g4820254054 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v6 5/5] t7700: stop losing return codes of git commands 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (3 preceding siblings ...) 2019-12-04 22:03 ` [PATCH v6 4/5] t7700: make references to SHA-1 generic Denton Liu @ 2019-12-04 22:03 ` Denton Liu 2019-12-04 22:07 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Junio C Hamano 5 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 22:03 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t7700-repack.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 5229999d77..25b235c063 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git commit -m initial_commit && # Create two packs # The first pack will contain all of the objects except one - git rev-list --objects --all | grep -v file2 | - git pack-objects pack && + git rev-list --objects --all >objs && + grep -v file2 objs | git pack-objects pack && # The second pack will contain the excluded object - packid=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packid=$(grep file2 objs | git pack-objects pack) && >pack-$packid.keep && - oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | - sed -e "s/^\($OID_REGEX\).*/\1/") && + git verify-pack -v pack-$packid.idx >packlist && + oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && @@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " packlist && echo >.git/objects/info/alternates && test_must_fail git show $coid ' @@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " && echo >.git/objects/info/alternates && test_must_fail git show $coid ' -- 2.24.0.578.g4820254054 ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (4 preceding siblings ...) 2019-12-04 22:03 ` [PATCH v6 5/5] t7700: stop losing return codes of git commands Denton Liu @ 2019-12-04 22:07 ` Junio C Hamano 5 siblings, 0 replies; 228+ messages in thread From: Junio C Hamano @ 2019-12-04 22:07 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Jeff King Denton Liu <liu.denton@gmail.com> writes: > > Range-diff against v5: > 1: a99a45cb6f ! 1: 3008ce8deb t7700: consolidate code into test_no_missing_in_packs() > @@ Commit message > Refactor the resulting extraction so that if any git commands fail, > their return codes are not silently lost. > > - We were using sed to filter lines. Although not incorrect, this is > - exactly what grep is built for. Replace this invocation of sed with grep > - so that we use the correct tool for the job. > - > Instead of verifying each file of `alt_objects/pack/*.idx` individually > in a for-loop, batch them together into one verification step. > > The original testing construct was O(n^2): it used a grep in a loop to > test whether any objects were missing in the packfile. Rewrite this to > - sort the files then use `comm -23` so that finding missing lines from > - the original file is done more efficiently. > + extract the hash using sed or cut, sort the files, then use `comm -23` > + so that finding missing lines from the original file is done more > + efficiently. > > While we're at it, add a space to `commit_and_pack ()` for style. > > @@ t/t7700-repack.sh: test_description='git repack works correctly' > + myidx=$(ls -1 .git/objects/pack/*.idx) && > + test_path_is_file "$myidx" && > + git verify-pack -v alt_objects/pack/*.idx >orig.raw && > -+ grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && > ++ sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && > + git verify-pack -v $myidx >dest.raw && > + cut -d" " -f1 dest.raw | sort >dest && > + comm -23 orig dest >missing && OK. > 2: f79240e937 = 2: f3a0470edc t7700: consolidate code into test_has_duplicate_object() > 3: 632a62f6e9 = 3: c34477a5a9 t7700: replace egrep with grep > 4: bf70cc5a0d ! 4: 113f375192 t7700: make references to SHA-1 generic > @@ t/t7700-repack.sh: test_description='git repack works correctly' > myidx=$(ls -1 .git/objects/pack/*.idx) && > test_path_is_file "$myidx" && > git verify-pack -v alt_objects/pack/*.idx >orig.raw && > -- grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && > -+ grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig && > +- sed -n -e "s/^\([0-9a-f]\{40\}\).*/\1/p" orig.raw | sort >orig && > ++ sed -n -e "s/^\($OID_REGEX\).*/\1/p" orig.raw | sort >orig && Looking really good. Thanks for following through. Will replace and queue. Hopefully this round is now ready for 'next'. Knock knock... ^ permalink raw reply [flat|nested] 228+ messages in thread
* [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object() 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (21 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:53 ` [PATCH v5 24/26] t7700: replace egrep with grep Denton Liu ` (2 subsequent siblings) 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The code to test that objects were not duplicated from the packfile was duplicated many times. Extract the duplicated code into test_has_duplicate_object() and use that instead. Refactor the resulting extraction so that if the git command fails, the return code is not silently lost. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 71 +++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 48 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4bcd9fcc80..5bbed02fe5 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -21,6 +21,25 @@ test_no_missing_in_packs () { test_must_be_empty missing } +# we expect $packsha1 and $objsha1 to be defined +test_has_duplicate_object () { + want_duplicate_object="$1" + found_duplicate_object=false + for p in .git/objects/pack/*.idx + do + idx=$(basename $p) + test "pack-$packsha1.idx" = "$idx" && continue + git verify-pack -v $p >packlist || return $? + if egrep "^$objsha1" packlist + then + found_duplicate_object=true + echo "DUPLICATE OBJECT FOUND" + break + fi + done && + test "$want_duplicate_object" = "$found_duplicate_object" +} + test_expect_success 'objects in packs marked .keep are not repacked' ' echo content1 >file1 && echo content2 >file2 && @@ -40,54 +59,19 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git repack -Adbl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' # build on $objsha1, $packsha1, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && - test_when_finished "found_duplicate_object=" && - for p in .git/objects/pack/*.idx - do - idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test "$found_duplicate_object" = 1 + test_has_duplicate_object true ' test_expect_success 'loose objects in alternate ODB are not repacked' ' @@ -100,16 +84,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' git commit -m commit_file3 && git repack -a -d -l && git prune-packed && - for p in .git/objects/pack/*.idx - do - if git verify-pack -v $p | egrep "^$objsha1" - then - found_duplicate_object=1 - echo "DUPLICATE OBJECT FOUND" - break - fi - done && - test -z "$found_duplicate_object" + test_has_duplicate_object false ' test_expect_success 'packed obs in alt ODB are repacked even when local repo is packless' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 24/26] t7700: replace egrep with grep 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (22 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object() Denton Liu @ 2019-11-27 19:53 ` Denton Liu 2019-11-27 19:54 ` [PATCH v5 25/26] t7700: make references to SHA-1 generic Denton Liu 2019-11-27 19:54 ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:53 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King The egrep expressions in this test suite were of the form `^$variable`. Although egrep works just fine, it's overkill since we're not using any extended regex. Replace egrep invocations with grep so that we aren't swatting flies with a sledgehammer. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 5bbed02fe5..2493cc4e9b 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -30,7 +30,7 @@ test_has_duplicate_object () { idx=$(basename $p) test "pack-$packsha1.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if egrep "^$objsha1" packlist + if grep "^$objsha1" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ -135,7 +135,7 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' @@ -152,7 +152,7 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - egrep "^$csha1 " | sort | uniq | wc -l) && + grep "^$csha1 " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && test_must_fail git show $csha1 ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 25/26] t7700: make references to SHA-1 generic 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (23 preceding siblings ...) 2019-11-27 19:53 ` [PATCH v5 24/26] t7700: replace egrep with grep Denton Liu @ 2019-11-27 19:54 ` Denton Liu 2019-11-27 19:54 ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu 25 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:54 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King Make the test more hash-agnostic by renaming variables from "sha1" to some variation of "oid" or "packid". Also, replace the regex, `[0-9a-f]\{40\}` with `$OID_REGEX`. A better name for "incrpackid" (incremental pack-id) might have been just "packid". However, later in the test suite, we have other uses of "packid". Although the scopes of these variables don't conflict, a future developer may think that commit_and_pack() and test_has_duplicate_object() are semantically related somehow since they share the same variable name. Give them distinct names so that it's clear these uses are unrelated. Signed-off-by: Denton Liu <liu.denton@gmail.com> --- t/t7700-repack.sh | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 2493cc4e9b..1edb21bf93 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -6,31 +6,31 @@ test_description='git repack works correctly' commit_and_pack () { test_commit "$@" 1>&2 && - SHA1=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && - echo pack-${SHA1}.pack + incrpackid=$(git pack-objects --all --unpacked --incremental .git/objects/pack/pack </dev/null) && + echo pack-${incrpackid}.pack } test_no_missing_in_packs () { myidx=$(ls -1 .git/objects/pack/*.idx) && test_path_is_file "$myidx" && git verify-pack -v alt_objects/pack/*.idx >orig.raw && - grep "^[0-9a-f]\{40\}" orig.raw | cut -d" " -f1 | sort >orig && + grep "^$OID_REGEX" orig.raw | cut -d" " -f1 | sort >orig && git verify-pack -v $myidx >dest.raw && cut -d" " -f1 dest.raw | sort >dest && comm -23 orig dest >missing && test_must_be_empty missing } -# we expect $packsha1 and $objsha1 to be defined +# we expect $packid and $oid to be defined test_has_duplicate_object () { want_duplicate_object="$1" found_duplicate_object=false for p in .git/objects/pack/*.idx do idx=$(basename $p) - test "pack-$packsha1.idx" = "$idx" && continue + test "pack-$packid.idx" = "$idx" && continue git verify-pack -v $p >packlist || return $? - if grep "^$objsha1" packlist + if grep "^$oid" packlist then found_duplicate_object=true echo "DUPLICATE OBJECT FOUND" @@ -51,11 +51,11 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git rev-list --objects --all | grep -v file2 | git pack-objects pack && # The second pack will contain the excluded object - packsha1=$(git rev-list --objects --all | grep file2 | + packid=$(git rev-list --objects --all | grep file2 | git pack-objects pack) && - >pack-$packsha1.keep && - objsha1=$(git verify-pack -v pack-$packsha1.idx | head -n 1 | - sed -e "s/^\([0-9a-f]\{40\}\).*/\1/") && + >pack-$packid.keep && + oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | + sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && @@ -63,13 +63,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' ' test_expect_success 'writing bitmaps via command-line can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git repack -Adbl && test_has_duplicate_object true ' test_expect_success 'writing bitmaps via config can duplicate .keep objects' ' - # build on $objsha1, $packsha1, and .keep state from previous + # build on $oid, $packid, and .keep state from previous git -c repack.writebitmaps=true repack -Adl && test_has_duplicate_object true ' @@ -78,7 +78,7 @@ test_expect_success 'loose objects in alternate ODB are not repacked' ' mkdir alt_objects && echo $(pwd)/alt_objects >.git/objects/info/alternates && echo content3 >file3 && - objsha1=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && + oid=$(GIT_OBJECT_DIRECTORY=alt_objects git hash-object -w file3) && git add file3 && test_tick && git commit -m commit_file3 && @@ -124,7 +124,7 @@ test_expect_success 'packed obs in alternate ODB kept pack are repacked' ' test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f alt_objects/pack/*.keep && mv .git/objects/pack/* alt_objects/pack/ && - csha1=$(git rev-parse HEAD^{commit}) && + coid=$(git rev-parse HEAD^{commit}) && git reset --hard HEAD^ && test_tick && git reflog expire --expire=$test_tick --expire-unreachable=$test_tick --all && @@ -135,14 +135,14 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'local packed unreachable obs that exist in alternate ODB are not loosened' ' echo $(pwd)/alt_objects >.git/objects/info/alternates && - echo "$csha1" | git pack-objects --non-empty --all --reflog pack && + echo "$coid" | git pack-objects --non-empty --all --reflog pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && # The pack-objects call on the next line is equivalent to @@ -152,9 +152,9 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$csha1 " | sort | uniq | wc -l) && + grep "^$coid " | sort | uniq | wc -l) && echo >.git/objects/info/alternates && - test_must_fail git show $csha1 + test_must_fail git show $coid ' test_expect_success 'objects made unreachable by grafts only are kept' ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* [PATCH v5 26/26] t7700: stop losing return codes of git commands 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu ` (24 preceding siblings ...) 2019-11-27 19:54 ` [PATCH v5 25/26] t7700: make references to SHA-1 generic Denton Liu @ 2019-11-27 19:54 ` Denton Liu 2019-11-30 10:48 ` Danh Doan 25 siblings, 1 reply; 228+ messages in thread From: Denton Liu @ 2019-11-27 19:54 UTC (permalink / raw) To: Git Mailing List; +Cc: Eric Sunshine, Junio C Hamano, Jeff King 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 <liu.denton@gmail.com> --- t/t7700-repack.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1edb21bf93..d5cce7c06f 100755 --- a/t/t7700-repack.sh +++ b/t/t7700-repack.sh @@ -48,14 +48,13 @@ test_expect_success 'objects in packs marked .keep are not repacked' ' git commit -m initial_commit && # Create two packs # The first pack will contain all of the objects except one - git rev-list --objects --all | grep -v file2 | - git pack-objects pack && + git rev-list --objects --all >objs && + grep -v file2 objs | git pack-objects pack && # The second pack will contain the excluded object - packid=$(git rev-list --objects --all | grep file2 | - git pack-objects pack) && + packid=$(grep file2 objs | git pack-objects pack) && >pack-$packid.keep && - oid=$(git verify-pack -v pack-$packid.idx | head -n 1 | - sed -e "s/^\($OID_REGEX\).*/\1/") && + git verify-pack -v pack-$packid.idx >packlist && + oid=$(head -n 1 packlist | sed -e "s/^\($OID_REGEX\).*/\1/") && mv pack-* .git/objects/pack/ && git repack -A -d -l && git prune-packed && @@ -134,8 +133,8 @@ test_expect_success 'packed unreachable obs in alternate ODB are not loosened' ' --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " packlist && echo >.git/objects/info/alternates && test_must_fail git show $coid ' @@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar --unpack-unreachable </dev/null pack && rm -f .git/objects/pack/* && mv pack-* .git/objects/pack/ && - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | - grep "^$coid " | sort | uniq | wc -l) && + git verify-pack -v -- .git/objects/pack/*.idx >packlist && + ! grep "^$coid " && echo >.git/objects/info/alternates && test_must_fail git show $coid ' -- 2.24.0.504.g3cd56eb17d ^ permalink raw reply related [flat|nested] 228+ messages in thread
* Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands 2019-11-27 19:54 ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu @ 2019-11-30 10:48 ` Danh Doan 2019-11-30 11:31 ` Eric Sunshine 0 siblings, 1 reply; 228+ messages in thread From: Danh Doan @ 2019-11-30 10:48 UTC (permalink / raw) To: Denton Liu; +Cc: Git Mailing List, Eric Sunshine, Junio C Hamano, Jeff King Hi Denton, On 2019-11-27 11:54:04-0800, Denton Liu <liu.denton@gmail.com> wrote: > - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | > - grep "^$coid " | sort | uniq | wc -l) && > + git verify-pack -v -- .git/objects/pack/*.idx >packlist && > + ! grep "^$coid " packlist && I think we want to use test_must_fail instead of ! > echo >.git/objects/info/alternates && > test_must_fail git show $coid > ' > @@ -151,8 +150,8 @@ test_expect_success 'local packed unreachable obs that exist in alternate ODB ar > --unpack-unreachable </dev/null pack && > rm -f .git/objects/pack/* && > mv pack-* .git/objects/pack/ && > - test 0 = $(git verify-pack -v -- .git/objects/pack/*.idx | > - grep "^$coid " | sort | uniq | wc -l) && > + git verify-pack -v -- .git/objects/pack/*.idx >packlist && > + ! grep "^$coid " && ditto -- Danh ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands 2019-11-30 10:48 ` Danh Doan @ 2019-11-30 11:31 ` Eric Sunshine 2019-11-30 17:00 ` Junio C Hamano 0 siblings, 1 reply; 228+ messages in thread From: Eric Sunshine @ 2019-11-30 11:31 UTC (permalink / raw) To: Danh Doan; +Cc: Denton Liu, Git Mailing List, Junio C Hamano, Jeff King On Sat, Nov 30, 2019 at 5:48 AM Danh Doan <congdanhqx@gmail.com> wrote: > On 2019-11-27 11:54:04-0800, Denton Liu <liu.denton@gmail.com> wrote: > > + ! grep "^$coid " packlist && > > I think we want to use test_must_fail instead of ! test_must_fail() is intended only for use with 'git' commands; "!" should be used otherwise. Quoting from t/README: Don't use '! git cmd' when you want to make sure the git command exits with failure in a controlled way by calling "die()". Instead, use 'test_must_fail git cmd'. This will signal a failure if git dies in an unexpected way (e.g. segfault). On the other hand, don't use test_must_fail for running regular platform commands; just use '! cmd'. We are not in the business of verifying that the world given to us sanely works. So, Denton's use of "!" here is correct. ^ permalink raw reply [flat|nested] 228+ messages in thread
* Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands 2019-11-30 11:31 ` Eric Sunshine @ 2019-11-30 17:00 ` Junio C Hamano 2019-12-04 12:59 ` t: remove inappropriate uses of test_must_fail(), was " Denton Liu 0 siblings, 1 reply; 228+ messages in thread From: Junio C Hamano @ 2019-11-30 17:00 UTC (permalink / raw) To: Eric Sunshine; +Cc: Danh Doan, Denton Liu, Git Mailing List, Jeff King Eric Sunshine <sunshine@sunshineco.com> writes: > On Sat, Nov 30, 2019 at 5:48 AM Danh Doan <congdanhqx@gmail.com> wrote: >> On 2019-11-27 11:54:04-0800, Denton Liu <liu.denton@gmail.com> wrote: >> > + ! grep "^$coid " packlist && >> >> I think we want to use test_must_fail instead of ! > > test_must_fail() is intended only for use with 'git' commands; "!" > should be used otherwise. Quoting from t/README: > > Don't use '! git cmd' when you want to make sure the git command > exits with failure in a controlled way by calling "die()". Instead, > use 'test_must_fail git cmd'. This will signal a failure if git > dies in an unexpected way (e.g. segfault). > > On the other hand, don't use test_must_fail for running regular > platform commands; just use '! cmd'. We are not in the business > of verifying that the world given to us sanely works. > > So, Denton's use of "!" here is correct. I wonder we can make the framework a bit more self-documenting to avoid having to waste time on discovering potential issues and explaining why it is not an issue, like this exchange. Some ideas: * Perhaps test_must_fail is not descriptive enough that it should apply only to git command invocation. Would it make it more obvious to rename it to say git_must_fail? That would also make it unnecessary to give this rather unfortunate comment in test-lib-functions.sh: # This is not among top-level (test_expect_success | test_expect_failure) # but is a prefix that can be used in the test script, like: # # test_expect_success 'complain and die' ' # do something && # do something else && # test_must_fail git checkout ../outerspace # ' # * If it is too much trouble to rename it, perhaps test_must_fail can be documented better up there? diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index b299ecc326..052d88c5da 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -817,6 +817,13 @@ list_contains () { # Multiple signals can be specified as a comma separated list. # Currently recognized signal names are: sigpipe, success. # (Don't use 'success', use 'test_might_fail' instead.) +# +# Do not use this to run anything but "git". We are not in the business +# of vetting system supplied commands---IOW this is wrong: +# +# test_must_fail grep pattern output +# +# Just use '!' instead. test_must_fail () { case "$1" in * Or perhaps we can detect its use on anything that is not "git" automatically? This is merely to illustrate the idea (the exemption of "env" shown here is too broad for production use) diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh index b299ecc326..7ab113cd50 100644 --- a/t/test-lib-functions.sh +++ b/t/test-lib-functions.sh @@ -828,6 +828,10 @@ test_must_fail () { _test_ok= ;; esac + case "$1" in + git|test-tool|env) ;; + *) echo >&7 "warning: test_must_fail $*???" ;; + esac "$@" 2>&7 exit_code=$? if test $exit_code -eq 0 && ! list_contains "$_test_ok" success Hmm? ^ permalink raw reply [flat|nested] 228+ messages in thread
* t: remove inappropriate uses of test_must_fail(), was Re: [PATCH v5 26/26] t7700: stop losing return codes of git commands 2019-11-30 17:00 ` Junio C Hamano @ 2019-12-04 12:59 ` Denton Liu 0 siblings, 0 replies; 228+ messages in thread From: Denton Liu @ 2019-12-04 12:59 UTC (permalink / raw) To: Junio C Hamano; +Cc: Eric Sunshine, Danh Doan, Git Mailing List, Jeff King Hi all, On Sat, Nov 30, 2019 at 09:00:08AM -0800, Junio C Hamano wrote: > * Or perhaps we can detect its use on anything that is not "git" > automatically? This is merely to illustrate the idea (the > exemption of "env" shown here is too broad for production use) > > diff --git a/t/test-lib-functions.sh b/t/test-lib-functions.sh > index b299ecc326..7ab113cd50 100644 > --- a/t/test-lib-functions.sh > +++ b/t/test-lib-functions.sh > @@ -828,6 +828,10 @@ test_must_fail () { > _test_ok= > ;; > esac > + case "$1" in > + git|test-tool|env) ;; > + *) echo >&7 "warning: test_must_fail $*???" ;; > + esac > "$@" 2>&7 > exit_code=$? > if test $exit_code -eq 0 && ! list_contains "$_test_ok" success I've been cooking a series that gets rid of inappropriate uses test_must_fail() for a while now. As a finishing touch, I implemented the idea Junio suggested above and it seems to be working well. It's a pretty hefty series, weighing in at 46 patches. After the dust settles on 'dl/test-cleanup' (once it gets merged to master), I'll probably start sending out this test_must_fail() series around 10 patches at a time. An advanced preview can be found here[1]. Or, if you'd like me to privately mail you the series, I can do that too. Early comments would be very appreciated. Thanks, Denton [1]: https://github.com/Denton-L/git/commits/ready/cleanup-test-must-fail ^ permalink raw reply [flat|nested] 228+ messages in thread
end of thread, other threads:[~2021-01-23 21:36 UTC | newest] Thread overview: 228+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2019-11-15 1:00 [PATCH 00/27] t: general test cleanup + `set -o pipefail` Denton Liu 2019-11-15 1:00 ` [PATCH 01/27] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-15 18:22 ` Eric Sunshine 2019-11-16 2:50 ` Junio C Hamano 2019-11-15 1:00 ` [PATCH 02/27] t0014: remove git command upstream of pipe Denton Liu 2019-11-15 1:00 ` [PATCH 03/27] t0090: stop losing return codes of git commands Denton Liu 2019-11-15 1:00 ` [PATCH 04/27] t3301: " Denton Liu 2019-11-15 1:00 ` [PATCH 05/27] t3600: use test_line_count() where possible Denton Liu 2019-11-15 1:00 ` [PATCH 06/27] t3600: stop losing return codes of git commands Denton Liu 2019-11-15 1:00 ` [PATCH 07/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu 2019-11-15 1:00 ` [PATCH 08/27] t4015: stop losing return codes of git commands Denton Liu 2019-11-15 1:00 ` [PATCH 09/27] t4015: use test_write_lines() Denton Liu 2019-11-15 1:00 ` [PATCH 10/27] t4138: stop losing return codes of git commands Denton Liu 2019-11-16 9:00 ` Eric Sunshine 2019-11-15 1:00 ` [PATCH 11/27] t5317: " Denton Liu 2019-11-15 1:00 ` [PATCH 12/27] t5317: use ! grep to check for no matching lines Denton Liu 2019-11-16 9:27 ` Eric Sunshine 2019-11-15 1:01 ` [PATCH 13/27] t5703: stop losing return codes of git commands Denton Liu 2019-11-16 10:11 ` Eric Sunshine 2019-11-15 1:01 ` [PATCH 14/27] t7501: remove spaces after redirect operators Denton Liu 2019-11-15 1:01 ` [PATCH 15/27] t7501: stop losing return codes of git commands Denton Liu 2019-11-16 10:35 ` Eric Sunshine 2019-11-15 1:01 ` [PATCH 16/27] t7700: drop redirections to /dev/null Denton Liu 2019-11-15 1:01 ` [PATCH 17/27] t7700: remove spaces after redirect operators Denton Liu 2019-11-15 1:01 ` [PATCH 18/27] t7700: move keywords onto their own line Denton Liu 2019-11-15 1:01 ` [PATCH 19/27] t7700: s/test -f/test_path_is_file/ Denton Liu 2019-11-15 1:01 ` [PATCH 20/27] t7700: stop losing return codes of git commands Denton Liu 2019-11-15 1:01 ` [PATCH 21/27] t: define test_grep_return_success() Denton Liu 2019-11-15 5:26 ` Junio C Hamano 2019-11-15 1:01 ` [PATCH 22/27] t0090: mask failing grep status Denton Liu 2019-11-15 1:01 ` [PATCH 23/27] t3600: mark git command as failing Denton Liu 2019-11-15 5:35 ` Junio C Hamano 2019-11-15 1:01 ` [PATCH 24/27] t5004: ignore SIGPIPE in zipinfo Denton Liu 2019-11-15 5:36 ` Junio C Hamano 2019-11-15 1:01 ` [PATCH 25/27] t5703: mask failing grep status Denton Liu 2019-11-15 1:01 ` [PATCH 26/27] t9902: disable pipefail Denton Liu 2019-11-15 1:01 ` [PATCH 27/27] t: run tests with `set -o pipefail` on Bash Denton Liu 2019-11-15 4:09 ` [PATCH 00/27] t: general test cleanup + `set -o pipefail` Jeff King 2021-01-14 23:35 ` [PATCH 0/6] tests: add a bash "set -o pipefail" test mode Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 00/11] " Ævar Arnfjörð Bjarmason 2021-01-16 21:50 ` Junio C Hamano 2021-01-17 16:50 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 01/11] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 02/11] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason 2021-01-17 16:55 ` Jeff King 2021-01-17 22:23 ` Eric Sunshine 2021-01-17 23:37 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 03/11] cache-tree tests: refactor overly complex function Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 04/11] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 05/11] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 06/11] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason 2021-01-16 21:51 ` Junio C Hamano 2021-01-17 16:47 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 07/11] rm tests: actually test for SIGPIPE in SIGPIPE test Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 08/11] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason 2021-01-16 21:48 ` Junio C Hamano 2021-01-16 15:35 ` [PATCH v2 09/11] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason 2021-01-17 17:08 ` Jeff King 2021-01-16 15:35 ` [PATCH v2 10/11] tests: split up bash detection library Ævar Arnfjörð Bjarmason 2021-01-16 15:35 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 2021-01-20 13:04 ` SZEDER Gábor 2021-01-23 3:46 ` Junio C Hamano 2021-01-23 7:37 ` Junio C Hamano 2021-01-23 9:32 ` Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 00/10] Miscellaneous "set -o pipefail"-related test cleanups Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 01/10] cache-tree tests: refactor for modern test style Ævar Arnfjörð Bjarmason 2021-01-23 21:34 ` Junio C Hamano 2021-01-23 13:00 ` [PATCH v3 02/10] cache-tree tests: remove unused $2 parameter Ævar Arnfjörð Bjarmason 2021-01-23 21:35 ` Junio C Hamano 2021-01-23 13:00 ` [PATCH v3 03/10] cache-tree tests: use a sub-shell with less indirection Ævar Arnfjörð Bjarmason 2021-01-23 21:35 ` Junio C Hamano 2021-01-23 13:00 ` [PATCH v3 04/10] cache-tree tests: explicitly test HEAD and index differences Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 05/10] git svn mergeinfo tests: modernize redirection & quoting style Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 06/10] git svn mergeinfo tests: refactor "test -z" to use test_must_be_empty Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 07/10] git-svn tests: rewrite brittle tests to use "--[no-]merges" Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 08/10] upload-pack tests: avoid a non-zero "grep" exit status Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 09/10] archive tests: use a cheaper "zipinfo -h" invocation to get header Ævar Arnfjörð Bjarmason 2021-01-23 13:00 ` [PATCH v3 10/10] rm tests: actually test for SIGPIPE in SIGPIPE test Ævar Arnfjörð Bjarmason 2021-01-23 9:40 ` [PATCH v2 11/11] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 1/6] test-lib: add tests for test_might_fail Ævar Arnfjörð Bjarmason 2021-01-15 9:36 ` Jeff King 2021-01-16 14:41 ` [PATCH] " Ævar Arnfjörð Bjarmason 2021-01-17 16:48 ` Jeff King 2021-01-14 23:35 ` [PATCH 2/6] test-lib: add ok=* support to test_might_fail Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 3/6] test_lib: allow test_{must,might}_fail to accept non-git on "sigpipe" Ævar Arnfjörð Bjarmason 2021-01-15 8:15 ` Denton Liu 2021-01-15 9:39 ` Ævar Arnfjörð Bjarmason 2021-01-15 10:00 ` Jeff King 2021-01-14 23:35 ` [PATCH 4/6] tests: use "test_might_fail ok=sigpipe grep" when appropriate Ævar Arnfjörð Bjarmason 2021-01-15 9:14 ` Ævar Arnfjörð Bjarmason 2021-01-15 9:48 ` Jeff King 2021-01-14 23:35 ` [PATCH 5/6] tests: split up bash detection library Ævar Arnfjörð Bjarmason 2021-01-15 9:42 ` Ævar Arnfjörð Bjarmason 2021-01-14 23:35 ` [PATCH 6/6] tests: add a "set -o pipefail" for a patched bash Ævar Arnfjörð Bjarmason 2021-01-15 10:04 ` Jeff King 2019-11-21 0:45 ` [PATCH v2 00/21] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-21 0:45 ` [PATCH v2 01/21] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-21 0:45 ` [PATCH v2 02/21] t0014: remove git command upstream of pipe Denton Liu 2019-11-21 0:45 ` [PATCH v2 03/21] t0090: stop losing return codes of git commands Denton Liu 2019-11-21 0:45 ` [PATCH v2 04/21] t3301: " Denton Liu 2019-11-21 0:45 ` [PATCH v2 05/21] t3600: use test_line_count() where possible Denton Liu 2019-11-21 0:46 ` [PATCH v2 06/21] t3600: stop losing return codes of git commands Denton Liu 2019-11-21 0:46 ` [PATCH v2 07/21] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu 2019-11-21 0:46 ` [PATCH v2 08/21] t4015: stop losing return codes of git commands Denton Liu 2019-11-21 0:46 ` [PATCH v2 09/21] t4015: use test_write_lines() Denton Liu 2019-11-21 0:46 ` [PATCH v2 10/21] t4138: stop losing return codes of git commands Denton Liu 2019-11-21 0:46 ` [PATCH v2 11/21] t5317: " Denton Liu 2019-11-21 0:46 ` [PATCH v2 12/21] t5317: use ! grep to check for no matching lines Denton Liu 2019-11-21 12:59 ` Eric Sunshine 2019-11-21 0:46 ` [PATCH v2 13/21] t5703: simplify one-time-sed generation logic Denton Liu 2019-11-21 13:12 ` Eric Sunshine 2019-11-21 23:22 ` Denton Liu 2019-11-21 0:46 ` [PATCH v2 14/21] t5703: stop losing return codes of git commands Denton Liu 2019-11-21 0:46 ` [PATCH v2 15/21] t7501: remove spaces after redirect operators Denton Liu 2019-11-21 0:46 ` [PATCH v2 16/21] t7501: stop losing return codes of git commands Denton Liu 2019-11-21 0:46 ` [PATCH v2 17/21] t7700: drop redirections to /dev/null Denton Liu 2019-11-21 0:46 ` [PATCH v2 18/21] t7700: remove spaces after redirect operators Denton Liu 2019-11-21 0:46 ` [PATCH v2 19/21] t7700: move keywords onto their own line Denton Liu 2019-11-21 0:46 ` [PATCH v2 20/21] t7700: s/test -f/test_path_is_file/ Denton Liu 2019-11-21 0:46 ` [PATCH v2 21/21] t7700: stop losing return codes of git commands Denton Liu 2019-11-22 18:59 ` [PATCH v3 00/22] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-22 18:59 ` [PATCH v3 01/22] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-22 18:59 ` [PATCH v3 02/22] apply-one-time-sed.sh: modernize style Denton Liu 2019-11-23 1:32 ` Junio C Hamano 2019-11-22 18:59 ` [PATCH v3 03/22] t0014: remove git command upstream of pipe Denton Liu 2019-11-22 18:59 ` [PATCH v3 04/22] t0090: stop losing return codes of git commands Denton Liu 2019-11-22 18:59 ` [PATCH v3 05/22] t3301: " Denton Liu 2019-11-22 18:59 ` [PATCH v3 06/22] t3600: use test_line_count() where possible Denton Liu 2019-11-22 18:59 ` [PATCH v3 07/22] t3600: stop losing return codes of git commands Denton Liu 2019-11-22 19:00 ` [PATCH v3 08/22] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu 2019-11-22 19:00 ` [PATCH v3 09/22] t4015: stop losing return codes of git commands Denton Liu 2019-11-22 19:00 ` [PATCH v3 10/22] t4015: use test_write_lines() Denton Liu 2019-11-22 19:00 ` [PATCH v3 11/22] t4138: stop losing return codes of git commands Denton Liu 2019-11-22 19:00 ` [PATCH v3 12/22] t5317: " Denton Liu 2019-11-22 19:00 ` [PATCH v3 13/22] t5317: use ! grep to check for no matching lines Denton Liu 2019-11-23 6:21 ` Eric Sunshine 2019-11-25 21:43 ` Denton Liu 2019-11-22 19:00 ` [PATCH v3 14/22] t5703: simplify one-time-sed generation logic Denton Liu 2019-11-22 19:00 ` [PATCH v3 15/22] t5703: stop losing return codes of git commands Denton Liu 2019-11-22 19:00 ` [PATCH v3 16/22] t7501: remove spaces after redirect operators Denton Liu 2019-11-22 19:00 ` [PATCH v3 17/22] t7501: stop losing return codes of git commands Denton Liu 2019-11-22 19:00 ` [PATCH v3 18/22] t7700: drop redirections to /dev/null Denton Liu 2019-11-22 19:00 ` [PATCH v3 19/22] t7700: remove spaces after redirect operators Denton Liu 2019-11-22 19:00 ` [PATCH v3 20/22] t7700: move keywords onto their own line Denton Liu 2019-11-22 19:00 ` [PATCH v3 21/22] t7700: s/test -f/test_path_is_file/ Denton Liu 2019-11-22 19:00 ` [PATCH v3 22/22] t7700: stop losing return codes of git commands Denton Liu 2019-11-23 1:49 ` Junio C Hamano 2019-11-25 23:57 ` Denton Liu 2019-11-26 0:58 ` Eric Sunshine 2019-11-26 1:34 ` Junio C Hamano 2019-11-26 4:47 ` Denton Liu 2019-11-26 1:17 ` [PATCH v4 00/27] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-26 1:17 ` [PATCH v4 01/27] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-26 1:17 ` [PATCH v4 02/27] apply-one-time-sed.sh: modernize style Denton Liu 2019-11-26 1:17 ` [PATCH v4 03/27] t0014: remove git command upstream of pipe Denton Liu 2019-11-26 1:17 ` [PATCH v4 04/27] t0090: stop losing return codes of git commands Denton Liu 2019-11-26 1:17 ` [PATCH v4 05/27] t3301: " Denton Liu 2019-11-26 1:17 ` [PATCH v4 06/27] t3600: use test_line_count() where possible Denton Liu 2019-11-26 1:18 ` [PATCH v4 07/27] t3600: stop losing return codes of git commands Denton Liu 2019-11-26 1:18 ` [PATCH v4 08/27] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu 2019-11-26 1:18 ` [PATCH v4 09/27] t4015: stop losing return codes of git commands Denton Liu 2019-11-26 1:18 ` [PATCH v4 10/27] t4015: use test_write_lines() Denton Liu 2019-11-26 1:18 ` [PATCH v4 11/27] t4138: stop losing return codes of git commands Denton Liu 2019-11-26 1:18 ` [PATCH v4 12/27] t5317: " Denton Liu 2019-11-26 1:18 ` [PATCH v4 13/27] t5317: use ! grep to check for no matching lines Denton Liu 2019-11-26 1:18 ` [PATCH v4 14/27] t5703: simplify one-time-sed generation logic Denton Liu 2019-11-26 1:18 ` [PATCH v4 15/27] t5703: stop losing return codes of git commands Denton Liu 2019-11-26 1:18 ` [PATCH v4 16/27] t7501: remove spaces after redirect operators Denton Liu 2019-11-26 1:18 ` [PATCH v4 17/27] t7501: stop losing return codes of git commands Denton Liu 2019-11-26 1:18 ` [PATCH v4 18/27] t7700: drop redirections to /dev/null Denton Liu 2019-11-26 1:18 ` [PATCH v4 19/27] t7700: remove spaces after redirect operators Denton Liu 2019-11-26 1:18 ` [PATCH v4 20/27] t7700: move keywords onto their own line Denton Liu 2019-11-26 1:18 ` [PATCH v4 21/27] t7700: s/test -f/test_path_is_file/ Denton Liu 2019-11-26 1:18 ` [PATCH v4 22/27] t7700: consolidate code into test_no_missing_in_packs() Denton Liu 2019-11-26 2:35 ` Eric Sunshine 2019-11-26 1:18 ` [PATCH v4 23/27] squash! " Denton Liu 2019-11-26 1:18 ` [PATCH v4 24/27] t7700: consolidate code into test_has_duplicate_object() Denton Liu 2019-11-26 1:18 ` [PATCH v4 25/27] t7700: replace egrep with grep Denton Liu 2019-11-26 1:18 ` [PATCH v4 26/27] t7700: make references to SHA-1 generic Denton Liu 2019-11-26 3:15 ` Eric Sunshine 2019-11-26 1:18 ` [PATCH v4 27/27] t7700: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 00/26] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-11-27 19:53 ` [PATCH v5 01/26] lib-bash.sh: move `then` onto its own line Denton Liu 2019-11-27 19:53 ` [PATCH v5 02/26] apply-one-time-sed.sh: modernize style Denton Liu 2019-11-27 19:53 ` [PATCH v5 03/26] t0014: remove git command upstream of pipe Denton Liu 2019-11-27 19:53 ` [PATCH v5 04/26] t0090: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 05/26] t3301: " Denton Liu 2019-11-27 19:53 ` [PATCH v5 06/26] t3600: use test_line_count() where possible Denton Liu 2019-11-27 19:53 ` [PATCH v5 07/26] t3600: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 08/26] t3600: comment on inducing SIGPIPE in `git rm` Denton Liu 2019-11-27 19:53 ` [PATCH v5 09/26] t4015: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 10/26] t4015: use test_write_lines() Denton Liu 2019-11-27 19:53 ` [PATCH v5 11/26] t4138: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 12/26] t5317: " Denton Liu 2019-11-27 19:53 ` [PATCH v5 13/26] t5317: use ! grep to check for no matching lines Denton Liu 2019-11-27 19:53 ` [PATCH v5 14/26] t5703: simplify one-time-sed generation logic Denton Liu 2019-11-27 19:53 ` [PATCH v5 15/26] t5703: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 16/26] t7501: remove spaces after redirect operators Denton Liu 2019-11-27 19:53 ` [PATCH v5 17/26] t7501: stop losing return codes of git commands Denton Liu 2019-11-27 19:53 ` [PATCH v5 18/26] t7700: drop redirections to /dev/null Denton Liu 2019-11-27 19:53 ` [PATCH v5 19/26] t7700: remove spaces after redirect operators Denton Liu 2019-11-27 19:53 ` [PATCH v5 20/26] t7700: move keywords onto their own line Denton Liu 2019-11-27 19:53 ` [PATCH v5 21/26] t7700: s/test -f/test_path_is_file/ Denton Liu 2019-11-27 19:53 ` [PATCH v5 22/26] t7700: consolidate code into test_no_missing_in_packs() Denton Liu 2019-11-29 21:39 ` Junio C Hamano 2019-12-02 20:50 ` Denton Liu 2019-12-02 22:53 ` Junio C Hamano 2019-12-02 23:28 ` Denton Liu 2019-12-03 15:41 ` Junio C Hamano 2019-12-04 7:24 ` Denton Liu 2019-12-04 18:13 ` Junio C Hamano 2019-12-04 22:03 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Denton Liu 2019-12-04 22:03 ` [PATCH v6 1/5] t7700: consolidate code into test_no_missing_in_packs() Denton Liu 2019-12-04 22:03 ` [PATCH v6 2/5] t7700: consolidate code into test_has_duplicate_object() Denton Liu 2019-12-04 22:03 ` [PATCH v6 3/5] t7700: replace egrep with grep Denton Liu 2019-12-04 22:03 ` [PATCH v6 4/5] t7700: make references to SHA-1 generic Denton Liu 2019-12-04 22:03 ` [PATCH v6 5/5] t7700: stop losing return codes of git commands Denton Liu 2019-12-04 22:07 ` [PATCH v6 0/5] t: test cleanup stemming from experimentally enabling pipefail Junio C Hamano 2019-11-27 19:53 ` [PATCH v5 23/26] t7700: consolidate code into test_has_duplicate_object() Denton Liu 2019-11-27 19:53 ` [PATCH v5 24/26] t7700: replace egrep with grep Denton Liu 2019-11-27 19:54 ` [PATCH v5 25/26] t7700: make references to SHA-1 generic Denton Liu 2019-11-27 19:54 ` [PATCH v5 26/26] t7700: stop losing return codes of git commands Denton Liu 2019-11-30 10:48 ` Danh Doan 2019-11-30 11:31 ` Eric Sunshine 2019-11-30 17:00 ` Junio C Hamano 2019-12-04 12:59 ` t: remove inappropriate uses of test_must_fail(), was " Denton Liu
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.