@@ -821,9 +821,87 @@ test_expect_success 'tests clean up even on failures' "
821821 EOF
822822"
823823
824+ test_expect_success ' test_oid setup' '
825+ test_oid_init
826+ '
827+
828+ test_expect_success ' test_oid provides sane info by default' '
829+ test_oid zero >actual &&
830+ grep "^00*\$" actual &&
831+ rawsz="$(test_oid rawsz)" &&
832+ hexsz="$(test_oid hexsz)" &&
833+ test "$hexsz" -eq $(wc -c <actual) &&
834+ test $(( $rawsz * 2)) -eq "$hexsz"
835+ '
836+
837+ test_expect_success ' test_oid can look up data for SHA-1' '
838+ test_when_finished "test_detect_hash" &&
839+ test_set_hash sha1 &&
840+ test_oid zero >actual &&
841+ grep "^00*\$" actual &&
842+ rawsz="$(test_oid rawsz)" &&
843+ hexsz="$(test_oid hexsz)" &&
844+ test $(wc -c <actual) -eq 40 &&
845+ test "$rawsz" -eq 20 &&
846+ test "$hexsz" -eq 40
847+ '
848+
849+ test_expect_success ' test_oid can look up data for SHA-256' '
850+ test_when_finished "test_detect_hash" &&
851+ test_set_hash sha256 &&
852+ test_oid zero >actual &&
853+ grep "^00*\$" actual &&
854+ rawsz="$(test_oid rawsz)" &&
855+ hexsz="$(test_oid hexsz)" &&
856+ test $(wc -c <actual) -eq 64 &&
857+ test "$rawsz" -eq 32 &&
858+ test "$hexsz" -eq 64
859+ '
860+
824861# ###############################################################
825862# Basics of the basics
826863
864+ test_oid_cache << \EOF
865+ path0f sha1:f87290f8eb2cbbea7857214459a0739927eab154
866+ path0f sha256:638106af7c38be056f3212cbd7ac65bc1bac74f420ca5a436ff006a9d025d17d
867+
868+ path0s sha1:15a98433ae33114b085f3eb3bb03b832b3180a01
869+ path0s sha256:3a24cc53cf68edddac490bbf94a418a52932130541361f685df685e41dd6c363
870+
871+ path2f sha1:3feff949ed00a62d9f7af97c15cd8a30595e7ac7
872+ path2f sha256:2a7f36571c6fdbaf0e3f62751a0b25a3f4c54d2d1137b3f4af9cb794bb498e5f
873+
874+ path2s sha1:d8ce161addc5173867a3c3c730924388daedbc38
875+ path2s sha256:18fd611b787c2e938ddcc248fabe4d66a150f9364763e9ec133dd01d5bb7c65a
876+
877+ path2d sha1:58a09c23e2ca152193f2786e06986b7b6712bdbe
878+ path2d sha256:00e4b32b96e7e3d65d79112dcbea53238a22715f896933a62b811377e2650c17
879+
880+ path3f sha1:0aa34cae68d0878578ad119c86ca2b5ed5b28376
881+ path3f sha256:09f58616b951bd571b8cb9dc76d372fbb09ab99db2393f5ab3189d26c45099ad
882+
883+ path3s sha1:8599103969b43aff7e430efea79ca4636466794f
884+ path3s sha256:fce1aed087c053306f3f74c32c1a838c662bbc4551a7ac2420f5d6eb061374d0
885+
886+ path3d sha1:21ae8269cacbe57ae09138dcc3a2887f904d02b3
887+ path3d sha256:9b60497be959cb830bf3f0dc82bcc9ad9e925a24e480837ade46b2295e47efe1
888+
889+ subp3f sha1:00fb5908cb97c2564a9783c0c64087333b3b464f
890+ subp3f sha256:a1a9e16998c988453f18313d10375ee1d0ddefe757e710dcae0d66aa1e0c58b3
891+
892+ subp3s sha1:6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c
893+ subp3s sha256:81759d9f5e93c6546ecfcadb560c1ff057314b09f93fe8ec06e2d8610d34ef10
894+
895+ subp3d sha1:3c5e5399f3a333eddecce7a9b9465b63f65f51e2
896+ subp3d sha256:76b4ef482d4fa1c754390344cf3851c7f883b27cf9bc999c6547928c46aeafb7
897+
898+ root sha1:087704a96baf1c2d1c869a8b084481e121c88b5b
899+ root sha256:9481b52abab1b2ffeedbf9de63ce422b929f179c1b98ff7bee5f8f1bc0710751
900+
901+ simpletree sha1:7bb943559a305bdd6bdee2cef6e5df2413c3d30a
902+ simpletree sha256:1710c07a6c86f9a3c7376364df04c47ee39e5a5e221fcdd84b743bc9bb7e2bc5
903+ EOF
904+
827905# updating a new file without --add should fail.
828906test_expect_success ' git update-index without --add should fail adding' '
829907 test_must_fail git update-index should-be-empty
@@ -839,8 +917,8 @@ test_expect_success 'writing tree out with git write-tree' '
839917'
840918
841919# we know the shape and contents of the tree and know the object ID for it.
842- test_expect_success SHA1 ' validate object ID of a known tree' '
843- test "$tree" = 7bb943559a305bdd6bdee2cef6e5df2413c3d30a
920+ test_expect_success ' validate object ID of a known tree' '
921+ test "$tree" = "$(test_oid simpletree)"
844922 '
845923
846924# Removing paths.
@@ -882,16 +960,16 @@ test_expect_success 'showing stage with git ls-files --stage' '
882960 git ls-files --stage >current
883961'
884962
885- test_expect_success SHA1 ' validate git ls-files output for a known tree' '
886- cat >expected <<-\ EOF &&
887- 100644 f87290f8eb2cbbea7857214459a0739927eab154 0 path0
888- 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0 path0sym
889- 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0 path2/file2
890- 120000 d8ce161addc5173867a3c3c730924388daedbc38 0 path2/file2sym
891- 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0 path3/file3
892- 120000 8599103969b43aff7e430efea79ca4636466794f 0 path3/file3sym
893- 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0 path3/subp3/file3
894- 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0 path3/subp3/file3sym
963+ test_expect_success ' validate git ls-files output for a known tree' '
964+ cat >expected <<-EOF &&
965+ 100644 $(test_oid path0f) 0 path0
966+ 120000 $(test_oid path0s) 0 path0sym
967+ 100644 $(test_oid path2f) 0 path2/file2
968+ 120000 $(test_oid path2s) 0 path2/file2sym
969+ 100644 $(test_oid path3f) 0 path3/file3
970+ 120000 $(test_oid path3s) 0 path3/file3sym
971+ 100644 $(test_oid subp3f) 0 path3/subp3/file3
972+ 120000 $(test_oid subp3s) 0 path3/subp3/file3sym
895973 EOF
896974 test_cmp expected current
897975'
@@ -900,20 +978,20 @@ test_expect_success 'writing tree out with git write-tree' '
900978 tree=$(git write-tree)
901979'
902980
903- test_expect_success SHA1 ' validate object ID for a known tree' '
904- test "$tree" = 087704a96baf1c2d1c869a8b084481e121c88b5b
981+ test_expect_success ' validate object ID for a known tree' '
982+ test "$tree" = "$(test_oid root)"
905983'
906984
907985test_expect_success ' showing tree with git ls-tree' '
908986 git ls-tree $tree >current
909987'
910988
911- test_expect_success SHA1 ' git ls-tree output for a known tree' '
912- cat >expected <<-\ EOF &&
913- 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
914- 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
915- 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
916- 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
989+ test_expect_success ' git ls-tree output for a known tree' '
990+ cat >expected <<-EOF &&
991+ 100644 blob $(test_oid path0f) path0
992+ 120000 blob $(test_oid path0s) path0sym
993+ 040000 tree $(test_oid path2d) path2
994+ 040000 tree $(test_oid path3d) path3
917995 EOF
918996 test_cmp expected current
919997'
@@ -924,16 +1002,16 @@ test_expect_success 'showing tree with git ls-tree -r' '
9241002 git ls-tree -r $tree >current
9251003'
9261004
927- test_expect_success SHA1 ' git ls-tree -r output for a known tree' '
928- cat >expected <<-\ EOF &&
929- 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
930- 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
931- 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
932- 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
933- 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
934- 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
935- 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
936- 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
1005+ test_expect_success ' git ls-tree -r output for a known tree' '
1006+ cat >expected <<-EOF &&
1007+ 100644 blob $(test_oid path0f) path0
1008+ 120000 blob $(test_oid path0s) path0sym
1009+ 100644 blob $(test_oid path2f) path2/file2
1010+ 120000 blob $(test_oid path2s) path2/file2sym
1011+ 100644 blob $(test_oid path3f) path3/file3
1012+ 120000 blob $(test_oid path3s) path3/file3sym
1013+ 100644 blob $(test_oid subp3f) path3/subp3/file3
1014+ 120000 blob $(test_oid subp3s) path3/subp3/file3sym
9371015 EOF
9381016 test_cmp expected current
9391017'
@@ -943,19 +1021,19 @@ test_expect_success 'showing tree with git ls-tree -r -t' '
9431021 git ls-tree -r -t $tree >current
9441022'
9451023
946- test_expect_success SHA1 ' git ls-tree -r output for a known tree' '
947- cat >expected <<-\ EOF &&
948- 100644 blob f87290f8eb2cbbea7857214459a0739927eab154 path0
949- 120000 blob 15a98433ae33114b085f3eb3bb03b832b3180a01 path0sym
950- 040000 tree 58a09c23e2ca152193f2786e06986b7b6712bdbe path2
951- 100644 blob 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 path2/file2
952- 120000 blob d8ce161addc5173867a3c3c730924388daedbc38 path2/file2sym
953- 040000 tree 21ae8269cacbe57ae09138dcc3a2887f904d02b3 path3
954- 100644 blob 0aa34cae68d0878578ad119c86ca2b5ed5b28376 path3/file3
955- 120000 blob 8599103969b43aff7e430efea79ca4636466794f path3/file3sym
956- 040000 tree 3c5e5399f3a333eddecce7a9b9465b63f65f51e2 path3/subp3
957- 100644 blob 00fb5908cb97c2564a9783c0c64087333b3b464f path3/subp3/file3
958- 120000 blob 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c path3/subp3/file3sym
1024+ test_expect_success ' git ls-tree -r output for a known tree' '
1025+ cat >expected <<-EOF &&
1026+ 100644 blob $(test_oid path0f) path0
1027+ 120000 blob $(test_oid path0s) path0sym
1028+ 040000 tree $(test_oid path2d) path2
1029+ 100644 blob $(test_oid path2f) path2/file2
1030+ 120000 blob $(test_oid path2s) path2/file2sym
1031+ 040000 tree $(test_oid path3d) path3
1032+ 100644 blob $(test_oid path3f) path3/file3
1033+ 120000 blob $(test_oid path3s) path3/file3sym
1034+ 040000 tree $(test_oid subp3d) path3/subp3
1035+ 100644 blob $(test_oid subp3f) path3/subp3/file3
1036+ 120000 blob $(test_oid subp3s) path3/subp3/file3sym
9591037 EOF
9601038 test_cmp expected current
9611039'
@@ -964,26 +1042,27 @@ test_expect_success 'writing partial tree out with git write-tree --prefix' '
9641042 ptree=$(git write-tree --prefix=path3)
9651043'
9661044
967- test_expect_success SHA1 ' validate object ID for a known tree' '
968- test "$ptree" = 21ae8269cacbe57ae09138dcc3a2887f904d02b3
1045+ test_expect_success ' validate object ID for a known tree' '
1046+ test "$ptree" = $(test_oid path3d)
9691047'
9701048
9711049test_expect_success ' writing partial tree out with git write-tree --prefix' '
9721050 ptree=$(git write-tree --prefix=path3/subp3)
9731051'
9741052
975- test_expect_success SHA1 ' validate object ID for a known tree' '
976- test "$ptree" = 3c5e5399f3a333eddecce7a9b9465b63f65f51e2
1053+ test_expect_success ' validate object ID for a known tree' '
1054+ test "$ptree" = $(test_oid subp3d)
9771055'
9781056
9791057test_expect_success ' put invalid objects into the index' '
9801058 rm -f .git/index &&
981- cat >badobjects <<-\EOF &&
982- 100644 blob 1000000000000000000000000000000000000000 dir/file1
983- 100644 blob 2000000000000000000000000000000000000000 dir/file2
984- 100644 blob 3000000000000000000000000000000000000000 dir/file3
985- 100644 blob 4000000000000000000000000000000000000000 dir/file4
986- 100644 blob 5000000000000000000000000000000000000000 dir/file5
1059+ suffix=$(echo $ZERO_OID | sed -e "s/^.//") &&
1060+ cat >badobjects <<-EOF &&
1061+ 100644 blob $(test_oid 001) dir/file1
1062+ 100644 blob $(test_oid 002) dir/file2
1063+ 100644 blob $(test_oid 003) dir/file3
1064+ 100644 blob $(test_oid 004) dir/file4
1065+ 100644 blob $(test_oid 005) dir/file5
9871066 EOF
9881067 git update-index --index-info <badobjects
9891068'
@@ -1006,16 +1085,16 @@ test_expect_success 'git read-tree followed by write-tree should be idempotent'
10061085 test "$newtree" = "$tree"
10071086'
10081087
1009- test_expect_success SHA1 ' validate git diff-files output for a know cache/work tree state' '
1010- cat >expected <<\ EOF &&
1011- :100644 100644 f87290f8eb2cbbea7857214459a0739927eab154 0000000000000000000000000000000000000000 M path0
1012- :120000 120000 15a98433ae33114b085f3eb3bb03b832b3180a01 0000000000000000000000000000000000000000 M path0sym
1013- :100644 100644 3feff949ed00a62d9f7af97c15cd8a30595e7ac7 0000000000000000000000000000000000000000 M path2/file2
1014- :120000 120000 d8ce161addc5173867a3c3c730924388daedbc38 0000000000000000000000000000000000000000 M path2/file2sym
1015- :100644 100644 0aa34cae68d0878578ad119c86ca2b5ed5b28376 0000000000000000000000000000000000000000 M path3/file3
1016- :120000 120000 8599103969b43aff7e430efea79ca4636466794f 0000000000000000000000000000000000000000 M path3/file3sym
1017- :100644 100644 00fb5908cb97c2564a9783c0c64087333b3b464f 0000000000000000000000000000000000000000 M path3/subp3/file3
1018- :120000 120000 6649a1ebe9e9f1c553b66f5a6e74136a07ccc57c 0000000000000000000000000000000000000000 M path3/subp3/file3sym
1088+ test_expect_success ' validate git diff-files output for a know cache/work tree state' '
1089+ cat >expected <<EOF &&
1090+ :100644 100644 $(test_oid path0f) $ZERO_OID M path0
1091+ :120000 120000 $(test_oid path0s) $ZERO_OID M path0sym
1092+ :100644 100644 $(test_oid path2f) $ZERO_OID M path2/file2
1093+ :120000 120000 $(test_oid path2s) $ZERO_OID M path2/file2sym
1094+ :100644 100644 $(test_oid path3f) $ZERO_OID M path3/file3
1095+ :120000 120000 $(test_oid path3s) $ZERO_OID M path3/file3sym
1096+ :100644 100644 $(test_oid subp3f) $ZERO_OID M path3/subp3/file3
1097+ :120000 120000 $(test_oid subp3s) $ZERO_OID M path3/subp3/file3sym
10191098EOF
10201099 git diff-files >current &&
10211100 test_cmp current expected
@@ -1031,23 +1110,23 @@ test_expect_success 'no diff after checkout and git update-index --refresh' '
10311110'
10321111
10331112# ###############################################################
1034- P=087704a96baf1c2d1c869a8b084481e121c88b5b
1113+ P=$( test_oid root )
10351114
1036- test_expect_success SHA1 ' git commit-tree records the correct tree in a commit' '
1115+ test_expect_success ' git commit-tree records the correct tree in a commit' '
10371116 commit0=$(echo NO | git commit-tree $P) &&
10381117 tree=$(git show --pretty=raw $commit0 |
10391118 sed -n -e "s/^tree //p" -e "/^author /q") &&
10401119 test "z$tree" = "z$P"
10411120'
10421121
1043- test_expect_success SHA1 ' git commit-tree records the correct parent in a commit' '
1122+ test_expect_success ' git commit-tree records the correct parent in a commit' '
10441123 commit1=$(echo NO | git commit-tree $P -p $commit0) &&
10451124 parent=$(git show --pretty=raw $commit1 |
10461125 sed -n -e "s/^parent //p" -e "/^author /q") &&
10471126 test "z$commit0" = "z$parent"
10481127'
10491128
1050- test_expect_success SHA1 ' git commit-tree omits duplicated parent in a commit' '
1129+ test_expect_success ' git commit-tree omits duplicated parent in a commit' '
10511130 commit2=$(echo NO | git commit-tree $P -p $commit0 -p $commit0) &&
10521131 parent=$(git show --pretty=raw $commit2 |
10531132 sed -n -e "s/^parent //p" -e "/^author /q" |
0 commit comments