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