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