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