mktag tests: test verify_object() with replaced objects
Add tests to demonstrate what "mktag" does in the face of replaced objects. There was an existing test for replaced objects fed to "mktag" added in cc400f50112 (mktag: call "check_sha1_signature" with the replacement sha1, 2009-01-23), but that one only tests a commit->commit mapping. Not a mapping to a different type as like we're also testing for here. We could remove the "mktag" test in t6050-replace.sh now if the created tag wasn't being used by a subsequent "fsck" test. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Ævar Arnfjörð Bjarmason committed
Jan 5, 2021 at 20:42 UTC
692654dca01dda9951a81de4ecfa958b61b8bc5c
1 file changed
+34
-1
t/t3800-mktag.sh
+34
-1
@@ -38,7 +38,11 @@ test_expect_mktag_success() {
38
# for the tag.
39
test_expect_success 'setup' '
40
test_commit A &&
41
- head=$(git rev-parse --verify HEAD)
41
+ test_commit B &&
42
+ head=$(git rev-parse --verify HEAD) &&
43
+ head_parent=$(git rev-parse --verify HEAD~) &&
44
+ tree=$(git rev-parse HEAD^{tree}) &&
45
+ blob=$(git rev-parse --verify HEAD:B.t)
46
'
47
48
############################################################
@@ -180,6 +184,35 @@ tagger . <> 0 +0000
184
185
EOF
186
187
+check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
188
+ '^error: char7: could not verify object'
189
+
190
+############################################################
191
+# 9.5. verify object (hash/type) check -- replacement
192
+
193
+test_expect_success 'setup replacement of commit -> commit and tree -> blob' '
194
+ git replace $head_parent $head &&
195
+ git replace -f $tree $blob
196
+'
197
+
198
+cat >tag.sig <<EOF
199
+object $head_parent
200
+type commit
201
+tag mytag
202
+tagger . <> 0 +0000
203
+
204
+EOF
205
+
206
+test_expect_mktag_success 'tag to a commit replaced by another commit'
207
+
208
+cat >tag.sig <<EOF
209
+object $tree
210
+type tree
211
+tag mytag
212
+tagger . <> 0 +0000
213
+
214
+EOF
215
+
216
check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
217
'^error: char7: could not verify object'
218