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 () {
15 test_expect_success "$1" "
16 test_must_fail env GIT_TEST_GETTEXT_POISON=false \
17 git mktag <tag.sig 2>message &&
19 if test '$3' != '--no-strict'
21 test_must_fail env GIT_TEST_GETTEXT_POISON=false \
22 git mktag --no-strict <tag.sig 2>message.no-strict &&
23 grep '$2' message.no-strict
28 test_expect_mktag_success() {
29 test_expect_success "$1" '
30 git hash-object -t tag -w --stdin <tag.sig >expected &&
33 git mktag <tag.sig >hash &&
34 test_cmp expected hash &&
35 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
36 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
41 ###########################################################
42 # first create a commit, so we have a valid object/type
44 test_expect_success 'setup' '
47 head=$(git rev-parse --verify HEAD) &&
48 head_parent=$(git rev-parse --verify HEAD~) &&
49 tree=$(git rev-parse HEAD^{tree}) &&
50 blob=$(git rev-parse --verify HEAD:B.t)
53 test_expect_success 'basic usage' '
54 cat >tag.sig <<-EOF &&
58 tagger T A Gger <tagger@example.com> 1206478233 -0500
61 git mktag --end-of-options <tag.sig &&
62 test_expect_code 129 git mktag --unknown-option
65 ############################################################
72 check_verify_failure 'Tag object length check' \
73 '^error:.* missingObject:' 'strict'
75 ############################################################
76 # 2. object line label check
86 check_verify_failure '"object" line label check' '^error:.* missingObject:'
88 ############################################################
89 # 3. object line hash check
92 object $(echo $head | tr 0-9a-f z)
99 check_verify_failure '"object" line check' '^error:.* badObjectSha1:'
101 ############################################################
102 # 4. type line label check
112 check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:'
114 ############################################################
115 # 5. type line eol check
117 echo "object $head" >tag.sig
118 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
120 check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:'
122 ############################################################
123 # 6. tag line label check #1
133 check_verify_failure '"tag" line label check #1' \
134 '^error:.* missingTagEntry:'
136 ############################################################
137 # 7. tag line label check #2
141 type taggggggggggggggggggggggggggggggg
145 check_verify_failure '"tag" line label check #2' \
148 ############################################################
149 # 8. type line type-name length check
153 type taggggggggggggggggggggggggggggggg
157 check_verify_failure '"type" line type-name length check' \
160 ############################################################
161 # 9. verify object (hash/type) check
164 object $(test_oid deadbeef)
171 check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
172 '^fatal: could not read tagged object'
182 check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
186 object $(test_oid deadbeef)
193 check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
204 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
205 '^fatal: object.*tagged as.*tree.*but is.*commit'
207 ############################################################
208 # 9.5. verify object (hash/type) check -- replacement
210 test_expect_success 'setup replacement of commit -> commit and tree -> blob' '
211 git replace $head_parent $head &&
212 git replace -f $tree $blob
223 test_expect_mktag_success 'tag to a commit replaced by another commit'
233 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
234 '^fatal: object.*tagged as.*tree.*but is.*blob'
236 ############################################################
237 # 10. verify tag-name check
247 check_verify_failure 'verify tag-name check' \
248 '^error:.* badTagName:' '--no-strict'
250 ############################################################
251 # 11. tagger line label check #1
261 check_verify_failure '"tagger" line label check #1' \
262 '^error:.* missingTaggerEntry:' '--no-strict'
264 ############################################################
265 # 12. tagger line label check #2
276 check_verify_failure '"tagger" line label check #2' \
277 '^error:.* missingTaggerEntry:' '--no-strict'
279 ############################################################
280 # 13. allow missing tag author name like fsck
291 test_expect_mktag_success 'allow missing tag author name'
293 ############################################################
294 # 14. disallow missing tag author name
305 check_verify_failure 'disallow malformed tagger' \
306 '^error:.* badEmail:' '--no-strict'
308 ############################################################
309 # 15. allow empty tag email
315 tagger T A Gger <> 0 +0000
319 test_expect_mktag_success 'allow empty tag email'
321 ############################################################
322 # 16. allow spaces in tag email like fsck
328 tagger T A Gger <tag ger@example.com> 0 +0000
332 test_expect_mktag_success 'allow spaces in tag email like fsck'
334 ############################################################
335 # 17. disallow missing tag timestamp
337 tr '_' ' ' >tag.sig <<EOF
341 tagger T A Gger <tagger@example.com>__
345 check_verify_failure 'disallow missing tag timestamp' \
348 ############################################################
349 # 18. detect invalid tag timestamp1
355 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
359 check_verify_failure 'detect invalid tag timestamp1' \
362 ############################################################
363 # 19. detect invalid tag timestamp2
369 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
373 check_verify_failure 'detect invalid tag timestamp2' \
376 ############################################################
377 # 20. detect invalid tag timezone1
383 tagger T A Gger <tagger@example.com> 1206478233 GMT
387 check_verify_failure 'detect invalid tag timezone1' \
388 '^error:.* badTimezone:'
390 ############################################################
391 # 21. detect invalid tag timezone2
397 tagger T A Gger <tagger@example.com> 1206478233 + 30
401 check_verify_failure 'detect invalid tag timezone2' \
402 '^error:.* badTimezone:'
404 ############################################################
405 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
411 tagger T A Gger <tagger@example.com> 1206478233 -1430
415 test_expect_mktag_success 'allow invalid tag timezone'
417 ############################################################
418 # 23. detect invalid header entry
424 tagger T A Gger <tagger@example.com> 1206478233 -0500
425 this line should not be here
429 check_verify_failure 'detect invalid header entry' \
430 '^error:.* extraHeaderEntry:' '--no-strict'
432 test_expect_success 'invalid header entry config & fsck' '
433 test_must_fail git mktag <tag.sig &&
434 git mktag --no-strict <tag.sig &&
436 test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
437 test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
439 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
440 git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
442 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
443 git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
446 env GIT_TEST_GETTEXT_POISON=false \
447 git -c fsck.extraHeaderEntry=warn fsck 2>err &&
448 grep "warning .*extraHeaderEntry:" err &&
449 test_must_fail env GIT_TEST_GETTEXT_POISON=false \
450 git -c fsck.extraHeaderEntry=error 2>err fsck &&
451 grep "error .* extraHeaderEntry:" err
458 tagger T A Gger <tagger@example.com> 1206478233 -0500
461 this line comes after an extra newline
464 test_expect_mktag_success 'allow extra newlines at start of body'
470 tagger T A Gger <tagger@example.com> 1206478233 -0500
474 test_expect_mktag_success 'allow a blank line before an empty body (1)'
480 tagger T A Gger <tagger@example.com> 1206478233 -0500
483 test_expect_mktag_success 'allow no blank line before an empty body (2)'
485 ############################################################
486 # 24. create valid tag
492 tagger T A Gger <tagger@example.com> 1206478233 -0500
495 test_expect_mktag_success 'create valid tag object'