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