Merge branch 'md/test-cleanup'
authorJunio C Hamano <gitster@pobox.com>
Tue, 16 Oct 2018 07:16:01 +0000 (16:16 +0900)
committerJunio C Hamano <gitster@pobox.com>
Tue, 16 Oct 2018 07:16:01 +0000 (16:16 +0900)
Various test scripts have been updated for style and also correct
handling of exit status of various commands.

* md/test-cleanup:
tests: order arguments to git-rev-list properly
t9109: don't swallow Git errors upstream of pipes
tests: don't swallow Git errors upstream of pipes
t/*: fix ordering of expected/observed arguments
tests: standardize pipe placement
Documentation: add shell guidelines
t/README: reformat Do, Don't, Keep in mind lists

1  2 
t/README
t/t0000-basic.sh
t/t1006-cat-file.sh
t/t5318-commit-graph.sh
t/t5701-git-serve.sh
t/t5702-protocol-v2.sh
diff --combined t/README
index 5e48a043cef01b10935574fa302e44679980a3b5,3054e1534a5e5d74e9259fea54cbad79c594499b..4d8dbc7c5f5800bb838a09a8ca87fab8a3de72ab
+++ b/t/README
@@@ -401,13 -401,13 +401,13 @@@ This test harness library does the foll
     consistently when command line arguments --verbose (or -v),
     --debug (or -d), and --immediate (or -i) is given.
  
- Do's, don'ts & things to keep in mind
- -------------------------------------
+ Do's & don'ts
+ -------------
  
  Here are a few examples of things you probably should and shouldn't do
  when writing tests.
  
- Do:
+ Here are the "do's:"
  
   - Put all code inside test_expect_success and other assertions.
  
     Windows, where the shell (MSYS bash) mangles absolute path names.
     For details, see the commit message of 4114156ae9.
  
- Don't:
+  - Remember that inside the <script> part, the standard output and
+    standard error streams are discarded, and the test harness only
+    reports "ok" or "not ok" to the end user running the tests. Under
+    --verbose, they are shown to help debug the tests.
+ And here are the "don'ts:"
  
-  - exit() within a <script> part.
+  - Don't exit() within a <script> part.
  
     The harness will catch this as a programming error of the test.
     Use test_done instead if you need to stop the tests early (see
     "Skipping tests" below).
  
-  - use '! git cmd' when you want to make sure the git command exits
-    with failure in a controlled way by calling "die()".  Instead,
+  - 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).
  
     platform commands; just use '! cmd'.  We are not in the business
     of verifying that the world given to us sanely works.
  
-  - use perl without spelling it as "$PERL_PATH". This is to help our
-    friends on Windows where the platform Perl often adds CR before
+  - Don't feed the output of a git command to a pipe, as in:
+      git -C repo ls-files |
+      xargs -n 1 basename |
+      grep foo
+    which will discard git's exit code and may mask a crash. In the
+    above example, all exit codes are ignored except grep's.
+    Instead, write the output of that command to a temporary
+    file with ">" or assign it to a variable with "x=$(git ...)" rather
+    than pipe it.
+  - Don't use command substitution in a way that discards git's exit
+    code. When assigning to a variable, the exit code is not discarded,
+    e.g.:
+      x=$(git cat-file -p $sha) &&
+      ...
+    is OK because a crash in "git cat-file" will cause the "&&" chain
+    to fail, but:
+      test "refs/heads/foo" = "$(git symbolic-ref HEAD)"
+    is not OK and a crash in git could go undetected.
+  - Don't use perl without spelling it as "$PERL_PATH". This is to help
+    our friends on Windows where the platform Perl often adds CR before
     the end of line, and they bundle Git with a version of Perl that
     does not do so, whose path is specified with $PERL_PATH. Note that we
     provide a "perl" function which uses $PERL_PATH under the hood, so
     (but you do, for example, on a shebang line or in a sub script
     created via "write_script").
  
-  - use sh without spelling it as "$SHELL_PATH", when the script can
-    be misinterpreted by broken platform shell (e.g. Solaris).
+  - Don't use sh without spelling it as "$SHELL_PATH", when the script
+    can be misinterpreted by broken platform shell (e.g. Solaris).
  
-  - chdir around in tests.  It is not sufficient to chdir to
+  - Don't chdir around in tests.  It is not sufficient to chdir to
     somewhere and then chdir back to the original location later in
     the test, as any intermediate step can fail and abort the test,
     causing the next test to start in an unexpected directory.  Do so
     inside a subshell if necessary.
  
-  - save and verify the standard error of compound commands, i.e. group
-    commands, subshells, and shell functions (except test helper
+  - Don't save and verify the standard error of compound commands, i.e.
+    group commands, subshells, and shell functions (except test helper
     functions like 'test_must_fail') like this:
  
       ( cd dir && git cmd ) 2>error &&
       ( cd dir && git cmd 2>../error ) &&
       test_cmp expect error
  
-  - Break the TAP output
+  - Don't break the TAP output
  
     The raw output from your test may be interpreted by a TAP harness. TAP
     harnesses will ignore everything they don't know about, but don't step
     but the best indication is to just run the tests with prove(1),
     it'll complain if anything is amiss.
  
- Keep in mind:
-  - Inside the <script> part, the standard output and standard error
-    streams are discarded, and the test harness only reports "ok" or
-    "not ok" to the end user running the tests. Under --verbose, they
-    are shown to help debugging the tests.
  
  Skipping tests
  --------------
@@@ -814,28 -839,6 +839,28 @@@ library for your script to use
     the symbolic link in the file system and a part that does; then only
     the latter part need be protected by a SYMLINKS prerequisite (see below).
  
 + - test_oid_init
 +
 +   This function loads facts and useful object IDs related to the hash
 +   algorithm(s) in use from the files in t/oid-info.
 +
 + - test_oid_cache
 +
 +   This function reads per-hash algorithm information from standard
 +   input (usually a heredoc) in the format described in
 +   t/oid-info/README.  This is useful for test-specific values, such as
 +   object IDs, which must vary based on the hash algorithm.
 +
 +   Certain fixed values, such as hash sizes and common placeholder
 +   object IDs, can be loaded with test_oid_init (described above).
 +
 + - test_oid <key>
 +
 +   This function looks up a value for the hash algorithm in use, based
 +   on the key given.  The value must have been loaded using
 +   test_oid_init or test_oid_cache.  Providing an unknown key is an
 +   error.
 +
  Prerequisites
  -------------
  
diff --combined t/t0000-basic.sh
index 391f910c6a9fceff7a03e523076399f2db1cc0f0,224c098a85c6816c992ce63f1faee39f4867905a..26601e698bd3abebd2e1f10ba6012f80c65ffa85
@@@ -821,87 -821,9 +821,87 @@@ test_expect_success 'tests clean up eve
        EOF
  "
  
 +test_expect_success 'test_oid setup' '
 +      test_oid_init
 +'
 +
 +test_expect_success 'test_oid provides sane info by default' '
 +      test_oid zero >actual &&
 +      grep "^00*\$" actual &&
 +      rawsz="$(test_oid rawsz)" &&
 +      hexsz="$(test_oid hexsz)" &&
 +      test "$hexsz" -eq $(wc -c <actual) &&
 +      test $(( $rawsz * 2)) -eq "$hexsz"
 +'
 +
 +test_expect_success 'test_oid can look up data for SHA-1' '
 +      test_when_finished "test_detect_hash" &&
 +      test_set_hash sha1 &&
 +      test_oid zero >actual &&
 +      grep "^00*\$" actual &&
 +      rawsz="$(test_oid rawsz)" &&
 +      hexsz="$(test_oid hexsz)" &&
 +      test $(wc -c <actual) -eq 40 &&
 +      test "$rawsz" -eq 20 &&
 +      test "$hexsz" -eq 40
 +'
 +
 +test_expect_success 'test_oid can look up data for SHA-256' '
 +      test_when_finished "test_detect_hash" &&
 +      test_set_hash sha256 &&
 +      test_oid zero >actual &&
 +      grep "^00*\$" actual &&
 +      rawsz="$(test_oid rawsz)" &&
 +      hexsz="$(test_oid hexsz)" &&
 +      test $(wc -c <actual) -eq 64 &&
 +      test "$rawsz" -eq 32 &&
 +      test "$hexsz" -eq 64
 +'
 +
  ################################################################
  # Basics of the basics
  
 +test_oid_cache <<\EOF
 +path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154
 +path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
 +
 +path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01
 +path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
 +
 +path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
 +path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
 +
 +path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38
 +path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
 +
 +path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe
 +path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
 +
 +path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376
 +path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
 +
 +path3s sha1:8599103969b43aff7e430efea79ca4636466794f
 +path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
 +
 +path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3
 +path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
 +
 +subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f
 +subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
 +
 +subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
 +subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
 +
 +subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
 +subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
 +
 +root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b
 +root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
 +
 +simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
 +simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
 +EOF
 +
  # updating a new file without --add should fail.
  test_expect_success 'git update-index without --add should fail adding' '
        test_must_fail git update-index should-be-empty
@@@ -917,8 -839,8 +917,8 @@@ test_expect_success 'writing tree out w
  '
  
  # we know the shape and contents of the tree and know the object ID for it.
 -test_expect_success SHA1 'validate object ID of a known tree' '
 -      test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
 +test_expect_success 'validate object ID of a known tree' '
 +      test "$tree" = "$(test_oid simpletree)"
      '
  
  # Removing paths.
@@@ -960,16 -882,16 +960,16 @@@ test_expect_success 'showing stage wit
        git ls-files --stage >current
  '
  
 -test_expect_success SHA1 'validate git ls-files output for a known tree' '
 -      cat >expected <<-\EOF &&
 -      100644 f87290f8eb2cbbea7857214459a0739927eab154 0       path0
 -      120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0       path0sym
 -      100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0       path2/file2
 -      120000 d8ce161addc5173867a3c3c730924388daedbc38 0       path2/file2sym
 -      100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0       path3/file3
 -      120000 8599103969b43aff7e430efea79ca4636466794f 0       path3/file3sym
 -      100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0       path3/subp3/file3
 -      120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0       path3/subp3/file3sym
 +test_expect_success 'validate git ls-files output for a known tree' '
 +      cat >expected <<-EOF &&
 +      100644 $(test_oid path0f) 0     path0
 +      120000 $(test_oid path0s) 0     path0sym
 +      100644 $(test_oid path2f) 0     path2/file2
 +      120000 $(test_oid path2s) 0     path2/file2sym
 +      100644 $(test_oid path3f) 0     path3/file3
 +      120000 $(test_oid path3s) 0     path3/file3sym
 +      100644 $(test_oid subp3f) 0     path3/subp3/file3
 +      120000 $(test_oid subp3s) 0     path3/subp3/file3sym
        EOF
        test_cmp expected current
  '
@@@ -978,20 -900,20 +978,20 @@@ test_expect_success 'writing tree out w
        tree=$(git write-tree)
  '
  
 -test_expect_success SHA1 'validate object ID for a known tree' '
 -      test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
 +test_expect_success 'validate object ID for a known tree' '
 +      test "$tree" = "$(test_oid root)"
  '
  
  test_expect_success 'showing tree with git ls-tree' '
      git ls-tree $tree >current
  '
  
 -test_expect_success SHA1 'git ls-tree output for a known tree' '
 -      cat >expected <<-\EOF &&
 -      100644 blob f87290f8eb2cbbea7857214459a0739927eab154    path0
 -      120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01    path0sym
 -      040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe    path2
 -      040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3    path3
 +test_expect_success 'git ls-tree output for a known tree' '
 +      cat >expected <<-EOF &&
 +      100644 blob $(test_oid path0f)  path0
 +      120000 blob $(test_oid path0s)  path0sym
 +      040000 tree $(test_oid path2d)  path2
 +      040000 tree $(test_oid path3d)  path3
        EOF
        test_cmp expected current
  '
@@@ -1002,16 -924,16 +1002,16 @@@ test_expect_success 'showing tree with 
        git ls-tree -r $tree >current
  '
  
 -test_expect_success SHA1 'git ls-tree -r output for a known tree' '
 -      cat >expected <<-\EOF &&
 -      100644 blob f87290f8eb2cbbea7857214459a0739927eab154    path0
 -      120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01    path0sym
 -      100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7    path2/file2
 -      120000 blob d8ce161addc5173867a3c3c730924388daedbc38    path2/file2sym
 -      100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376    path3/file3
 -      120000 blob 8599103969b43aff7e430efea79ca4636466794f    path3/file3sym
 -      100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f    path3/subp3/file3
 -      120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c    path3/subp3/file3sym
 +test_expect_success 'git ls-tree -r output for a known tree' '
 +      cat >expected <<-EOF &&
 +      100644 blob $(test_oid path0f)  path0
 +      120000 blob $(test_oid path0s)  path0sym
 +      100644 blob $(test_oid path2f)  path2/file2
 +      120000 blob $(test_oid path2s)  path2/file2sym
 +      100644 blob $(test_oid path3f)  path3/file3
 +      120000 blob $(test_oid path3s)  path3/file3sym
 +      100644 blob $(test_oid subp3f)  path3/subp3/file3
 +      120000 blob $(test_oid subp3s)  path3/subp3/file3sym
        EOF
        test_cmp expected current
  '
@@@ -1021,19 -943,19 +1021,19 @@@ test_expect_success 'showing tree with 
        git ls-tree -r -t $tree >current
  '
  
 -test_expect_success SHA1 'git ls-tree -r output for a known tree' '
 -      cat >expected <<-\EOF &&
 -      100644 blob f87290f8eb2cbbea7857214459a0739927eab154    path0
 -      120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01    path0sym
 -      040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe    path2
 -      100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7    path2/file2
 -      120000 blob d8ce161addc5173867a3c3c730924388daedbc38    path2/file2sym
 -      040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3    path3
 -      100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376    path3/file3
 -      120000 blob 8599103969b43aff7e430efea79ca4636466794f    path3/file3sym
 -      040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2    path3/subp3
 -      100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f    path3/subp3/file3
 -      120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c    path3/subp3/file3sym
 +test_expect_success 'git ls-tree -r output for a known tree' '
 +      cat >expected <<-EOF &&
 +      100644 blob $(test_oid path0f)  path0
 +      120000 blob $(test_oid path0s)  path0sym
 +      040000 tree $(test_oid path2d)  path2
 +      100644 blob $(test_oid path2f)  path2/file2
 +      120000 blob $(test_oid path2s)  path2/file2sym
 +      040000 tree $(test_oid path3d)  path3
 +      100644 blob $(test_oid path3f)  path3/file3
 +      120000 blob $(test_oid path3s)  path3/file3sym
 +      040000 tree $(test_oid subp3d)  path3/subp3
 +      100644 blob $(test_oid subp3f)  path3/subp3/file3
 +      120000 blob $(test_oid subp3s)  path3/subp3/file3sym
        EOF
        test_cmp expected current
  '
@@@ -1042,27 -964,26 +1042,27 @@@ test_expect_success 'writing partial tr
        ptree=$(git write-tree --prefix=path3)
  '
  
 -test_expect_success SHA1 'validate object ID for a known tree' '
 -      test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
 +test_expect_success 'validate object ID for a known tree' '
 +      test "$ptree" = $(test_oid path3d)
  '
  
  test_expect_success 'writing partial tree out with git write-tree --prefix' '
        ptree=$(git write-tree --prefix=path3/subp3)
  '
  
 -test_expect_success SHA1 'validate object ID for a known tree' '
 -      test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
 +test_expect_success 'validate object ID for a known tree' '
 +      test "$ptree" = $(test_oid subp3d)
  '
  
  test_expect_success 'put invalid objects into the index' '
        rm -f .git/index &&
 -      cat >badobjects <<-\EOF &&
 -      100644 blob 1000000000000000000000000000000000000000    dir/file1
 -      100644 blob 2000000000000000000000000000000000000000    dir/file2
 -      100644 blob 3000000000000000000000000000000000000000    dir/file3
 -      100644 blob 4000000000000000000000000000000000000000    dir/file4
 -      100644 blob 5000000000000000000000000000000000000000    dir/file5
 +      suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
 +      cat >badobjects <<-EOF &&
 +      100644 blob $(test_oid 001)     dir/file1
 +      100644 blob $(test_oid 002)     dir/file2
 +      100644 blob $(test_oid 003)     dir/file3
 +      100644 blob $(test_oid 004)     dir/file4
 +      100644 blob $(test_oid 005)     dir/file5
        EOF
        git update-index --index-info <badobjects
  '
@@@ -1085,19 -1006,19 +1085,19 @@@ test_expect_success 'git read-tree foll
        test "$newtree" = "$tree"
  '
  
 -test_expect_success SHA1 'validate git diff-files output for a know cache/work tree state' '
 -      cat >expected <<\EOF &&
 -:100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M    path0
 -:120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M    path0sym
 -:100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M    path2/file2
 -:120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M    path2/file2sym
 -:100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M    path3/file3
 -:120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M    path3/file3sym
 -:100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M    path3/subp3/file3
 -:120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M    path3/subp3/file3sym
 +test_expect_success 'validate git diff-files output for a know cache/work tree state' '
 +      cat >expected <<EOF &&
 +:100644 100644 $(test_oid path0f) $ZERO_OID M path0
 +:120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
 +:100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
 +:120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
 +:100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
 +:120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
 +:100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
 +:120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
  EOF
        git diff-files >current &&
-       test_cmp current expected
+       test_cmp expected current
  '
  
  test_expect_success 'git update-index --refresh should succeed' '
@@@ -1110,23 -1031,23 +1110,23 @@@ test_expect_success 'no diff after chec
  '
  
  ################################################################
 -P=087704a96baf1c2d1c869a8b084481e121c88b5b
 +P=$(test_oid root)
  
 -test_expect_success SHA1 'git commit-tree records the correct tree in a commit' '
 +test_expect_success 'git commit-tree records the correct tree in a commit' '
        commit0=$(echo NO | git commit-tree $P) &&
        tree=$(git show --pretty=raw $commit0 |
                 sed -n -e "s/^tree //p" -e "/^author /q") &&
        test "z$tree" = "z$P"
  '
  
 -test_expect_success SHA1 'git commit-tree records the correct parent in a commit' '
 +test_expect_success 'git commit-tree records the correct parent in a commit' '
        commit1=$(echo NO | git commit-tree $P -p $commit0) &&
        parent=$(git show --pretty=raw $commit1 |
                sed -n -e "s/^parent //p" -e "/^author /q") &&
        test "z$commit0" = "z$parent"
  '
  
 -test_expect_success SHA1 'git commit-tree omits duplicated parent in a commit' '
 +test_expect_success 'git commit-tree omits duplicated parent in a commit' '
        commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
             parent=$(git show --pretty=raw $commit2 |
                sed -n -e "s/^parent //p" -e "/^author /q" |
diff --combined t/t1006-cat-file.sh
index a7c95bb785879f083f469ce1ba7d5d2836cb7906,83980b7887085312993a854b1e4c856fa3089e24..43c4be1e5ef559d10ca276ef777a8fe7ba8a3971
@@@ -140,17 -140,15 +140,17 @@@ test_expect_success '--batch-check with
        test_cmp expect actual
  '
  
 +test_oid_init
 +
  tree_sha1=$(git write-tree)
 -tree_size=33
 +tree_size=$(($(test_oid rawsz) + 13))
  tree_pretty_content="100644 blob $hello_sha1  hello"
  
  run_tests 'tree' $tree_sha1 $tree_size "" "$tree_pretty_content"
  
  commit_message="Initial commit"
  commit_sha1=$(echo_without_newline "$commit_message" | git commit-tree $tree_sha1)
 -commit_size=177
 +commit_size=$(($(test_oid hexsz) + 137))
  commit_content="tree $tree_sha1
  author $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL> 0000000000 +0000
  committer $GIT_COMMITTER_NAME <$GIT_COMMITTER_EMAIL> 0000000000 +0000
@@@ -220,8 -218,8 +220,8 @@@ test_expect_success "--batch-check for 
      test "0000000000000000000000000000000000000042 missing
  0000000000000000000000000000000000000084 missing" = \
      "$( ( echo 0000000000000000000000000000000000000042;
-          echo_without_newline 0000000000000000000000000000000000000084; ) \
-        git cat-file --batch-check)"
+        echo_without_newline 0000000000000000000000000000000000000084; ) |
+        git cat-file --batch-check)"
  '
  
  test_expect_success "--batch for an existent and a non-existent hash" '
  $tag_content
  0000000000000000000000000000000000000000 missing" = \
      "$( ( echo $tag_sha1;
-          echo_without_newline 0000000000000000000000000000000000000000; ) \
-        git cat-file --batch)"
+        echo_without_newline 0000000000000000000000000000000000000000; ) |
+        git cat-file --batch)"
  '
  
  test_expect_success "--batch-check for an empty line" '
diff --combined t/t5318-commit-graph.sh
index db8dcafca3c764f17ca323be91af65d991ccb73a,d6da3ce4e203cdc4017de227adf196d75b4badb2..5fe21db99f43aa79dc36ab36bf6d40ca2f47264d
@@@ -8,8 -8,7 +8,8 @@@ test_expect_success 'setup full repo' 
        cd "$TRASH_DIRECTORY/full" &&
        git init &&
        git config core.commitGraph true &&
 -      objdir=".git/objects"
 +      objdir=".git/objects" &&
 +      test_oid_init
  '
  
  test_expect_success 'verify graph with no graph file' '
@@@ -36,7 -35,7 +36,7 @@@ test_expect_success 'create commits an
  graph_git_two_modes() {
        git -c core.commitGraph=true $1 >output
        git -c core.commitGraph=false $1 >expect
-       test_cmp output expect
+       test_cmp expect output
  }
  
  graph_git_behavior() {
@@@ -260,66 -259,6 +260,66 @@@ test_expect_success 'check that gc comp
        test_cmp_bin commit-graph-after-gc $objdir/info/commit-graph
  '
  
 +test_expect_success 'replace-objects invalidates commit-graph' '
 +      cd "$TRASH_DIRECTORY" &&
 +      test_when_finished rm -rf replace &&
 +      git clone full replace &&
 +      (
 +              cd replace &&
 +              git commit-graph write --reachable &&
 +              test_path_is_file .git/objects/info/commit-graph &&
 +              git replace HEAD~1 HEAD~2 &&
 +              git -c core.commitGraph=false log >expect &&
 +              git -c core.commitGraph=true log >actual &&
 +              test_cmp expect actual &&
 +              git commit-graph write --reachable &&
 +              git -c core.commitGraph=false --no-replace-objects log >expect &&
 +              git -c core.commitGraph=true --no-replace-objects log >actual &&
 +              test_cmp expect actual &&
 +              rm -rf .git/objects/info/commit-graph &&
 +              git commit-graph write --reachable &&
 +              test_path_is_file .git/objects/info/commit-graph
 +      )
 +'
 +
 +test_expect_success 'commit grafts invalidate commit-graph' '
 +      cd "$TRASH_DIRECTORY" &&
 +      test_when_finished rm -rf graft &&
 +      git clone full graft &&
 +      (
 +              cd graft &&
 +              git commit-graph write --reachable &&
 +              test_path_is_file .git/objects/info/commit-graph &&
 +              H1=$(git rev-parse --verify HEAD~1) &&
 +              H3=$(git rev-parse --verify HEAD~3) &&
 +              echo "$H1 $H3" >.git/info/grafts &&
 +              git -c core.commitGraph=false log >expect &&
 +              git -c core.commitGraph=true log >actual &&
 +              test_cmp expect actual &&
 +              git commit-graph write --reachable &&
 +              git -c core.commitGraph=false --no-replace-objects log >expect &&
 +              git -c core.commitGraph=true --no-replace-objects log >actual &&
 +              test_cmp expect actual &&
 +              rm -rf .git/objects/info/commit-graph &&
 +              git commit-graph write --reachable &&
 +              test_path_is_missing .git/objects/info/commit-graph
 +      )
 +'
 +
 +test_expect_success 'replace-objects invalidates commit-graph' '
 +      cd "$TRASH_DIRECTORY" &&
 +      test_when_finished rm -rf shallow &&
 +      git clone --depth 2 "file://$TRASH_DIRECTORY/full" shallow &&
 +      (
 +              cd shallow &&
 +              git commit-graph write --reachable &&
 +              test_path_is_missing .git/objects/info/commit-graph &&
 +              git fetch origin --unshallow &&
 +              git commit-graph write --reachable &&
 +              test_path_is_file .git/objects/info/commit-graph
 +      )
 +'
 +
  # the verify tests below expect the commit-graph to contain
  # exactly the commits reachable from the commits/8 branch.
  # If the file changes the set of commits in the list, then the
@@@ -334,7 -273,7 +334,7 @@@ test_expect_success 'git commit-graph v
  
  NUM_COMMITS=9
  NUM_OCTOPUS_EDGES=2
 -HASH_LEN=20
 +HASH_LEN="$(test_oid rawsz)"
  GRAPH_BYTE_VERSION=4
  GRAPH_BYTE_HASH=5
  GRAPH_BYTE_CHUNK_COUNT=6
diff --combined t/t5701-git-serve.sh
index 29a54fbfff2b1ade62cea815192ca12b941c6acd,bf139e245937bc1dca1eeb924dbf193a7c347a2a..ae79c6bbc0d66e9a7a184b2d1726a316a0affbbe
@@@ -15,13 -15,13 +15,13 @@@ test_expect_success 'test capability ad
        EOF
  
        git serve --advertise-capabilities >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'stateless-rpc flag does not list capabilities' '
        # Empty request
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        0000
        EOF
        git serve --stateless-rpc >out <in &&
@@@ -33,7 -33,7 +33,7 @@@
  '
  
  test_expect_success 'request invalid capability' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        foobar
        0000
        EOF
@@@ -42,7 -42,7 +42,7 @@@
  '
  
  test_expect_success 'request with no command' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        agent=git/test
        0000
        EOF
@@@ -51,7 -51,7 +51,7 @@@
  '
  
  test_expect_success 'request invalid command' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=foo
        agent=git/test
        0000
@@@ -71,7 -71,7 +71,7 @@@ test_expect_success 'setup some refs an
  '
  
  test_expect_success 'basics of ls-refs' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs
        0000
        EOF
        EOF
  
        git serve --stateless-rpc <in >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'basic ref-prefixes' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs
        0001
        ref-prefix refs/heads/master
        EOF
  
        git serve --stateless-rpc <in >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'refs/heads prefix' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs
        0001
        ref-prefix refs/heads/
        EOF
  
        git serve --stateless-rpc <in >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'peel parameter' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs
        0001
        peel
        EOF
  
        git serve --stateless-rpc <in >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'symrefs parameter' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs
        0001
        symrefs
        EOF
  
        git serve --stateless-rpc <in >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'sending server-options' '
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=ls-refs
        server-option=hello
        server-option=world
        EOF
  
        git serve --stateless-rpc <in >out &&
 -      test-pkt-line unpack <out >actual &&
 +      test-tool pkt-line unpack <out >actual &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'unexpected lines are not allowed in fetch request' '
        git init server &&
  
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=fetch
        0001
        this-is-not-a-command
diff --combined t/t5702-protocol-v2.sh
index 88a886975df1d031553efb96e33116df122f0491,11a84efffeb55940f1800d5552b7895d5995b9c2..98fbf39da325ab574f9717a03c6a6588b15f0ffa
@@@ -29,7 -29,7 +29,7 @@@ test_expect_success 'list refs with git
        grep "git< version 2" log &&
  
        git ls-remote --symref "$GIT_DAEMON_URL/parent" >expect &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
@@@ -42,7 -42,7 +42,7 @@@
        $(git -C "$daemon_parent" rev-parse refs/heads/master)$(printf "\t")refs/heads/master
        EOF
  
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'clone with git:// using protocol v2' '
@@@ -138,7 -138,7 +138,7 @@@ test_expect_success 'list refs with fil
        grep "git< version 2" log &&
  
        git ls-remote --symref "file://$(pwd)/file_parent" >expect &&
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'ref advertisment is filtered with ls-remote using protocol v2' '
        $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master
        EOF
  
-       test_cmp actual expect
+       test_cmp expect actual
  '
  
  test_expect_success 'server-options are sent when using ls-remote' '
        $(git -C file_parent rev-parse refs/heads/master)$(printf "\t")refs/heads/master
        EOF
  
-       test_cmp actual expect &&
+       test_cmp expect actual &&
        grep "server-option=hello" log &&
        grep "server-option=world" log
  '
@@@ -271,7 -271,7 +271,7 @@@ test_expect_success 'partial clone' 
        grep "version 2" trace &&
  
        # Ensure that the old version of the file is missing
-       git -C client rev-list master --quiet --objects --missing=print \
+       git -C client rev-list --quiet --objects --missing=print master \
                >observed.oids &&
        grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
  
@@@ -297,7 -297,7 +297,7 @@@ test_expect_success 'partial fetch' 
        grep "version 2" trace &&
  
        # Ensure that the old version of the file is missing
-       git -C client rev-list other --quiet --objects --missing=print \
+       git -C client rev-list --quiet --objects --missing=print other \
                >observed.oids &&
        grep "$(git -C server rev-parse message1:a.txt)" observed.oids &&
  
@@@ -334,7 -334,7 +334,7 @@@ test_expect_success 'even with handcraf
        git -C server config uploadpack.allowfilter 0 &&
  
        # Custom request that tries to filter even though it is not advertised.
 -      test-pkt-line pack >in <<-EOF &&
 +      test-tool pkt-line pack >in <<-EOF &&
        command=fetch
        0001
        want $(git -C server rev-parse master)