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