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