gc: add `gc.repackFilter` config option
[git.git] / t / t3800-mktag.sh
blobd3e428ff46eb5c99d98a8fe27b54cf98d6d2a936
1 #!/bin/sh
5 test_description='git mktag: tag object verify test'
7 TEST_PASSES_SANITIZE_LEAK=true
8 . ./test-lib.sh
10 ###########################################################
11 # check the tag.sig file, expecting verify_tag() to fail,
12 # and checking that the error message matches the pattern
13 # given in the expect.pat file.
15 check_verify_failure () {
16 subject=$1 &&
17 message=$2 &&
18 shift 2 &&
20 no_strict= &&
21 fsck_obj_ok= &&
22 no_strict= &&
23 while test $# != 0
25 case "$1" in
26 --no-strict)
27 no_strict=yes
29 --fsck-obj-ok)
30 fsck_obj_ok=yes
32 esac &&
33 shift
34 done &&
36 test_expect_success "fail with [--[no-]strict]: $subject" '
37 test_must_fail git mktag <tag.sig 2>err &&
38 if test -z "$no_strict"
39 then
40 test_must_fail git mktag <tag.sig 2>err2 &&
41 test_cmp err err2
42 else
43 git mktag --no-strict <tag.sig
47 test_expect_success "setup: $subject" '
48 tag_ref=refs/tags/bad_tag &&
50 # Reset any leftover state from the last $subject
51 rm -rf bad-tag &&
53 git init --bare bad-tag &&
54 bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally <tag.sig)
57 test_expect_success "hash-object & fsck unreachable: $subject" '
58 if test -n "$fsck_obj_ok"
59 then
60 git -C bad-tag fsck
61 else
62 test_must_fail git -C bad-tag fsck
66 test_expect_success "update-ref & fsck reachable: $subject" '
67 # Make sure the earlier test created it for us
68 git rev-parse "$bad_tag" &&
70 # The update-ref of the bad content will fail, do it
71 # anyway to see if it segfaults
72 test_might_fail git -C bad-tag update-ref "$tag_ref" "$bad_tag" &&
74 # Manually create the broken, we cannot do it with
75 # update-ref
76 test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" &&
77 test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION &&
79 # Unlike fsck-ing unreachable content above, this
80 # will always fail.
81 test_must_fail git -C bad-tag fsck
84 test_expect_success "for-each-ref: $subject" '
85 # Make sure the earlier test created it for us
86 git rev-parse "$bad_tag" &&
88 test-tool -C bad-tag ref-store main delete-refs 0 msg "$tag_ref" &&
89 test-tool -C bad-tag ref-store main update-ref msg "$tag_ref" $bad_tag $ZERO_OID REF_SKIP_OID_VERIFICATION &&
91 printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected &&
92 git -C bad-tag for-each-ref "$tag_ref" >actual &&
93 test_cmp expected actual &&
95 test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
98 test_expect_success "fast-export & fast-import: $subject" '
99 # Make sure the earlier test created it for us
100 git rev-parse "$bad_tag" &&
102 test_must_fail git -C bad-tag fast-export --all &&
103 test_must_fail git -C bad-tag fast-export "$bad_tag"
107 test_expect_mktag_success() {
108 test_expect_success "$1" '
109 git hash-object -t tag -w --stdin <tag.sig >expected &&
110 git fsck --strict &&
112 git mktag <tag.sig >hash &&
113 test_cmp expected hash &&
114 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
115 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
116 git fsck --strict
120 ###########################################################
121 # first create a commit, so we have a valid object/type
122 # for the tag.
123 test_expect_success 'setup' '
124 test_commit A &&
125 test_commit B &&
126 head=$(git rev-parse --verify HEAD) &&
127 head_parent=$(git rev-parse --verify HEAD~) &&
128 tree=$(git rev-parse HEAD^{tree}) &&
129 blob=$(git rev-parse --verify HEAD:B.t)
132 test_expect_success 'basic usage' '
133 cat >tag.sig <<-EOF &&
134 object $head
135 type commit
136 tag mytag
137 tagger T A Gger <tagger@example.com> 1206478233 -0500
139 git mktag <tag.sig &&
140 git mktag --end-of-options <tag.sig &&
141 test_expect_code 129 git mktag --unknown-option
144 ############################################################
145 # 1. length check
147 cat >tag.sig <<EOF
148 too short for a tag
151 check_verify_failure 'Tag object length check' \
152 '^error:.* missingObject:' 'strict'
154 ############################################################
155 # 2. object line label check
157 cat >tag.sig <<EOF
158 xxxxxx $head
159 type tag
160 tag mytag
161 tagger . <> 0 +0000
165 check_verify_failure '"object" line label check' '^error:.* missingObject:'
167 ############################################################
168 # 3. object line hash check
170 cat >tag.sig <<EOF
171 object $(echo $head | tr 0-9a-f z)
172 type tag
173 tag mytag
174 tagger . <> 0 +0000
178 check_verify_failure '"object" line check' '^error:.* badObjectSha1:'
180 ############################################################
181 # 4. type line label check
183 cat >tag.sig <<EOF
184 object $head
185 xxxx tag
186 tag mytag
187 tagger . <> 0 +0000
191 check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:'
193 ############################################################
194 # 5. type line eol check
196 echo "object $head" >tag.sig
197 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
199 check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:'
201 ############################################################
202 # 6. tag line label check #1
204 cat >tag.sig <<EOF
205 object $head
206 type tag
207 xxx mytag
208 tagger . <> 0 +0000
212 check_verify_failure '"tag" line label check #1' \
213 '^error:.* missingTagEntry:'
215 ############################################################
216 # 7. tag line label check #2
218 cat >tag.sig <<EOF
219 object $head
220 type taggggggggggggggggggggggggggggggg
224 check_verify_failure '"tag" line label check #2' \
225 '^error:.* badType:'
227 ############################################################
228 # 8. type line type-name length check
230 cat >tag.sig <<EOF
231 object $head
232 type taggggggggggggggggggggggggggggggg
233 tag mytag
236 check_verify_failure '"type" line type-name length check' \
237 '^error:.* badType:'
239 ############################################################
240 # 9. verify object (hash/type) check
242 cat >tag.sig <<EOF
243 object $(test_oid deadbeef)
244 type tag
245 tag mytag
246 tagger . <> 0 +0000
250 check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
251 '^fatal: could not read tagged object' \
252 --fsck-obj-ok
254 cat >tag.sig <<EOF
255 object $head
256 type tagggg
257 tag mytag
258 tagger . <> 0 +0000
262 check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
263 '^error:.* badType:'
265 cat >tag.sig <<EOF
266 object $(test_oid deadbeef)
267 type tagggg
268 tag mytag
269 tagger . <> 0 +0000
273 check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
274 '^error:.* badType:'
276 cat >tag.sig <<EOF
277 object $head
278 type tree
279 tag mytag
280 tagger . <> 0 +0000
284 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
285 '^fatal: object.*tagged as.*tree.*but is.*commit' \
286 --fsck-obj-ok
288 ############################################################
289 # 9.5. verify object (hash/type) check -- replacement
291 test_expect_success 'setup replacement of commit -> commit and tree -> blob' '
292 git replace $head_parent $head &&
293 git replace -f $tree $blob
296 cat >tag.sig <<EOF
297 object $head_parent
298 type commit
299 tag mytag
300 tagger . <> 0 +0000
304 test_expect_mktag_success 'tag to a commit replaced by another commit'
306 cat >tag.sig <<EOF
307 object $tree
308 type tree
309 tag mytag
310 tagger . <> 0 +0000
314 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
315 '^fatal: object.*tagged as.*tree.*but is.*blob' \
316 --fsck-obj-ok
318 ############################################################
319 # 10. verify tag-name check
321 cat >tag.sig <<EOF
322 object $head
323 type commit
324 tag my tag
325 tagger . <> 0 +0000
329 check_verify_failure 'verify tag-name check' \
330 '^error:.* badTagName:' \
331 --no-strict \
332 --fsck-obj-ok
334 ############################################################
335 # 11. tagger line label check #1
337 cat >tag.sig <<EOF
338 object $head
339 type commit
340 tag mytag
342 This is filler
345 check_verify_failure '"tagger" line label check #1' \
346 '^error:.* missingTaggerEntry:' \
347 --no-strict \
348 --fsck-obj-ok
350 ############################################################
351 # 12. tagger line label check #2
353 cat >tag.sig <<EOF
354 object $head
355 type commit
356 tag mytag
357 tagger
359 This is filler
362 check_verify_failure '"tagger" line label check #2' \
363 '^error:.* missingTaggerEntry:' \
364 --no-strict \
365 --fsck-obj-ok
367 ############################################################
368 # 13. allow missing tag author name like fsck
370 cat >tag.sig <<EOF
371 object $head
372 type commit
373 tag mytag
374 tagger <> 0 +0000
376 This is filler
379 test_expect_mktag_success 'allow missing tag author name'
381 ############################################################
382 # 14. disallow missing tag author name
384 cat >tag.sig <<EOF
385 object $head
386 type commit
387 tag mytag
388 tagger T A Gger <
389 > 0 +0000
393 check_verify_failure 'disallow malformed tagger' \
394 '^error:.* badEmail:' \
395 --no-strict \
396 --fsck-obj-ok
398 ############################################################
399 # 15. allow empty tag email
401 cat >tag.sig <<EOF
402 object $head
403 type commit
404 tag mytag
405 tagger T A Gger <> 0 +0000
409 test_expect_mktag_success 'allow empty tag email'
411 ############################################################
412 # 16. allow spaces in tag email like fsck
414 cat >tag.sig <<EOF
415 object $head
416 type commit
417 tag mytag
418 tagger T A Gger <tag ger@example.com> 0 +0000
422 test_expect_mktag_success 'allow spaces in tag email like fsck'
424 ############################################################
425 # 17. disallow missing tag timestamp
427 tr '_' ' ' >tag.sig <<EOF
428 object $head
429 type commit
430 tag mytag
431 tagger T A Gger <tagger@example.com>__
435 check_verify_failure 'disallow missing tag timestamp' \
436 '^error:.* badDate:'
438 ############################################################
439 # 18. detect invalid tag timestamp1
441 cat >tag.sig <<EOF
442 object $head
443 type commit
444 tag mytag
445 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
449 check_verify_failure 'detect invalid tag timestamp1' \
450 '^error:.* badDate:'
452 ############################################################
453 # 19. detect invalid tag timestamp2
455 cat >tag.sig <<EOF
456 object $head
457 type commit
458 tag mytag
459 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
463 check_verify_failure 'detect invalid tag timestamp2' \
464 '^error:.* badDate:'
466 ############################################################
467 # 20. detect invalid tag timezone1
469 cat >tag.sig <<EOF
470 object $head
471 type commit
472 tag mytag
473 tagger T A Gger <tagger@example.com> 1206478233 GMT
477 check_verify_failure 'detect invalid tag timezone1' \
478 '^error:.* badTimezone:'
480 ############################################################
481 # 21. detect invalid tag timezone2
483 cat >tag.sig <<EOF
484 object $head
485 type commit
486 tag mytag
487 tagger T A Gger <tagger@example.com> 1206478233 + 30
491 check_verify_failure 'detect invalid tag timezone2' \
492 '^error:.* badTimezone:'
494 ############################################################
495 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
497 cat >tag.sig <<EOF
498 object $head
499 type commit
500 tag mytag
501 tagger T A Gger <tagger@example.com> 1206478233 -1430
505 test_expect_mktag_success 'allow invalid tag timezone'
507 ############################################################
508 # 23. detect invalid header entry
510 cat >tag.sig <<EOF
511 object $head
512 type commit
513 tag mytag
514 tagger T A Gger <tagger@example.com> 1206478233 -0500
515 this line should not be here
519 check_verify_failure 'detect invalid header entry' \
520 '^error:.* extraHeaderEntry:' \
521 --no-strict \
522 --fsck-obj-ok
524 test_expect_success 'invalid header entry config & fsck' '
525 test_must_fail git mktag <tag.sig &&
526 git mktag --no-strict <tag.sig &&
528 test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
529 test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
531 test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
532 git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
534 git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
535 git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
537 git fsck &&
538 git -c fsck.extraHeaderEntry=warn fsck 2>err &&
539 grep "warning .*extraHeaderEntry:" err &&
540 test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck &&
541 grep "error .* extraHeaderEntry:" err
544 cat >tag.sig <<EOF
545 object $head
546 type commit
547 tag mytag
548 tagger T A Gger <tagger@example.com> 1206478233 -0500
551 this line comes after an extra newline
554 test_expect_mktag_success 'allow extra newlines at start of body'
556 cat >tag.sig <<EOF
557 object $head
558 type commit
559 tag mytag
560 tagger T A Gger <tagger@example.com> 1206478233 -0500
564 test_expect_mktag_success 'allow a blank line before an empty body (1)'
566 cat >tag.sig <<EOF
567 object $head
568 type commit
569 tag mytag
570 tagger T A Gger <tagger@example.com> 1206478233 -0500
573 test_expect_mktag_success 'allow no blank line before an empty body (2)'
575 ############################################################
576 # 24. create valid tag
578 cat >tag.sig <<EOF
579 object $head
580 type commit
581 tag mytag
582 tagger T A Gger <tagger@example.com> 1206478233 -0500
585 test_expect_mktag_success 'create valid tag object'
587 test_done