Merge branch 'ab/progress-cleanup' into seen
[git] / t / t3800-mktag.sh
1 #!/bin/sh
2 #
3 #
4
5 test_description='git mktag: tag object verify test'
6
7 . ./test-lib.sh
8
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.
13
14 check_verify_failure () {
15         subject=$1 &&
16         message=$2 &&
17         shift 2 &&
18
19         no_strict= &&
20         fsck_obj_ok= &&
21         no_strict= &&
22         while test $# != 0
23         do
24                 case "$1" in
25                 --no-strict)
26                         no_strict=yes
27                         ;;
28                 --fsck-obj-ok)
29                         fsck_obj_ok=yes
30                         ;;
31                 esac
32                 shift
33         done &&
34
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
43                 fi
44         '
45
46         test_expect_success "setup: $subject" '
47                 tag_ref=refs/tags/bad_tag &&
48
49                 # Reset any leftover state from the last $subject
50                 rm -rf bad-tag &&
51
52                 git init --bare bad-tag &&
53                 bad_tag=$(git -C bad-tag hash-object -t tag -w --stdin --literally <tag.sig)
54         '
55
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 >out 2>err
62                 fi
63         '
64
65         test_expect_success "update-ref & fsck reachable: $subject" '
66                 # The update-ref of the bad content will fail, do it
67                 # anyway to see if it segfaults
68                 test_might_fail git -C bad-tag update-ref "$tag_ref" "$bad_tag" &&
69
70                 # Manually create the broken, we cannot do it with
71                 # update-ref
72                 echo "$bad_tag" >"bad-tag/$tag_ref" &&
73
74                 # Unlike fsck-ing unreachable content above, this
75                 # will always fail.
76                 test_must_fail git -C bad-tag fsck
77         '
78
79         test_expect_success "for-each-ref: $subject" '
80                 echo "$bad_tag" >"bad-tag/$tag_ref" &&
81
82                 printf "%s tag\t%s\n" "$bad_tag" "$tag_ref" >expected &&
83                 git -C bad-tag for-each-ref "$tag_ref" >actual &&
84                 test_cmp expected actual &&
85
86                 test_must_fail git -C bad-tag for-each-ref --format="%(*objectname)"
87         '
88
89         test_expect_success "fast-export & fast-import: $subject" '
90                 test_must_fail git -C bad-tag fast-export --all &&
91                 test_must_fail git -C bad-tag fast-export $bad_tag
92         '
93 }
94
95 test_expect_mktag_success() {
96         test_expect_success "$1" '
97                 git hash-object -t tag -w --stdin <tag.sig >expected &&
98                 git fsck --strict &&
99
100                 git mktag <tag.sig >hash &&
101                 test_cmp expected hash &&
102                 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
103                 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
104                 git fsck --strict
105         '
106 }
107
108 ###########################################################
109 # first create a commit, so we have a valid object/type
110 # for the tag.
111 test_expect_success 'setup' '
112         test_commit A &&
113         test_commit B &&
114         head=$(git rev-parse --verify HEAD) &&
115         head_parent=$(git rev-parse --verify HEAD~) &&
116         tree=$(git rev-parse HEAD^{tree}) &&
117         blob=$(git rev-parse --verify HEAD:B.t)
118 '
119
120 test_expect_success 'basic usage' '
121         cat >tag.sig <<-EOF &&
122         object $head
123         type commit
124         tag mytag
125         tagger T A Gger <tagger@example.com> 1206478233 -0500
126         EOF
127         git mktag <tag.sig &&
128         git mktag --end-of-options <tag.sig &&
129         test_expect_code 129 git mktag --unknown-option
130 '
131
132 ############################################################
133 #  1. length check
134
135 cat >tag.sig <<EOF
136 too short for a tag
137 EOF
138
139 check_verify_failure 'Tag object length check' \
140         '^error:.* missingObject:' 'strict'
141
142 ############################################################
143 #  2. object line label check
144
145 cat >tag.sig <<EOF
146 xxxxxx $head
147 type tag
148 tag mytag
149 tagger . <> 0 +0000
150
151 EOF
152
153 check_verify_failure '"object" line label check' '^error:.* missingObject:'
154
155 ############################################################
156 #  3. object line hash check
157
158 cat >tag.sig <<EOF
159 object $(echo $head | tr 0-9a-f z)
160 type tag
161 tag mytag
162 tagger . <> 0 +0000
163
164 EOF
165
166 check_verify_failure '"object" line check' '^error:.* badObjectSha1:'
167
168 ############################################################
169 #  4. type line label check
170
171 cat >tag.sig <<EOF
172 object $head
173 xxxx tag
174 tag mytag
175 tagger . <> 0 +0000
176
177 EOF
178
179 check_verify_failure '"type" line label check' '^error:.* missingTypeEntry:'
180
181 ############################################################
182 #  5. type line eol check
183
184 echo "object $head" >tag.sig
185 printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
186
187 check_verify_failure '"type" line eol check' '^error:.* unterminatedHeader:'
188
189 ############################################################
190 #  6. tag line label check #1
191
192 cat >tag.sig <<EOF
193 object $head
194 type tag
195 xxx mytag
196 tagger . <> 0 +0000
197
198 EOF
199
200 check_verify_failure '"tag" line label check #1' \
201         '^error:.* missingTagEntry:'
202
203 ############################################################
204 #  7. tag line label check #2
205
206 cat >tag.sig <<EOF
207 object $head
208 type taggggggggggggggggggggggggggggggg
209 tag
210 EOF
211
212 check_verify_failure '"tag" line label check #2' \
213         '^error:.* badType:'
214
215 ############################################################
216 #  8. type line type-name length check
217
218 cat >tag.sig <<EOF
219 object $head
220 type taggggggggggggggggggggggggggggggg
221 tag mytag
222 EOF
223
224 check_verify_failure '"type" line type-name length check' \
225         '^error:.* badType:'
226
227 ############################################################
228 #  9. verify object (hash/type) check
229
230 cat >tag.sig <<EOF
231 object $(test_oid deadbeef)
232 type tag
233 tag mytag
234 tagger . <> 0 +0000
235
236 EOF
237
238 check_verify_failure 'verify object (hash/type) check -- correct type, nonexisting object' \
239         '^fatal: could not read tagged object' \
240         --fsck-obj-ok
241
242 cat >tag.sig <<EOF
243 object $head
244 type tagggg
245 tag mytag
246 tagger . <> 0 +0000
247
248 EOF
249
250 check_verify_failure 'verify object (hash/type) check -- made-up type, valid object' \
251         '^error:.* badType:'
252
253 cat >tag.sig <<EOF
254 object $(test_oid deadbeef)
255 type tagggg
256 tag mytag
257 tagger . <> 0 +0000
258
259 EOF
260
261 check_verify_failure 'verify object (hash/type) check -- made-up type, nonexisting object' \
262         '^error:.* badType:'
263
264 cat >tag.sig <<EOF
265 object $head
266 type tree
267 tag mytag
268 tagger . <> 0 +0000
269
270 EOF
271
272 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
273         '^fatal: object.*tagged as.*tree.*but is.*commit' \
274         --fsck-obj-ok
275
276 ############################################################
277 #  9.5. verify object (hash/type) check -- replacement
278
279 test_expect_success 'setup replacement of commit -> commit and tree -> blob' '
280         git replace $head_parent $head &&
281         git replace -f $tree $blob
282 '
283
284 cat >tag.sig <<EOF
285 object $head_parent
286 type commit
287 tag mytag
288 tagger . <> 0 +0000
289
290 EOF
291
292 test_expect_mktag_success 'tag to a commit replaced by another commit'
293
294 cat >tag.sig <<EOF
295 object $tree
296 type tree
297 tag mytag
298 tagger . <> 0 +0000
299
300 EOF
301
302 check_verify_failure 'verify object (hash/type) check -- mismatched type, valid object' \
303         '^fatal: object.*tagged as.*tree.*but is.*blob' \
304         --fsck-obj-ok
305
306 ############################################################
307 # 10. verify tag-name check
308
309 cat >tag.sig <<EOF
310 object $head
311 type commit
312 tag my  tag
313 tagger . <> 0 +0000
314
315 EOF
316
317 check_verify_failure 'verify tag-name check' \
318         '^error:.* badTagName:' \
319         --no-strict \
320         --fsck-obj-ok
321
322 ############################################################
323 # 11. tagger line label check #1
324
325 cat >tag.sig <<EOF
326 object $head
327 type commit
328 tag mytag
329
330 This is filler
331 EOF
332
333 check_verify_failure '"tagger" line label check #1' \
334         '^error:.* missingTaggerEntry:' \
335         --no-strict \
336         --fsck-obj-ok
337
338 ############################################################
339 # 12. tagger line label check #2
340
341 cat >tag.sig <<EOF
342 object $head
343 type commit
344 tag mytag
345 tagger
346
347 This is filler
348 EOF
349
350 check_verify_failure '"tagger" line label check #2' \
351         '^error:.* missingTaggerEntry:' \
352         --no-strict \
353         --fsck-obj-ok
354
355 ############################################################
356 # 13. allow missing tag author name like fsck
357
358 cat >tag.sig <<EOF
359 object $head
360 type commit
361 tag mytag
362 tagger  <> 0 +0000
363
364 This is filler
365 EOF
366
367 test_expect_mktag_success 'allow missing tag author name'
368
369 ############################################################
370 # 14. disallow missing tag author name
371
372 cat >tag.sig <<EOF
373 object $head
374 type commit
375 tag mytag
376 tagger T A Gger <
377  > 0 +0000
378
379 EOF
380
381 check_verify_failure 'disallow malformed tagger' \
382         '^error:.* badEmail:' \
383         --no-strict \
384         --fsck-obj-ok
385
386 ############################################################
387 # 15. allow empty tag email
388
389 cat >tag.sig <<EOF
390 object $head
391 type commit
392 tag mytag
393 tagger T A Gger <> 0 +0000
394
395 EOF
396
397 test_expect_mktag_success 'allow empty tag email'
398
399 ############################################################
400 # 16. allow spaces in tag email like fsck
401
402 cat >tag.sig <<EOF
403 object $head
404 type commit
405 tag mytag
406 tagger T A Gger <tag ger@example.com> 0 +0000
407
408 EOF
409
410 test_expect_mktag_success 'allow spaces in tag email like fsck'
411
412 ############################################################
413 # 17. disallow missing tag timestamp
414
415 tr '_' ' ' >tag.sig <<EOF
416 object $head
417 type commit
418 tag mytag
419 tagger T A Gger <tagger@example.com>__
420
421 EOF
422
423 check_verify_failure 'disallow missing tag timestamp' \
424         '^error:.* badDate:'
425
426 ############################################################
427 # 18. detect invalid tag timestamp1
428
429 cat >tag.sig <<EOF
430 object $head
431 type commit
432 tag mytag
433 tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
434
435 EOF
436
437 check_verify_failure 'detect invalid tag timestamp1' \
438         '^error:.* badDate:'
439
440 ############################################################
441 # 19. detect invalid tag timestamp2
442
443 cat >tag.sig <<EOF
444 object $head
445 type commit
446 tag mytag
447 tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
448
449 EOF
450
451 check_verify_failure 'detect invalid tag timestamp2' \
452         '^error:.* badDate:'
453
454 ############################################################
455 # 20. detect invalid tag timezone1
456
457 cat >tag.sig <<EOF
458 object $head
459 type commit
460 tag mytag
461 tagger T A Gger <tagger@example.com> 1206478233 GMT
462
463 EOF
464
465 check_verify_failure 'detect invalid tag timezone1' \
466         '^error:.* badTimezone:'
467
468 ############################################################
469 # 21. detect invalid tag timezone2
470
471 cat >tag.sig <<EOF
472 object $head
473 type commit
474 tag mytag
475 tagger T A Gger <tagger@example.com> 1206478233 +  30
476
477 EOF
478
479 check_verify_failure 'detect invalid tag timezone2' \
480         '^error:.* badTimezone:'
481
482 ############################################################
483 # 22. allow invalid tag timezone3 (the maximum is -1200/+1400)
484
485 cat >tag.sig <<EOF
486 object $head
487 type commit
488 tag mytag
489 tagger T A Gger <tagger@example.com> 1206478233 -1430
490
491 EOF
492
493 test_expect_mktag_success 'allow invalid tag timezone'
494
495 ############################################################
496 # 23. detect invalid header entry
497
498 cat >tag.sig <<EOF
499 object $head
500 type commit
501 tag mytag
502 tagger T A Gger <tagger@example.com> 1206478233 -0500
503 this line should not be here
504
505 EOF
506
507 check_verify_failure 'detect invalid header entry' \
508         '^error:.* extraHeaderEntry:' \
509         --no-strict \
510         --fsck-obj-ok
511
512 test_expect_success 'invalid header entry config & fsck' '
513         test_must_fail git mktag <tag.sig &&
514         git mktag --no-strict <tag.sig &&
515
516         test_must_fail git -c fsck.extraHeaderEntry=error mktag <tag.sig &&
517         test_must_fail git -c fsck.extraHeaderEntry=error mktag --no-strict <tag.sig &&
518
519         test_must_fail git -c fsck.extraHeaderEntry=warn mktag <tag.sig &&
520         git -c fsck.extraHeaderEntry=warn mktag --no-strict <tag.sig &&
521
522         git -c fsck.extraHeaderEntry=ignore mktag <tag.sig &&
523         git -c fsck.extraHeaderEntry=ignore mktag --no-strict <tag.sig &&
524
525         git fsck &&
526         git -c fsck.extraHeaderEntry=warn fsck 2>err &&
527         grep "warning .*extraHeaderEntry:" err &&
528         test_must_fail git -c fsck.extraHeaderEntry=error 2>err fsck &&
529         grep "error .* extraHeaderEntry:" err
530 '
531
532 cat >tag.sig <<EOF
533 object $head
534 type commit
535 tag mytag
536 tagger T A Gger <tagger@example.com> 1206478233 -0500
537
538
539 this line comes after an extra newline
540 EOF
541
542 test_expect_mktag_success 'allow extra newlines at start of body'
543
544 cat >tag.sig <<EOF
545 object $head
546 type commit
547 tag mytag
548 tagger T A Gger <tagger@example.com> 1206478233 -0500
549
550 EOF
551
552 test_expect_mktag_success 'allow a blank line before an empty body (1)'
553
554 cat >tag.sig <<EOF
555 object $head
556 type commit
557 tag mytag
558 tagger T A Gger <tagger@example.com> 1206478233 -0500
559 EOF
560
561 test_expect_mktag_success 'allow no blank line before an empty body (2)'
562
563 ############################################################
564 # 24. create valid tag
565
566 cat >tag.sig <<EOF
567 object $head
568 type commit
569 tag mytag
570 tagger T A Gger <tagger@example.com> 1206478233 -0500
571 EOF
572
573 test_expect_mktag_success 'create valid tag object'
574
575 test_done