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 echo "$bad_tag" >"bad-tag/$tag_ref" &&
77 # Unlike fsck-ing unreachable content above, this
79 test_must_fail git -C bad-tag fsck
82 test_expect_success
"for-each-ref: $subject" '
83 # Make sure the earlier test created it for us
84 git rev-parse "$bad_tag" &&
86 echo "$bad_tag" >"bad-tag/$tag_ref" &&
88 printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected &&
89 git -C bad-tag for-each-ref "$tag_ref" >actual &&
90 test_cmp expected actual &&
92 test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
95 test_expect_success
"fast-export & fast-import: $subject" '
96 # Make sure the earlier test created it for us
97 git rev-parse "$bad_tag" &&
99 test_must_fail git -C bad-tag fast-export --all &&
100 test_must_fail git -C bad-tag fast-export "$bad_tag"
104 test_expect_mktag_success
() {
105 test_expect_success
"$1" '
106 git hash-object -t tag -w --stdin <tag.sig >expected &&
109 git mktag <tag.sig >hash &&
110 test_cmp expected hash &&
111 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
112 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
117 ###########################################################
118 # first create a commit, so we have a valid object/type
120 test_expect_success
'setup' '
123 head=$(git rev-parse --verify HEAD) &&
124 head_parent=$(git rev-parse --verify HEAD~) &&
125 tree=$(git rev-parse HEAD^{tree}) &&
126 blob=$(git rev-parse --verify HEAD:B.t)
129 test_expect_success
'basic usage' '
130 cat >tag.sig <<-EOF &&
134 tagger T A Gger <tagger@example.com> 1206478233 -0500
136 git mktag <tag.sig &&
137 git mktag --end-of-options <tag.sig &&
138 test_expect_code 129 git mktag --unknown-option
141 ############################################################
148 check_verify_failure
'Tag object length check' \
149 '^error:.* missingObject:' 'strict'
151 ############################################################
152 # 2. object line label check
162 check_verify_failure
'"object" line label check' '^error:.* missingObject:'
164 ############################################################
165 # 3. object line hash check
168 object $(echo $head | tr 0-9a-f z)
175 check_verify_failure
'"object" line check' '^error:.* badObjectSha1:'
177 ############################################################
178 # 4. type line label check
188 check_verify_failure
'"type" line label check' '^error:.* missingTypeEntry:'
190 ############################################################
191 # 5. type line eol check
193 echo "object $head" >tag.sig
194 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
196 check_verify_failure
'"type" line eol check' '^error:.* unterminatedHeader:'
198 ############################################################
199 # 6. tag line label check #1
209 check_verify_failure
'"tag" line label check #1' \
210 '^error:.* missingTagEntry:'
212 ############################################################
213 # 7. tag line label check #2
217 type taggggggggggggggggggggggggggggggg
221 check_verify_failure
'"tag" line label check #2' \
224 ############################################################
225 # 8. type line type-name length check
229 type taggggggggggggggggggggggggggggggg
233 check_verify_failure
'"type" line type-name length check' \
236 ############################################################
237 # 9. verify object (hash/type) check
240 object $(test_oid deadbeef)
247 check_verify_failure
'verify object (hash/type) check -- correct type, nonexisting object' \
248 '^fatal: could not read tagged object' \
259 check_verify_failure
'verify object (hash/type) check -- made-up type, valid object' \
263 object $(test_oid deadbeef)
270 check_verify_failure
'verify object (hash/type) check -- made-up type, nonexisting object' \
281 check_verify_failure
'verify object (hash/type) check -- mismatched type, valid object' \
282 '^fatal: object.*tagged as.*tree.*but is.*commit' \
285 ############################################################
286 # 9.5. verify object (hash/type) check -- replacement
288 test_expect_success
'setup replacement of commit -> commit and tree -> blob' '
289 git replace $head_parent $head &&
290 git replace -f $tree $blob
301 test_expect_mktag_success
'tag to a commit replaced by another commit'
311 check_verify_failure
'verify object (hash/type) check -- mismatched type, valid object' \
312 '^fatal: object.*tagged as.*tree.*but is.*blob' \
315 ############################################################
316 # 10. verify tag-name check
326 check_verify_failure
'verify tag-name check' \
327 '^error:.* badTagName:' \
331 ############################################################
332 # 11. tagger line label check #1
342 check_verify_failure
'"tagger" line label check #1' \
343 '^error:.* missingTaggerEntry:' \
347 ############################################################
348 # 12. tagger line label check #2
359 check_verify_failure
'"tagger" line label check #2' \
360 '^error:.* missingTaggerEntry:' \
364 ############################################################
365 # 13. allow missing tag author name like fsck
376 test_expect_mktag_success
'allow missing tag author name'
378 ############################################################
379 # 14. disallow missing tag author name
390 check_verify_failure
'disallow malformed tagger' \
391 '^error:.* badEmail:' \
395 ############################################################
396 # 15. allow empty tag email
402 tagger T A Gger <> 0 +0000
406 test_expect_mktag_success
'allow empty tag email'
408 ############################################################
409 # 16. allow spaces in tag email like fsck
415 tagger T A Gger <tag ger@example.com> 0 +0000
419 test_expect_mktag_success
'allow spaces in tag email like fsck'
421 ############################################################
422 # 17. disallow missing tag timestamp
424 tr '_' ' ' >tag.sig
<<EOF
428 tagger T A Gger <tagger@example.com>__
432 check_verify_failure
'disallow missing tag timestamp' \
435 ############################################################
436 # 18. detect invalid tag timestamp1
442 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
446 check_verify_failure
'detect invalid tag timestamp1' \
449 ############################################################
450 # 19. detect invalid tag timestamp2
456 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
460 check_verify_failure
'detect invalid tag timestamp2' \
463 ############################################################
464 # 20. detect invalid tag timezone1
470 tagger T A Gger <tagger@example.com> 1206478233 GMT
474 check_verify_failure
'detect invalid tag timezone1' \
475 '^error:.* badTimezone:'
477 ############################################################
478 # 21. detect invalid tag timezone2
484 tagger T A Gger <tagger@example.com> 1206478233 + 30
488 check_verify_failure
'detect invalid tag timezone2' \
489 '^error:.* badTimezone:'
491 ############################################################
492 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
498 tagger T A Gger <tagger@example.com> 1206478233 -1430
502 test_expect_mktag_success
'allow invalid tag timezone'
504 ############################################################
505 # 23. detect invalid header entry
511 tagger T A Gger <tagger@example.com> 1206478233 -0500
512 this line should not be here
516 check_verify_failure
'detect invalid header entry' \
517 '^error:.* extraHeaderEntry:' \
521 test_expect_success
'invalid header entry config & fsck' '
522 test_must_fail git mktag <tag.sig &&
523 git mktag --no-strict <tag.sig &&
525 test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
526 test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
528 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
529 git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
531 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
532 git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
535 git -c fsck.extraHeaderEntry=warn fsck 2>err &&
536 grep "warning .*extraHeaderEntry:" err &&
537 test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck &&
538 grep "error .* extraHeaderEntry:" err
545 tagger T A Gger <tagger@example.com> 1206478233 -0500
548 this line comes after an extra newline
551 test_expect_mktag_success
'allow extra newlines at start of body'
557 tagger T A Gger <tagger@example.com> 1206478233 -0500
561 test_expect_mktag_success
'allow a blank line before an empty body (1)'
567 tagger T A Gger <tagger@example.com> 1206478233 -0500
570 test_expect_mktag_success
'allow no blank line before an empty body (2)'
572 ############################################################
573 # 24. create valid tag
579 tagger T A Gger <tagger@example.com> 1206478233 -0500
582 test_expect_mktag_success
'create valid tag object'