3 # Copyright (c) 2023 Eric Biederman
6 test_description
='Test how well compatObjectFormat works'
8 TEST_PASSES_SANITIZE_LEAK
=true
10 .
"$TEST_DIRECTORY"/lib-gpg.sh
12 # All of the follow variables must be defined in the environment:
20 # The test relies on these variables being set so that the two
21 # different commits in two different repositories encoded with two
22 # different hash functions result in the same content in the commits.
23 # This means that when the commit is translated between hash functions
24 # the commit is identical to the commit in the other repository.
40 echo "$hello_sha1_oid"
43 echo "$hello_sha256_oid"
54 echo "$tree_sha256_oid"
62 echo "$commit_sha1_oid"
65 echo "$commit_sha256_oid"
73 echo "$commit2_sha1_oid"
76 echo "$commit2_sha256_oid"
84 if test "$delete" = "sha256" ; then
85 local pattern
="gpgsig-sha256"
87 local pattern
="gpgsig"
89 test-tool delete-gpgsig
"$pattern"
97 if test "$storage" = "$delete" ; then
98 local pattern
="trailer"
99 elif test "$storage" = "sha256" ; then
100 local pattern
="gpgsig"
102 local pattern
="gpgsig-sha256"
104 test-tool delete-gpgsig
"$pattern"
108 for hash in sha1 sha256
114 test_expect_success
"setup $hash repository" '
115 git init --object-format=$hash &&
116 git config core.repositoryformatversion 1 &&
117 git config extensions.objectformat $hash &&
118 git config extensions.compatobjectformat $(compat_hash $hash) &&
119 git config gpg.program $TEST_DIRECTORY/t1016/gpg &&
120 echo "Hellow World!" > hello &&
121 eval hello_${hash}_oid=$(git hash-object hello) &&
122 git update-index --add hello &&
123 git commit -m "Initial commit" &&
124 eval commit_${hash}_oid=$(git rev-parse HEAD) &&
125 eval tree_${hash}_oid=$(git rev-parse HEAD^{tree})
127 test_expect_success
"create a $hash tagged blob" '
128 git tag --no-sign -m "This is a tag" hellotag $(hello_oid $hash) &&
129 eval hellotag_${hash}_oid=$(git rev-parse hellotag)
131 test_expect_success
"create a $hash tagged tree" '
132 git tag --no-sign -m "This is a tag" treetag $(tree_oid $hash) &&
133 eval treetag_${hash}_oid=$(git rev-parse treetag)
135 test_expect_success
"create a $hash tagged commit" '
136 git tag --no-sign -m "This is a tag" committag $(commit_oid $hash) &&
137 eval committag_${hash}_oid=$(git rev-parse committag)
139 test_expect_success GPG2
"create a $hash signed commit" '
140 git commit --gpg-sign --allow-empty -m "This is a signed commit" &&
141 eval signedcommit_${hash}_oid=$(git rev-parse HEAD)
143 test_expect_success GPG2
"create a $hash signed tag" '
144 git tag -s -m "This is a signed tag" signedtag HEAD &&
145 eval signedtag_${hash}_oid=$(git rev-parse signedtag)
147 test_expect_success
"create a $hash branch" '
148 git checkout -b branch $(commit_oid $hash) &&
149 echo "More more more give me more!" > more &&
150 eval more_${hash}_oid=$(git hash-object more) &&
151 echo "Another and another and another" > another &&
152 eval another_${hash}_oid=$(git hash-object another) &&
153 git update-index --add more another &&
154 git commit -m "Add more files!" &&
155 eval commit2_${hash}_oid=$(git rev-parse HEAD) &&
156 eval tree2_${hash}_oid=$(git rev-parse HEAD^{tree})
158 test_expect_success GPG2
"create another $hash signed tag" '
159 git tag -s -m "This is another signed tag" signedtag2 $(commit2_oid $hash) &&
160 eval signedtag2_${hash}_oid=$(git rev-parse signedtag2)
162 test_expect_success GPG2
"merge the $hash branches together" '
163 git merge -S -m "merge some signed tags together" signedtag signedtag2 &&
164 eval signedcommit2_${hash}_oid=$(git rev-parse HEAD)
166 test_expect_success GPG2
"create additional $hash signed commits" '
167 git commit --gpg-sign --allow-empty -m "This is an additional signed commit" &&
168 git cat-file commit HEAD | del_sigcommit sha256 > "../${hash}_signedcommit3" &&
169 git cat-file commit HEAD | del_sigcommit sha1 > "../${hash}_signedcommit4" &&
170 eval signedcommit3_${hash}_oid=$(git hash-object -t commit -w ../${hash}_signedcommit3) &&
171 eval signedcommit4_${hash}_oid=$(git hash-object -t commit -w ../${hash}_signedcommit4)
173 test_expect_success GPG2
"create additional $hash signed tags" '
174 git tag -s -m "This is an additional signed tag" signedtag34 HEAD &&
175 git cat-file tag signedtag34 | del_sigtag "${hash}" sha256 > ../${hash}_signedtag3 &&
176 git cat-file tag signedtag34 | del_sigtag "${hash}" sha1 > ../${hash}_signedtag4 &&
177 eval signedtag3_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag3) &&
178 eval signedtag4_${hash}_oid=$(git hash-object -t tag -w ../${hash}_signedtag4)
184 test "$#" = 5 && { local PREREQ
="$1"; shift; } || PREREQ
=
188 local sha256_oid
="$4"
190 echo ${sha1_oid} > ${name}_sha1_expected
191 echo ${sha256_oid} > ${name}_sha256_expected
192 echo ${type} > ${name}_type_expected
194 git
--git-dir=repo-sha
1/.git rev-parse
--output-object-format=sha256
${sha1_oid} > ${name}_sha1_sha256_found
195 git
--git-dir=repo-sha256
/.git rev-parse
--output-object-format=sha1
${sha256_oid} > ${name}_sha256_sha1_found
196 local sha1_sha256_oid
="$(cat ${name}_sha1_sha256_found)"
197 local sha256_sha1_oid
="$(cat ${name}_sha256_sha1_found)"
199 test_expect_success
$PREREQ "Verify ${type} ${name}'s sha1 oid" '
200 git --git-dir=repo-sha256/.git rev-parse --output-object-format=sha1 ${sha256_oid} > ${name}_sha1 &&
201 test_cmp ${name}_sha1 ${name}_sha1_expected
204 test_expect_success
$PREREQ "Verify ${type} ${name}'s sha256 oid" '
205 git --git-dir=repo-sha1/.git rev-parse --output-object-format=sha256 ${sha1_oid} > ${name}_sha256 &&
206 test_cmp ${name}_sha256 ${name}_sha256_expected
209 test_expect_success
$PREREQ "Verify ${name}'s sha1 type" '
210 git --git-dir=repo-sha1/.git cat-file -t ${sha1_oid} > ${name}_type1 &&
211 git --git-dir=repo-sha256/.git cat-file -t ${sha256_sha1_oid} > ${name}_type2 &&
212 test_cmp ${name}_type1 ${name}_type2 &&
213 test_cmp ${name}_type1 ${name}_type_expected
216 test_expect_success
$PREREQ "Verify ${name}'s sha256 type" '
217 git --git-dir=repo-sha256/.git cat-file -t ${sha256_oid} > ${name}_type3 &&
218 git --git-dir=repo-sha1/.git cat-file -t ${sha1_sha256_oid} > ${name}_type4 &&
219 test_cmp ${name}_type3 ${name}_type4 &&
220 test_cmp ${name}_type3 ${name}_type_expected
223 test_expect_success
$PREREQ "Verify ${name}'s sha1 size" '
224 git --git-dir=repo-sha1/.git cat-file -s ${sha1_oid} > ${name}_size1 &&
225 git --git-dir=repo-sha256/.git cat-file -s ${sha256_sha1_oid} > ${name}_size2 &&
226 test_cmp ${name}_size1 ${name}_size2
229 test_expect_success
$PREREQ "Verify ${name}'s sha256 size" '
230 git --git-dir=repo-sha256/.git cat-file -s ${sha256_oid} > ${name}_size3 &&
231 git --git-dir=repo-sha1/.git cat-file -s ${sha1_sha256_oid} > ${name}_size4 &&
232 test_cmp ${name}_size3 ${name}_size4
235 test_expect_success
$PREREQ "Verify ${name}'s sha1 pretty content" '
236 git --git-dir=repo-sha1/.git cat-file -p ${sha1_oid} > ${name}_content1 &&
237 git --git-dir=repo-sha256/.git cat-file -p ${sha256_sha1_oid} > ${name}_content2 &&
238 test_cmp ${name}_content1 ${name}_content2
241 test_expect_success
$PREREQ "Verify ${name}'s sha256 pretty content" '
242 git --git-dir=repo-sha256/.git cat-file -p ${sha256_oid} > ${name}_content3 &&
243 git --git-dir=repo-sha1/.git cat-file -p ${sha1_sha256_oid} > ${name}_content4 &&
244 test_cmp ${name}_content3 ${name}_content4
247 test_expect_success
$PREREQ "Verify ${name}'s sha1 content" '
248 git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_oid} > ${name}_content5 &&
249 git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_sha1_oid} > ${name}_content6 &&
250 test_cmp ${name}_content5 ${name}_content6
253 test_expect_success
$PREREQ "Verify ${name}'s sha256 content" '
254 git --git-dir=repo-sha256/.git cat-file ${type} ${sha256_oid} > ${name}_content7 &&
255 git --git-dir=repo-sha1/.git cat-file ${type} ${sha1_sha256_oid} > ${name}_content8 &&
256 test_cmp ${name}_content7 ${name}_content8
261 compare_oids
'blob' hello
"$hello_sha1_oid" "$hello_sha256_oid"
262 compare_oids
'tree' tree
"$tree_sha1_oid" "$tree_sha256_oid"
263 compare_oids
'commit' commit
"$commit_sha1_oid" "$commit_sha256_oid"
264 compare_oids GPG2
'commit' signedcommit
"$signedcommit_sha1_oid" "$signedcommit_sha256_oid"
265 compare_oids
'tag' hellotag
"$hellotag_sha1_oid" "$hellotag_sha256_oid"
266 compare_oids
'tag' treetag
"$treetag_sha1_oid" "$treetag_sha256_oid"
267 compare_oids
'tag' committag
"$committag_sha1_oid" "$committag_sha256_oid"
268 compare_oids GPG2
'tag' signedtag
"$signedtag_sha1_oid" "$signedtag_sha256_oid"
270 compare_oids
'blob' more "$more_sha1_oid" "$more_sha256_oid"
271 compare_oids
'blob' another
"$another_sha1_oid" "$another_sha256_oid"
272 compare_oids
'tree' tree2
"$tree2_sha1_oid" "$tree2_sha256_oid"
273 compare_oids
'commit' commit2
"$commit2_sha1_oid" "$commit2_sha256_oid"
274 compare_oids GPG2
'tag' signedtag2
"$signedtag2_sha1_oid" "$signedtag2_sha256_oid"
275 compare_oids GPG2
'commit' signedcommit2
"$signedcommit2_sha1_oid" "$signedcommit2_sha256_oid"
276 compare_oids GPG2
'commit' signedcommit3
"$signedcommit3_sha1_oid" "$signedcommit3_sha256_oid"
277 compare_oids GPG2
'commit' signedcommit4
"$signedcommit4_sha1_oid" "$signedcommit4_sha256_oid"
278 compare_oids GPG2
'tag' signedtag3
"$signedtag3_sha1_oid" "$signedtag3_sha256_oid"
279 compare_oids GPG2
'tag' signedtag4
"$signedtag4_sha1_oid" "$signedtag4_sha256_oid"