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