5 test_description
='git mktag: tag object verify test'
9 ###########################################################
10 # check the tag.sig file, expecting verify_tag() to fail,
11 # and checking that the error message matches the pattern
12 # given in the expect.pat file.
14 check_verify_failure
() {
35 test_expect_success
"fail with [--[no-]strict]: $subject" '
36 test_must_fail git mktag <tag.sig 2>err &&
37 if test -z "$no_strict"
39 test_must_fail git mktag <tag.sig 2>err2 &&
42 git mktag --no-strict <tag.sig
46 test_expect_success
"setup: $subject" '
47 tag_ref=refs/tags/bad_tag &&
49 # Reset any leftover state from the last $subject
52 git init --bare bad-tag &&
53 bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally <tag.sig)
56 test_expect_success
"hash-object & fsck unreachable: $subject" '
57 if test -n "$fsck_obj_ok"
61 test_must_fail git -C bad-tag fsck
65 test_expect_success
"update-ref & fsck reachable: $subject" '
66 # Make sure the earlier test created it for us
67 git rev-parse "$bad_tag" &&
69 # The update-ref of the bad content will fail, do it
70 # anyway to see if it segfaults
71 test_might_fail git -C bad-tag update-ref "$tag_ref" "$bad_tag" &&
73 # Manually create the broken, we cannot do it with
75 test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" &&
76 test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION &&
78 # Unlike fsck-ing unreachable content above, this
80 test_must_fail git -C bad-tag fsck
83 test_expect_success
"for-each-ref: $subject" '
84 # Make sure the earlier test created it for us
85 git rev-parse "$bad_tag" &&
87 test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" &&
88 test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION &&
90 printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected &&
91 git -C bad-tag for-each-ref "$tag_ref" >actual &&
92 test_cmp expected actual &&
94 test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
97 test_expect_success
"fast-export & fast-import: $subject" '
98 # Make sure the earlier test created it for us
99 git rev-parse "$bad_tag" &&
101 test_must_fail git -C bad-tag fast-export --all &&
102 test_must_fail git -C bad-tag fast-export "$bad_tag"
106 test_expect_mktag_success
() {
107 test_expect_success
"$1" '
108 git hash-object -t tag -w --stdin <tag.sig >expected &&
111 git mktag <tag.sig >hash &&
112 test_cmp expected hash &&
113 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
114 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
119 ###########################################################
120 # first create a commit, so we have a valid object/type
122 test_expect_success
'setup' '
125 head=$(git rev-parse --verify HEAD) &&
126 head_parent=$(git rev-parse --verify HEAD~) &&
127 tree=$(git rev-parse HEAD^{tree}) &&
128 blob=$(git rev-parse --verify HEAD:B.t)
131 test_expect_success
'basic usage' '
132 cat >tag.sig <<-EOF &&
136 tagger T A Gger <tagger@example.com> 1206478233 -0500
138 git mktag <tag.sig &&
139 git mktag --end-of-options <tag.sig &&
140 test_expect_code 129 git mktag --unknown-option
143 ############################################################
150 check_verify_failure
'Tag object length check' \
151 '^error:.* missingObject:' 'strict'
153 ############################################################
154 # 2. object line label check
164 check_verify_failure
'"object" line label check' '^error:.* missingObject:'
166 ############################################################
167 # 3. object line hash check
170 object $(echo $head | tr 0-9a-f z)
177 check_verify_failure
'"object" line check' '^error:.* badObjectSha1:'
179 ############################################################
180 # 4. type line label check
190 check_verify_failure
'"type" line label check' '^error:.* missingTypeEntry:'
192 ############################################################
193 # 5. type line eol check
195 echo "object $head" >tag.sig
196 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
198 check_verify_failure
'"type" line eol check' '^error:.* unterminatedHeader:'
200 ############################################################
201 # 6. tag line label check #1
211 check_verify_failure
'"tag" line label check #1' \
212 '^error:.* missingTagEntry:'
214 ############################################################
215 # 7. tag line label check #2
219 type taggggggggggggggggggggggggggggggg
223 check_verify_failure
'"tag" line label check #2' \
226 ############################################################
227 # 8. type line type-name length check
231 type taggggggggggggggggggggggggggggggg
235 check_verify_failure
'"type" line type-name length check' \
238 ############################################################
239 # 9. verify object (hash/type) check
242 object $(test_oid deadbeef)
249 check_verify_failure
'verify object (hash/type) check -- correct type, nonexisting object' \
250 '^fatal: could not read tagged object' \
261 check_verify_failure
'verify object (hash/type) check -- made-up type, valid object' \
265 object $(test_oid deadbeef)
272 check_verify_failure
'verify object (hash/type) check -- made-up type, nonexisting object' \
283 check_verify_failure
'verify object (hash/type) check -- mismatched type, valid object' \
284 '^fatal: object.*tagged as.*tree.*but is.*commit' \
287 ############################################################
288 # 9.5. verify object (hash/type) check -- replacement
290 test_expect_success
'setup replacement of commit -> commit and tree -> blob' '
291 git replace $head_parent $head &&
292 git replace -f $tree $blob
303 test_expect_mktag_success
'tag to a commit replaced by another commit'
313 check_verify_failure
'verify object (hash/type) check -- mismatched type, valid object' \
314 '^fatal: object.*tagged as.*tree.*but is.*blob' \
317 ############################################################
318 # 10. verify tag-name check
328 check_verify_failure
'verify tag-name check' \
329 '^error:.* badTagName:' \
333 ############################################################
334 # 11. tagger line label check #1
344 check_verify_failure
'"tagger" line label check #1' \
345 '^error:.* missingTaggerEntry:' \
349 ############################################################
350 # 12. tagger line label check #2
361 check_verify_failure
'"tagger" line label check #2' \
362 '^error:.* missingTaggerEntry:' \
366 ############################################################
367 # 13. allow missing tag author name like fsck
378 test_expect_mktag_success
'allow missing tag author name'
380 ############################################################
381 # 14. disallow missing tag author name
392 check_verify_failure
'disallow malformed tagger' \
393 '^error:.* badEmail:' \
397 ############################################################
398 # 15. allow empty tag email
404 tagger T A Gger <> 0 +0000
408 test_expect_mktag_success
'allow empty tag email'
410 ############################################################
411 # 16. allow spaces in tag email like fsck
417 tagger T A Gger <tag ger@example.com> 0 +0000
421 test_expect_mktag_success
'allow spaces in tag email like fsck'
423 ############################################################
424 # 17. disallow missing tag timestamp
426 tr '_' ' ' >tag.sig
<<EOF
430 tagger T A Gger <tagger@example.com>__
434 check_verify_failure
'disallow missing tag timestamp' \
437 ############################################################
438 # 18. detect invalid tag timestamp1
444 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
448 check_verify_failure
'detect invalid tag timestamp1' \
451 ############################################################
452 # 19. detect invalid tag timestamp2
458 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
462 check_verify_failure
'detect invalid tag timestamp2' \
465 ############################################################
466 # 20. detect invalid tag timezone1
472 tagger T A Gger <tagger@example.com> 1206478233 GMT
476 check_verify_failure
'detect invalid tag timezone1' \
477 '^error:.* badTimezone:'
479 ############################################################
480 # 21. detect invalid tag timezone2
486 tagger T A Gger <tagger@example.com> 1206478233 + 30
490 check_verify_failure
'detect invalid tag timezone2' \
491 '^error:.* badTimezone:'
493 ############################################################
494 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
500 tagger T A Gger <tagger@example.com> 1206478233 -1430
504 test_expect_mktag_success
'allow invalid tag timezone'
506 ############################################################
507 # 23. detect invalid header entry
513 tagger T A Gger <tagger@example.com> 1206478233 -0500
514 this line should not be here
518 check_verify_failure
'detect invalid header entry' \
519 '^error:.* extraHeaderEntry:' \
523 test_expect_success
'invalid header entry config & fsck' '
524 test_must_fail git mktag <tag.sig &&
525 git mktag --no-strict <tag.sig &&
527 test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
528 test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
530 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
531 git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
533 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
534 git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
537 git -c fsck.extraHeaderEntry=warn fsck 2>err &&
538 grep "warning .*extraHeaderEntry:" err &&
539 test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck &&
540 grep "error .* extraHeaderEntry:" err
547 tagger T A Gger <tagger@example.com> 1206478233 -0500
550 this line comes after an extra newline
553 test_expect_mktag_success
'allow extra newlines at start of body'
559 tagger T A Gger <tagger@example.com> 1206478233 -0500
563 test_expect_mktag_success
'allow a blank line before an empty body (1)'
569 tagger T A Gger <tagger@example.com> 1206478233 -0500
572 test_expect_mktag_success
'allow no blank line before an empty body (2)'
574 ############################################################
575 # 24. create valid tag
581 tagger T A Gger <tagger@example.com> 1206478233 -0500
584 test_expect_mktag_success
'create valid tag object'