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