From df6d3d6802abcb89a30f4808fcca3bfe1485ce34 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 20 Nov 2019 16:45:48 -0800 Subject: lib-bash.sh: move `then` onto its own line The code style for tests is to have statements on their own line if possible. Move the `then` onto its own line so that it conforms with the test style. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/t/lib-bash.sh b/t/lib-bash.sh index 2be955f..b0b6060 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" "$@" -- cgit v0.10.2-6-g49f6 From 77a946be98f4cf2947f9aefac924c0ee78a042c7 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:06 -0800 Subject: apply-one-time-sed.sh: modernize style 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 Signed-off-by: Junio C Hamano diff --git a/t/lib-httpd/apply-one-time-sed.sh b/t/lib-httpd/apply-one-time-sed.sh index fcef728..bf7689d 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_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 -- cgit v0.10.2-6-g49f6 From 17aa9d9c1af316d60ce6573daf0ff7b28bf009ed Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:08 -0800 Subject: t0014: remove git command upstream of pipe 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 Signed-off-by: Junio C Hamano diff --git a/t/t0014-alias.sh b/t/t0014-alias.sh index 2694c81..8d3d914 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 ' -- cgit v0.10.2-6-g49f6 From 9b5a9fa60a444058c07c6f8df08fd779aaebfaae Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:11 -0800 Subject: t0090: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t0090-cache-tree.sh b/t/t0090-cache-tree.sh index ce9a4a5..5a63369 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 Date: Wed, 27 Nov 2019 11:53:13 -0800 Subject: t3301: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t3301-notes.sh b/t/t3301-notes.sh index d66a5f6..8f43303 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 "' ' - 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 + 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 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 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 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 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 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 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 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 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 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 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 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 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' ' -- cgit v0.10.2-6-g49f6 From 0d913dfa7e41f31befb080512d2e8524338f1907 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:16 -0800 Subject: t3600: use test_line_count() where possible 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 Signed-off-by: Junio C Hamano diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 8c8cca5..f6e659b 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" ' -- cgit v0.10.2-6-g49f6 From 3b737381d880bd6db1b09d8721f806774931853a Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:18 -0800 Subject: t3600: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index f6e659b..0c3bf10 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 && -- cgit v0.10.2-6-g49f6 From 50cd31c6526637e59ca180397aba425ec7a1e218 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:20 -0800 Subject: t3600: comment on inducing SIGPIPE in `git rm` 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 Signed-off-by: Junio C Hamano diff --git a/t/t3600-rm.sh b/t/t3600-rm.sh index 0c3bf10..0ea858d 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 ' -- cgit v0.10.2-6-g49f6 From 946d2353a36a6e1ce86e0bcade7ebd304d1c67a8 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:24 -0800 Subject: t4015: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index eadaf57..7fb83c8 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 && cat >expected <<-EOF && diff --git a/x b/x @@ -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 && cat >expected <<-EOF && diff --git a/x b/x @@ -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 && diff --git a/x b/x @@ -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 && 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 && 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 && 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 && 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 && 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 && 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 && 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 && 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 && 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 && cat >expected <<-EOF && diff --git a/main.c b/main.c new file mode 100644 @@ -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 && cat <<-EOF >expected && diff --git a/main.c b/main.c index $before_main..$after_main 100644 @@ -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 && cat <<-EOF >expected && diff --git a/main.c b/main.c index $before_main..$after_main 100644 @@ -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 && test_cmp expect decoded_actual && rm -rf bananas && git submodule deinit bananas -- cgit v0.10.2-6-g49f6 From afd43c99054a3d666e150bcee66183169b67df7f Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:26 -0800 Subject: t4015: use test_write_lines() 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 Signed-off-by: Junio C Hamano diff --git a/t/t4015-diff-whitespace.sh b/t/t4015-diff-whitespace.sh index 7fb83c8..4c540b1 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 ' -- cgit v0.10.2-6-g49f6 From b66e0a1773e941f3cd6b837346dfa98cbb8ddabb Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:29 -0800 Subject: t4138: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t4138-apply-ws-expansion.sh b/t/t4138-apply-ws-expansion.sh index 3b636a6..b19faeb 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 -- cgit v0.10.2-6-g49f6 From 6c37f3ec1b89f317bd379ce4db307f700ca4acd9 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:31 -0800 Subject: t5317: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index 2d2f5d0..a8bbad7 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 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 -- cgit v0.10.2-6-g49f6 From a29b2429e583794c27d9527e105b1ce7500e8062 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:33 -0800 Subject: t5317: use ! grep to check for no matching lines 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 Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/t/t5317-pack-objects-filter-objects.sh b/t/t5317-pack-objects-filter-objects.sh index a8bbad7..dc04465 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 verify_result && - grep blob verify_result | - awk -f print_1.awk | - sort >observed && - - nr=$(wc -l verify_result && - grep blob verify_result | - awk -f print_1.awk | - sort >observed && - - nr=$(wc -l Date: Wed, 27 Nov 2019 11:53:36 -0800 Subject: t5703: simplify one-time-sed generation logic 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 Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 3a2c143..88338c4 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' ' -- cgit v0.10.2-6-g49f6 From 763b47bafab6f781dc52461985b3300d447d1332 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:38 -0800 Subject: t5703: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t5703-upload-pack-ref-in-want.sh b/t/t5703-upload-pack-ref-in-want.sh index 88338c4..1424fab 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 }' 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 ' -- cgit v0.10.2-6-g49f6 From 38c1aa01de8220f84460ef115f1c1fc58b590240 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:40 -0800 Subject: t7501: remove spaces after redirect operators 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 Signed-off-by: Junio C Hamano diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index f1349af..5765d33 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 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 && -- cgit v0.10.2-6-g49f6 From 756ee7fc9fcf599e807a27e45a9d0fb89e8411a8 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:43 -0800 Subject: t7501: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t7501-commit-basic-functionality.sh b/t/t7501-commit-basic-functionality.sh index 5765d33..110b4bf 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 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 ' -- cgit v0.10.2-6-g49f6 From 09279086e8c92c77cc75f73dcac35062e6e68fd3 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:45 -0800 Subject: t7700: drop redirections to /dev/null 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 4e855bc..e1a689d 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 && + 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" ' -- cgit v0.10.2-6-g49f6 From 7a1c8c2346d43b4e5e5a59997288ae805a2a5019 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:47 -0800 Subject: t7700: remove spaces after redirect operators 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index e1a689d..8936928 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 -- cgit v0.10.2-6-g49f6 From d2eee32a8980c12be05c96e3ca84084a6234be32 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:49 -0800 Subject: t7700: move keywords onto their own line 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 8936928..a96e876 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 -- cgit v0.10.2-6-g49f6 From 17a4ae92eaa2f9614d739c11c3b60932a0f272b9 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 27 Nov 2019 11:53:52 -0800 Subject: t7700: s/test -f/test_path_is_file/ 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index a96e876..1d14ddc 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" -- cgit v0.10.2-6-g49f6 From ae475afc0f8685607e2de838db7fb4bee7934d4d Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 14:03:09 -0800 Subject: t7700: consolidate code into test_no_missing_in_packs() The code to test that objects were not missing from the packfile was duplicated many times. Extract the duplicated code into test_no_missing_in_packs() and use that instead. Refactor the resulting extraction so that if any git commands fail, their return codes are not silently lost. Instead of verifying each file of `alt_objects/pack/*.idx` individually in a for-loop, batch them together into one verification step. The original testing construct was O(n^2): it used a grep in a loop to test whether any objects were missing in the packfile. Rewrite this to extract the hash using sed or cut, sort the files, then use `comm -23` so that finding missing lines from the original file is done more efficiently. While we're at it, add a space to `commit_and_pack ()` for style. Signed-off-by: Denton Liu Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 1d14ddc..5fb9e99 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 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' ' -- cgit v0.10.2-6-g49f6 From cfe5eda02abddaaeb78c4e8bb31357112f0d5413 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 14:03:14 -0800 Subject: t7700: consolidate code into test_has_duplicate_object() 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 5fb9e99..80ded48 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' ' -- cgit v0.10.2-6-g49f6 From dcf9a748cabedd6353d411eb5119fbe7fdda6ff5 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 14:03:19 -0800 Subject: t7700: replace egrep with grep 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 80ded48..bfef588 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 ' -- cgit v0.10.2-6-g49f6 From 3699d69df0345309ba16b9c7fb43fd86a7595f58 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 14:03:24 -0800 Subject: t7700: make references to SHA-1 generic 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index bfef588..5229999 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 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' ' -- cgit v0.10.2-6-g49f6 From d9b31db2c42580af96499e763f4a681803f72826 Mon Sep 17 00:00:00 2001 From: Denton Liu Date: Wed, 4 Dec 2019 14:03:30 -0800 Subject: t7700: stop losing return codes of git commands 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 Signed-off-by: Junio C Hamano diff --git a/t/t7700-repack.sh b/t/t7700-repack.sh index 5229999..25b235c 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 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 packlist && + ! grep "^$coid " && echo >.git/objects/info/alternates && test_must_fail git show $coid ' -- cgit v0.10.2-6-g49f6