]> git.ipfire.org Git - thirdparty/git.git/blame - t/t3800-mktag.sh
mktag tests: test "hash-object" compatibility
[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" '
aba5377f 17 test_must_fail git mktag <tag.sig 2>message &&
525d4615 18 grep "$expect" message
e9b20943 19 '
446c6fae
RJ
20}
21
ca9a1ed9
ÆAB
22test_expect_mktag_success() {
23 test_expect_success "$1" '
24 git hash-object -t tag -w --stdin <tag.sig >expected &&
25 git fsck --strict &&
26
27 git mktag <tag.sig >hash &&
28 test_cmp expected hash &&
29 test_when_finished "git update-ref -d refs/tags/mytag $(cat hash)" &&
30 git update-ref refs/tags/mytag $(cat hash) $(test_oid zero) &&
31 git fsck --strict
32 '
33}
34
446c6fae
RJ
35###########################################################
36# first create a commit, so we have a valid object/type
37# for the tag.
4a45f7dd 38test_expect_success 'setup' '
b5ca549c 39 test_commit A &&
4a45f7dd
BG
40 head=$(git rev-parse --verify HEAD)
41'
446c6fae
RJ
42
43############################################################
44# 1. length check
45
46cat >tag.sig <<EOF
47too short for a tag
48EOF
49
e9b20943
JH
50check_verify_failure 'Tag object length check' \
51 '^error: .*size wrong.*$'
446c6fae
RJ
52
53############################################################
54# 2. object line label check
55
56cat >tag.sig <<EOF
0d35ccb5 57xxxxxx $head
446c6fae
RJ
58type tag
59tag mytag
e0aaf781
BC
60tagger . <> 0 +0000
61
446c6fae
RJ
62EOF
63
e9b20943 64check_verify_failure '"object" line label check' '^error: char0: .*"object "$'
446c6fae
RJ
65
66############################################################
0d35ccb5 67# 3. object line hash check
446c6fae
RJ
68
69cat >tag.sig <<EOF
0d35ccb5 70object $(echo $head | tr 0-9a-f z)
446c6fae
RJ
71type tag
72tag mytag
e0aaf781
BC
73tagger . <> 0 +0000
74
446c6fae
RJ
75EOF
76
e9b20943 77check_verify_failure '"object" line SHA1 check' '^error: char7: .*SHA1 hash$'
446c6fae
RJ
78
79############################################################
80# 4. type line label check
81
82cat >tag.sig <<EOF
acb49d1c 83object $head
446c6fae
RJ
84xxxx tag
85tag mytag
e0aaf781
BC
86tagger . <> 0 +0000
87
446c6fae
RJ
88EOF
89
acb49d1c 90check_verify_failure '"type" line label check' '^error: char.*: .*"\\ntype "$'
446c6fae
RJ
91
92############################################################
93# 5. type line eol check
94
acb49d1c 95echo "object $head" >tag.sig
2aad957a 96printf "type tagsssssssssssssssssssssssssssssss" >>tag.sig
446c6fae 97
acb49d1c 98check_verify_failure '"type" line eol check' '^error: char.*: .*"\\n"$'
446c6fae
RJ
99
100############################################################
101# 6. tag line label check #1
102
103cat >tag.sig <<EOF
acb49d1c 104object $head
446c6fae
RJ
105type tag
106xxx mytag
e0aaf781
BC
107tagger . <> 0 +0000
108
446c6fae
RJ
109EOF
110
e9b20943 111check_verify_failure '"tag" line label check #1' \
acb49d1c 112 '^error: char.*: no "tag " found$'
446c6fae
RJ
113
114############################################################
115# 7. tag line label check #2
116
117cat >tag.sig <<EOF
acb49d1c 118object $head
446c6fae
RJ
119type taggggggggggggggggggggggggggggggg
120tag
121EOF
122
e9b20943 123check_verify_failure '"tag" line label check #2' \
acb49d1c 124 '^error: char.*: no "tag " found$'
446c6fae
RJ
125
126############################################################
127# 8. type line type-name length check
128
129cat >tag.sig <<EOF
acb49d1c 130object $head
446c6fae
RJ
131type taggggggggggggggggggggggggggggggg
132tag mytag
133EOF
134
e9b20943 135check_verify_failure '"type" line type-name length check' \
acb49d1c 136 '^error: char.*: type too long$'
446c6fae
RJ
137
138############################################################
139# 9. verify object (SHA1/type) check
140
141cat >tag.sig <<EOF
acb49d1c 142object $(test_oid deadbeef)
446c6fae
RJ
143type tagggg
144tag mytag
e0aaf781
BC
145tagger . <> 0 +0000
146
446c6fae
RJ
147EOF
148
e9b20943
JH
149check_verify_failure 'verify object (SHA1/type) check' \
150 '^error: char7: could not verify object.*$'
446c6fae
RJ
151
152############################################################
153# 10. verify tag-name check
154
155cat >tag.sig <<EOF
156object $head
157type commit
158tag my tag
e0aaf781
BC
159tagger . <> 0 +0000
160
446c6fae
RJ
161EOF
162
e9b20943 163check_verify_failure 'verify tag-name check' \
acb49d1c 164 '^error: char.*: could not verify tag name$'
446c6fae
RJ
165
166############################################################
3dff5379 167# 11. tagger line label check #1
446c6fae
RJ
168
169cat >tag.sig <<EOF
170object $head
171type commit
172tag mytag
e0aaf781
BC
173
174This is filler
446c6fae
RJ
175EOF
176
e9b20943 177check_verify_failure '"tagger" line label check #1' \
acb49d1c 178 '^error: char.*: could not find "tagger "$'
446c6fae
RJ
179
180############################################################
3dff5379 181# 12. tagger line label check #2
446c6fae
RJ
182
183cat >tag.sig <<EOF
184object $head
185type commit
186tag mytag
187tagger
e0aaf781
BC
188
189This is filler
446c6fae
RJ
190EOF
191
e9b20943 192check_verify_failure '"tagger" line label check #2' \
acb49d1c 193 '^error: char.*: could not find "tagger "$'
446c6fae
RJ
194
195############################################################
ba26ab99 196# 13. disallow missing tag author name
446c6fae
RJ
197
198cat >tag.sig <<EOF
199object $head
200type commit
201tag mytag
e0aaf781
BC
202tagger <> 0 +0000
203
204This is filler
205EOF
206
ba26ab99 207check_verify_failure 'disallow missing tag author name' \
acb49d1c 208 '^error: char.*: missing tagger name$'
e0aaf781
BC
209
210############################################################
ba26ab99 211# 14. disallow missing tag author name
e0aaf781
BC
212
213cat >tag.sig <<EOF
214object $head
215type commit
216tag mytag
217tagger T A Gger <
218 > 0 +0000
219
220EOF
221
ba26ab99 222check_verify_failure 'disallow malformed tagger' \
acb49d1c 223 '^error: char.*: malformed tagger field$'
e0aaf781
BC
224
225############################################################
226# 15. allow empty tag email
227
228cat >tag.sig <<EOF
229object $head
230type commit
231tag mytag
232tagger T A Gger <> 0 +0000
233
234EOF
235
ca9a1ed9 236test_expect_mktag_success 'allow empty tag email'
e0aaf781
BC
237
238############################################################
ba26ab99
BC
239# 16. disallow spaces in tag email
240
241cat >tag.sig <<EOF
242object $head
243type commit
244tag mytag
245tagger T A Gger <tag ger@example.com> 0 +0000
246
247EOF
248
249check_verify_failure 'disallow spaces in tag email' \
acb49d1c 250 '^error: char.*: malformed tagger field$'
ba26ab99
BC
251
252############################################################
253# 17. disallow missing tag timestamp
e0aaf781 254
74f16b0c 255tr '_' ' ' >tag.sig <<EOF
e0aaf781
BC
256object $head
257type commit
258tag mytag
74f16b0c 259tagger T A Gger <tagger@example.com>__
e0aaf781
BC
260
261EOF
262
ba26ab99 263check_verify_failure 'disallow missing tag timestamp' \
acb49d1c 264 '^error: char.*: missing tag timestamp$'
e0aaf781
BC
265
266############################################################
ba26ab99 267# 18. detect invalid tag timestamp1
e0aaf781
BC
268
269cat >tag.sig <<EOF
270object $head
271type commit
272tag mytag
273tagger T A Gger <tagger@example.com> Tue Mar 25 15:47:44 2008
274
275EOF
276
ba26ab99 277check_verify_failure 'detect invalid tag timestamp1' \
acb49d1c 278 '^error: char.*: missing tag timestamp$'
e0aaf781
BC
279
280############################################################
ba26ab99
BC
281# 19. detect invalid tag timestamp2
282
283cat >tag.sig <<EOF
284object $head
285type commit
286tag mytag
287tagger T A Gger <tagger@example.com> 2008-03-31T12:20:15-0500
288
289EOF
290
291check_verify_failure 'detect invalid tag timestamp2' \
acb49d1c 292 '^error: char.*: malformed tag timestamp$'
ba26ab99
BC
293
294############################################################
295# 20. detect invalid tag timezone1
e0aaf781
BC
296
297cat >tag.sig <<EOF
298object $head
299type commit
300tag mytag
301tagger T A Gger <tagger@example.com> 1206478233 GMT
302
303EOF
304
ba26ab99 305check_verify_failure 'detect invalid tag timezone1' \
acb49d1c 306 '^error: char.*: malformed tag timezone$'
ba26ab99
BC
307
308############################################################
309# 21. detect invalid tag timezone2
310
311cat >tag.sig <<EOF
312object $head
313type commit
314tag mytag
315tagger T A Gger <tagger@example.com> 1206478233 + 30
316
317EOF
318
319check_verify_failure 'detect invalid tag timezone2' \
acb49d1c 320 '^error: char.*: malformed tag timezone$'
ba26ab99
BC
321
322############################################################
323# 22. detect invalid tag timezone3
324
325cat >tag.sig <<EOF
326object $head
327type commit
328tag mytag
329tagger T A Gger <tagger@example.com> 1206478233 -1430
330
331EOF
332
333check_verify_failure 'detect invalid tag timezone3' \
acb49d1c 334 '^error: char.*: malformed tag timezone$'
e0aaf781
BC
335
336############################################################
ba26ab99 337# 23. detect invalid header entry
e0aaf781
BC
338
339cat >tag.sig <<EOF
340object $head
341type commit
342tag mytag
343tagger T A Gger <tagger@example.com> 1206478233 -0500
344this line should not be here
345
346EOF
347
348check_verify_failure 'detect invalid header entry' \
acb49d1c 349 '^error: char.*: trailing garbage in tag header$'
e0aaf781 350
47c95e77
ÆAB
351cat >tag.sig <<EOF
352object $head
353type commit
354tag mytag
355tagger T A Gger <tagger@example.com> 1206478233 -0500
356
357
358this line comes after an extra newline
359EOF
360
ca9a1ed9 361test_expect_mktag_success 'allow extra newlines at start of body'
47c95e77
ÆAB
362
363cat >tag.sig <<EOF
364object $head
365type commit
366tag mytag
367tagger T A Gger <tagger@example.com> 1206478233 -0500
368
369EOF
370
ca9a1ed9 371test_expect_mktag_success 'require a blank line before an empty body (1)'
47c95e77
ÆAB
372
373cat >tag.sig <<EOF
374object $head
375type commit
376tag mytag
377tagger T A Gger <tagger@example.com> 1206478233 -0500
378EOF
379
380check_verify_failure 'require a blank line before an empty body (2)' \
381 '^error: char.*: trailing garbage in tag header$'
382
e0aaf781 383############################################################
ba26ab99 384# 24. create valid tag
e0aaf781
BC
385
386cat >tag.sig <<EOF
387object $head
388type commit
389tag mytag
390tagger T A Gger <tagger@example.com> 1206478233 -0500
391
446c6fae
RJ
392EOF
393
ca9a1ed9 394test_expect_mktag_success 'create valid tag object'
446c6fae
RJ
395
396test_done