Merge branch 'fr_next' of github.com:jnavila/git
[alt-git.git] / t / t3800-mktag.sh
blob6275c98523f73138acaae7fd807f38924bf8e625
1 #!/bin/sh
5 test_description='git mktag: tag object verify test'
7 . ./test-lib.sh
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 git mktag <tag.sig 2>message &&
17 grep '$2' message &&
18 if test '$3' != '--no-strict'
19 then
20 test_must_fail git mktag --no-strict <tag.sig 2>message.no-strict &&
21 grep '$2' message.no-strict
26 test_expect_mktag_success() {
27 test_expect_success "$1" '
28 git hash-object -t tag -w --stdin <tag.sig >expected &&
29 git fsck --strict &&
31 git mktag <tag.sig >hash &&
32 test_cmp expected hash &&
33 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
34 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
35 git fsck --strict
39 ###########################################################
40 # first create a commit, so we have a valid object/type
41 # for the tag.
42 test_expect_success 'setup' '
43 test_commit A &&
44 test_commit B &&
45 head=$(git rev-parse --verify HEAD) &&
46 head_parent=$(git rev-parse --verify HEAD~) &&
47 tree=$(git rev-parse HEAD^{tree}) &&
48 blob=$(git rev-parse --verify HEAD:B.t)
51 test_expect_success 'basic usage' '
52 cat >tag.sig <<-EOF &&
53 object $head
54 type commit
55 tag mytag
56 tagger T A Gger <tagger@example.com> 1206478233 -0500
57 EOF
58 git mktag <tag.sig &&
59 git mktag --end-of-options <tag.sig &&
60 test_expect_code 129 git mktag --unknown-option
63 ############################################################
64 # 1. length check
66 cat >tag.sig <<EOF
67 too short for a tag
68 EOF
70 check_verify_failure 'Tag object length check' \
71 '^error:.* missingObject:' 'strict'
73 ############################################################
74 # 2. object line label check
76 cat >tag.sig <<EOF
77 xxxxxx $head
78 type tag
79 tag mytag
80 tagger . <> 0 +0000
82 EOF
84 check_verify_failure '"object" line label check' '^error:.* missingObject:'
86 ############################################################
87 # 3. object line hash check
89 cat >tag.sig <<EOF
90 object $(echo $head | tr 0-9a-f z)
91 type tag
92 tag mytag
93 tagger . <> 0 +0000
95 EOF
97 check_verify_failure '"object" line check' '^error:.* badObjectSha1:'
99 ############################################################
100 # 4. type line label check
102 cat >tag.sig <<EOF
103 object $head
104 xxxx tag
105 tag mytag
106 tagger . <> 0 +0000
110 check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:'
112 ############################################################
113 # 5. type line eol check
115 echo "object $head" >tag.sig
116 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
118 check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:'
120 ############################################################
121 # 6. tag line label check #1
123 cat >tag.sig <<EOF
124 object $head
125 type tag
126 xxx mytag
127 tagger . <> 0 +0000
131 check_verify_failure '"tag" line label check #1' \
132 '^error:.* missingTagEntry:'
134 ############################################################
135 # 7. tag line label check #2
137 cat >tag.sig <<EOF
138 object $head
139 type taggggggggggggggggggggggggggggggg
143 check_verify_failure '"tag" line label check #2' \
144 '^error:.* badType:'
146 ############################################################
147 # 8. type line type-name length check
149 cat >tag.sig <<EOF
150 object $head
151 type taggggggggggggggggggggggggggggggg
152 tag mytag
155 check_verify_failure '"type" line type-name length check' \
156 '^error:.* badType:'
158 ############################################################
159 # 9. verify object (hash/type) check
161 cat >tag.sig <<EOF
162 object $(test_oid deadbeef)
163 type tag
164 tag mytag
165 tagger . <> 0 +0000
169 check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
170 '^fatal: could not read tagged object'
172 cat >tag.sig <<EOF
173 object $head
174 type tagggg
175 tag mytag
176 tagger . <> 0 +0000
180 check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
181 '^error:.* badType:'
183 cat >tag.sig <<EOF
184 object $(test_oid deadbeef)
185 type tagggg
186 tag mytag
187 tagger . <> 0 +0000
191 check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
192 '^error:.* badType:'
194 cat >tag.sig <<EOF
195 object $head
196 type tree
197 tag mytag
198 tagger . <> 0 +0000
202 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
203 '^fatal: object.*tagged as.*tree.*but is.*commit'
205 ############################################################
206 # 9.5. verify object (hash/type) check -- replacement
208 test_expect_success 'setup replacement of commit -> commit and tree -> blob' '
209 git replace $head_parent $head &&
210 git replace -f $tree $blob
213 cat >tag.sig <<EOF
214 object $head_parent
215 type commit
216 tag mytag
217 tagger . <> 0 +0000
221 test_expect_mktag_success 'tag to a commit replaced by another commit'
223 cat >tag.sig <<EOF
224 object $tree
225 type tree
226 tag mytag
227 tagger . <> 0 +0000
231 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
232 '^fatal: object.*tagged as.*tree.*but is.*blob'
234 ############################################################
235 # 10. verify tag-name check
237 cat >tag.sig <<EOF
238 object $head
239 type commit
240 tag my tag
241 tagger . <> 0 +0000
245 check_verify_failure 'verify tag-name check' \
246 '^error:.* badTagName:' '--no-strict'
248 ############################################################
249 # 11. tagger line label check #1
251 cat >tag.sig <<EOF
252 object $head
253 type commit
254 tag mytag
256 This is filler
259 check_verify_failure '"tagger" line label check #1' \
260 '^error:.* missingTaggerEntry:' '--no-strict'
262 ############################################################
263 # 12. tagger line label check #2
265 cat >tag.sig <<EOF
266 object $head
267 type commit
268 tag mytag
269 tagger
271 This is filler
274 check_verify_failure '"tagger" line label check #2' \
275 '^error:.* missingTaggerEntry:' '--no-strict'
277 ############################################################
278 # 13. allow missing tag author name like fsck
280 cat >tag.sig <<EOF
281 object $head
282 type commit
283 tag mytag
284 tagger <> 0 +0000
286 This is filler
289 test_expect_mktag_success 'allow missing tag author name'
291 ############################################################
292 # 14. disallow missing tag author name
294 cat >tag.sig <<EOF
295 object $head
296 type commit
297 tag mytag
298 tagger T A Gger <
299 > 0 +0000
303 check_verify_failure 'disallow malformed tagger' \
304 '^error:.* badEmail:' '--no-strict'
306 ############################################################
307 # 15. allow empty tag email
309 cat >tag.sig <<EOF
310 object $head
311 type commit
312 tag mytag
313 tagger T A Gger <> 0 +0000
317 test_expect_mktag_success 'allow empty tag email'
319 ############################################################
320 # 16. allow spaces in tag email like fsck
322 cat >tag.sig <<EOF
323 object $head
324 type commit
325 tag mytag
326 tagger T A Gger <tag ger@example.com> 0 +0000
330 test_expect_mktag_success 'allow spaces in tag email like fsck'
332 ############################################################
333 # 17. disallow missing tag timestamp
335 tr '_' ' ' >tag.sig <<EOF
336 object $head
337 type commit
338 tag mytag
339 tagger T A Gger <tagger@example.com>__
343 check_verify_failure 'disallow missing tag timestamp' \
344 '^error:.* badDate:'
346 ############################################################
347 # 18. detect invalid tag timestamp1
349 cat >tag.sig <<EOF
350 object $head
351 type commit
352 tag mytag
353 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
357 check_verify_failure 'detect invalid tag timestamp1' \
358 '^error:.* badDate:'
360 ############################################################
361 # 19. detect invalid tag timestamp2
363 cat >tag.sig <<EOF
364 object $head
365 type commit
366 tag mytag
367 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
371 check_verify_failure 'detect invalid tag timestamp2' \
372 '^error:.* badDate:'
374 ############################################################
375 # 20. detect invalid tag timezone1
377 cat >tag.sig <<EOF
378 object $head
379 type commit
380 tag mytag
381 tagger T A Gger <tagger@example.com> 1206478233 GMT
385 check_verify_failure 'detect invalid tag timezone1' \
386 '^error:.* badTimezone:'
388 ############################################################
389 # 21. detect invalid tag timezone2
391 cat >tag.sig <<EOF
392 object $head
393 type commit
394 tag mytag
395 tagger T A Gger <tagger@example.com> 1206478233 + 30
399 check_verify_failure 'detect invalid tag timezone2' \
400 '^error:.* badTimezone:'
402 ############################################################
403 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
405 cat >tag.sig <<EOF
406 object $head
407 type commit
408 tag mytag
409 tagger T A Gger <tagger@example.com> 1206478233 -1430
413 test_expect_mktag_success 'allow invalid tag timezone'
415 ############################################################
416 # 23. detect invalid header entry
418 cat >tag.sig <<EOF
419 object $head
420 type commit
421 tag mytag
422 tagger T A Gger <tagger@example.com> 1206478233 -0500
423 this line should not be here
427 check_verify_failure 'detect invalid header entry' \
428 '^error:.* extraHeaderEntry:' '--no-strict'
430 test_expect_success 'invalid header entry config & fsck' '
431 test_must_fail git mktag <tag.sig &&
432 git mktag --no-strict <tag.sig &&
434 test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
435 test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
437 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
438 git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
440 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
441 git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
443 git fsck &&
444 git -c fsck.extraHeaderEntry=warn fsck 2>err &&
445 grep "warning .*extraHeaderEntry:" err &&
446 test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck &&
447 grep "error .* extraHeaderEntry:" err
450 cat >tag.sig <<EOF
451 object $head
452 type commit
453 tag mytag
454 tagger T A Gger <tagger@example.com> 1206478233 -0500
457 this line comes after an extra newline
460 test_expect_mktag_success 'allow extra newlines at start of body'
462 cat >tag.sig <<EOF
463 object $head
464 type commit
465 tag mytag
466 tagger T A Gger <tagger@example.com> 1206478233 -0500
470 test_expect_mktag_success 'allow a blank line before an empty body (1)'
472 cat >tag.sig <<EOF
473 object $head
474 type commit
475 tag mytag
476 tagger T A Gger <tagger@example.com> 1206478233 -0500
479 test_expect_mktag_success 'allow no blank line before an empty body (2)'
481 ############################################################
482 # 24. create valid tag
484 cat >tag.sig <<EOF
485 object $head
486 type commit
487 tag mytag
488 tagger T A Gger <tagger@example.com> 1206478233 -0500
491 test_expect_mktag_success 'create valid tag object'
493 test_done