Merge branch 'ar/submodule-add-config'
[git/debian.git] / t / t3800-mktag.sh
blob0544d58a6ea5478f046b571f7e249a5942da37e2
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 subject=$1 &&
16 message=$2 &&
17 shift 2 &&
19 no_strict= &&
20 fsck_obj_ok= &&
21 no_strict= &&
22 while test $# != 0
24 case "$1" in
25 --no-strict)
26 no_strict=yes
28 --fsck-obj-ok)
29 fsck_obj_ok=yes
31 esac &&
32 shift
33 done &&
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"
38 then
39 test_must_fail git mktag <tag.sig 2>err2 &&
40 test_cmp err err2
41 else
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
50 rm -rf bad-tag &&
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"
58 then
59 git -C bad-tag fsck
60 else
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
74 # update-ref
75 echo "$bad_tag" >"bad-tag/$tag_ref" &&
77 # Unlike fsck-ing unreachable content above, this
78 # will always fail.
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 &&
107 git fsck --strict &&
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) &&
113 git fsck --strict
117 ###########################################################
118 # first create a commit, so we have a valid object/type
119 # for the tag.
120 test_expect_success 'setup' '
121 test_commit A &&
122 test_commit B &&
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 &&
131 object $head
132 type commit
133 tag mytag
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 ############################################################
142 # 1. length check
144 cat >tag.sig <<EOF
145 too short for a tag
148 check_verify_failure 'Tag object length check' \
149 '^error:.* missingObject:' 'strict'
151 ############################################################
152 # 2. object line label check
154 cat >tag.sig <<EOF
155 xxxxxx $head
156 type tag
157 tag mytag
158 tagger . <> 0 +0000
162 check_verify_failure '"object" line label check' '^error:.* missingObject:'
164 ############################################################
165 # 3. object line hash check
167 cat >tag.sig <<EOF
168 object $(echo $head | tr 0-9a-f z)
169 type tag
170 tag mytag
171 tagger . <> 0 +0000
175 check_verify_failure '"object" line check' '^error:.* badObjectSha1:'
177 ############################################################
178 # 4. type line label check
180 cat >tag.sig <<EOF
181 object $head
182 xxxx tag
183 tag mytag
184 tagger . <> 0 +0000
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
201 cat >tag.sig <<EOF
202 object $head
203 type tag
204 xxx mytag
205 tagger . <> 0 +0000
209 check_verify_failure '"tag" line label check #1' \
210 '^error:.* missingTagEntry:'
212 ############################################################
213 # 7. tag line label check #2
215 cat >tag.sig <<EOF
216 object $head
217 type taggggggggggggggggggggggggggggggg
221 check_verify_failure '"tag" line label check #2' \
222 '^error:.* badType:'
224 ############################################################
225 # 8. type line type-name length check
227 cat >tag.sig <<EOF
228 object $head
229 type taggggggggggggggggggggggggggggggg
230 tag mytag
233 check_verify_failure '"type" line type-name length check' \
234 '^error:.* badType:'
236 ############################################################
237 # 9. verify object (hash/type) check
239 cat >tag.sig <<EOF
240 object $(test_oid deadbeef)
241 type tag
242 tag mytag
243 tagger . <> 0 +0000
247 check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
248 '^fatal: could not read tagged object' \
249 --fsck-obj-ok
251 cat >tag.sig <<EOF
252 object $head
253 type tagggg
254 tag mytag
255 tagger . <> 0 +0000
259 check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
260 '^error:.* badType:'
262 cat >tag.sig <<EOF
263 object $(test_oid deadbeef)
264 type tagggg
265 tag mytag
266 tagger . <> 0 +0000
270 check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
271 '^error:.* badType:'
273 cat >tag.sig <<EOF
274 object $head
275 type tree
276 tag mytag
277 tagger . <> 0 +0000
281 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
282 '^fatal: object.*tagged as.*tree.*but is.*commit' \
283 --fsck-obj-ok
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
293 cat >tag.sig <<EOF
294 object $head_parent
295 type commit
296 tag mytag
297 tagger . <> 0 +0000
301 test_expect_mktag_success 'tag to a commit replaced by another commit'
303 cat >tag.sig <<EOF
304 object $tree
305 type tree
306 tag mytag
307 tagger . <> 0 +0000
311 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
312 '^fatal: object.*tagged as.*tree.*but is.*blob' \
313 --fsck-obj-ok
315 ############################################################
316 # 10. verify tag-name check
318 cat >tag.sig <<EOF
319 object $head
320 type commit
321 tag my tag
322 tagger . <> 0 +0000
326 check_verify_failure 'verify tag-name check' \
327 '^error:.* badTagName:' \
328 --no-strict \
329 --fsck-obj-ok
331 ############################################################
332 # 11. tagger line label check #1
334 cat >tag.sig <<EOF
335 object $head
336 type commit
337 tag mytag
339 This is filler
342 check_verify_failure '"tagger" line label check #1' \
343 '^error:.* missingTaggerEntry:' \
344 --no-strict \
345 --fsck-obj-ok
347 ############################################################
348 # 12. tagger line label check #2
350 cat >tag.sig <<EOF
351 object $head
352 type commit
353 tag mytag
354 tagger
356 This is filler
359 check_verify_failure '"tagger" line label check #2' \
360 '^error:.* missingTaggerEntry:' \
361 --no-strict \
362 --fsck-obj-ok
364 ############################################################
365 # 13. allow missing tag author name like fsck
367 cat >tag.sig <<EOF
368 object $head
369 type commit
370 tag mytag
371 tagger <> 0 +0000
373 This is filler
376 test_expect_mktag_success 'allow missing tag author name'
378 ############################################################
379 # 14. disallow missing tag author name
381 cat >tag.sig <<EOF
382 object $head
383 type commit
384 tag mytag
385 tagger T A Gger <
386 > 0 +0000
390 check_verify_failure 'disallow malformed tagger' \
391 '^error:.* badEmail:' \
392 --no-strict \
393 --fsck-obj-ok
395 ############################################################
396 # 15. allow empty tag email
398 cat >tag.sig <<EOF
399 object $head
400 type commit
401 tag mytag
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
411 cat >tag.sig <<EOF
412 object $head
413 type commit
414 tag mytag
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
425 object $head
426 type commit
427 tag mytag
428 tagger T A Gger <tagger@example.com>__
432 check_verify_failure 'disallow missing tag timestamp' \
433 '^error:.* badDate:'
435 ############################################################
436 # 18. detect invalid tag timestamp1
438 cat >tag.sig <<EOF
439 object $head
440 type commit
441 tag mytag
442 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
446 check_verify_failure 'detect invalid tag timestamp1' \
447 '^error:.* badDate:'
449 ############################################################
450 # 19. detect invalid tag timestamp2
452 cat >tag.sig <<EOF
453 object $head
454 type commit
455 tag mytag
456 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
460 check_verify_failure 'detect invalid tag timestamp2' \
461 '^error:.* badDate:'
463 ############################################################
464 # 20. detect invalid tag timezone1
466 cat >tag.sig <<EOF
467 object $head
468 type commit
469 tag mytag
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
480 cat >tag.sig <<EOF
481 object $head
482 type commit
483 tag mytag
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)
494 cat >tag.sig <<EOF
495 object $head
496 type commit
497 tag mytag
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
507 cat >tag.sig <<EOF
508 object $head
509 type commit
510 tag mytag
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:' \
518 --no-strict \
519 --fsck-obj-ok
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 &&
534 git fsck &&
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
541 cat >tag.sig <<EOF
542 object $head
543 type commit
544 tag mytag
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'
553 cat >tag.sig <<EOF
554 object $head
555 type commit
556 tag mytag
557 tagger T A Gger <tagger@example.com> 1206478233 -0500
561 test_expect_mktag_success 'allow a blank line before an empty body (1)'
563 cat >tag.sig <<EOF
564 object $head
565 type commit
566 tag mytag
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
575 cat >tag.sig <<EOF
576 object $head
577 type commit
578 tag mytag
579 tagger T A Gger <tagger@example.com> 1206478233 -0500
582 test_expect_mktag_success 'create valid tag object'
584 test_done