]>
Commit | Line | Data |
---|---|---|
ef5a6fb5 CR |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Carlos Rica | |
4 | # | |
5 | ||
d592b315 | 6 | test_description='git tag |
ef5a6fb5 | 7 | |
62e09ce9 | 8 | Tests for operations with tags.' |
ef5a6fb5 CR |
9 | |
10 | . ./test-lib.sh | |
37d3e859 | 11 | . "$TEST_DIRECTORY"/lib-gpg.sh |
ef5a6fb5 CR |
12 | |
13 | # creating and listing lightweight tags: | |
14 | ||
15 | tag_exists () { | |
16 | git show-ref --quiet --verify refs/tags/"$1" | |
17 | } | |
18 | ||
19 | # todo: git tag -l now returns always zero, when fixed, change this test | |
62e09ce9 CR |
20 | test_expect_success 'listing all tags in an empty tree should succeed' ' |
21 | git tag -l && | |
22 | git tag | |
23 | ' | |
ef5a6fb5 | 24 | |
62e09ce9 | 25 | test_expect_success 'listing all tags in an empty tree should output nothing' ' |
d592b315 NS |
26 | test `git tag -l | wc -l` -eq 0 && |
27 | test `git tag | wc -l` -eq 0 | |
62e09ce9 | 28 | ' |
ef5a6fb5 | 29 | |
41ac414e JH |
30 | test_expect_success 'looking for a tag in an empty tree should fail' \ |
31 | '! (tag_exists mytag)' | |
ef5a6fb5 CR |
32 | |
33 | test_expect_success 'creating a tag in an empty tree should fail' ' | |
d592b315 | 34 | test_must_fail git tag mynotag && |
ef5a6fb5 CR |
35 | ! tag_exists mynotag |
36 | ' | |
37 | ||
38 | test_expect_success 'creating a tag for HEAD in an empty tree should fail' ' | |
d592b315 | 39 | test_must_fail git tag mytaghead HEAD && |
ef5a6fb5 CR |
40 | ! tag_exists mytaghead |
41 | ' | |
42 | ||
43 | test_expect_success 'creating a tag for an unknown revision should fail' ' | |
d592b315 | 44 | test_must_fail git tag mytagnorev aaaaaaaaaaa && |
ef5a6fb5 CR |
45 | ! tag_exists mytagnorev |
46 | ' | |
47 | ||
48 | # commit used in the tests, test_tick is also called here to freeze the date: | |
49 | test_expect_success 'creating a tag using default HEAD should succeed' ' | |
50 | test_tick && | |
51 | echo foo >foo && | |
52 | git add foo && | |
53 | git commit -m Foo && | |
54 | git tag mytag | |
55 | ' | |
56 | ||
62e09ce9 | 57 | test_expect_success 'listing all tags if one exists should succeed' ' |
d592b315 NS |
58 | git tag -l && |
59 | git tag | |
62e09ce9 | 60 | ' |
ef5a6fb5 | 61 | |
62e09ce9 | 62 | test_expect_success 'listing all tags if one exists should output that tag' ' |
d592b315 NS |
63 | test `git tag -l` = mytag && |
64 | test `git tag` = mytag | |
62e09ce9 | 65 | ' |
ef5a6fb5 CR |
66 | |
67 | # pattern matching: | |
68 | ||
69 | test_expect_success 'listing a tag using a matching pattern should succeed' \ | |
d592b315 | 70 | 'git tag -l mytag' |
ef5a6fb5 CR |
71 | |
72 | test_expect_success \ | |
73 | 'listing a tag using a matching pattern should output that tag' \ | |
d592b315 | 74 | 'test `git tag -l mytag` = mytag' |
ef5a6fb5 CR |
75 | |
76 | # todo: git tag -l now returns always zero, when fixed, change this test | |
77 | test_expect_success \ | |
78 | 'listing tags using a non-matching pattern should suceed' \ | |
d592b315 | 79 | 'git tag -l xxx' |
ef5a6fb5 CR |
80 | |
81 | test_expect_success \ | |
82 | 'listing tags using a non-matching pattern should output nothing' \ | |
d592b315 | 83 | 'test `git tag -l xxx | wc -l` -eq 0' |
ef5a6fb5 CR |
84 | |
85 | # special cases for creating tags: | |
86 | ||
41ac414e | 87 | test_expect_success \ |
ef5a6fb5 | 88 | 'trying to create a tag with the name of one existing should fail' \ |
d492b31c | 89 | 'test_must_fail git tag mytag' |
ef5a6fb5 CR |
90 | |
91 | test_expect_success \ | |
92 | 'trying to create a tag with a non-valid name should fail' ' | |
d592b315 | 93 | test `git tag -l | wc -l` -eq 1 && |
d492b31c SB |
94 | test_must_fail git tag "" && |
95 | test_must_fail git tag .othertag && | |
96 | test_must_fail git tag "other tag" && | |
97 | test_must_fail git tag "othertag^" && | |
98 | test_must_fail git tag "other~tag" && | |
d592b315 | 99 | test `git tag -l | wc -l` -eq 1 |
ef5a6fb5 CR |
100 | ' |
101 | ||
102 | test_expect_success 'creating a tag using HEAD directly should succeed' ' | |
103 | git tag myhead HEAD && | |
104 | tag_exists myhead | |
105 | ' | |
106 | ||
107 | # deleting tags: | |
108 | ||
109 | test_expect_success 'trying to delete an unknown tag should fail' ' | |
110 | ! tag_exists unknown-tag && | |
d592b315 | 111 | test_must_fail git tag -d unknown-tag |
ef5a6fb5 CR |
112 | ' |
113 | ||
114 | cat >expect <<EOF | |
115 | myhead | |
116 | mytag | |
117 | EOF | |
118 | test_expect_success \ | |
119 | 'trying to delete tags without params should succeed and do nothing' ' | |
3af82863 | 120 | git tag -l > actual && test_cmp expect actual && |
d592b315 | 121 | git tag -d && |
3af82863 | 122 | git tag -l > actual && test_cmp expect actual |
ef5a6fb5 CR |
123 | ' |
124 | ||
125 | test_expect_success \ | |
126 | 'deleting two existing tags in one command should succeed' ' | |
127 | tag_exists mytag && | |
128 | tag_exists myhead && | |
d592b315 | 129 | git tag -d mytag myhead && |
ef5a6fb5 CR |
130 | ! tag_exists mytag && |
131 | ! tag_exists myhead | |
132 | ' | |
133 | ||
134 | test_expect_success \ | |
135 | 'creating a tag with the name of another deleted one should succeed' ' | |
136 | ! tag_exists mytag && | |
d592b315 | 137 | git tag mytag && |
ef5a6fb5 CR |
138 | tag_exists mytag |
139 | ' | |
140 | ||
141 | test_expect_success \ | |
142 | 'trying to delete two tags, existing and not, should fail in the 2nd' ' | |
143 | tag_exists mytag && | |
144 | ! tag_exists myhead && | |
d592b315 | 145 | test_must_fail git tag -d mytag anothertag && |
ef5a6fb5 CR |
146 | ! tag_exists mytag && |
147 | ! tag_exists myhead | |
148 | ' | |
149 | ||
41ac414e | 150 | test_expect_success 'trying to delete an already deleted tag should fail' \ |
d592b315 | 151 | 'test_must_fail git tag -d mytag' |
ef5a6fb5 CR |
152 | |
153 | # listing various tags with pattern matching: | |
154 | ||
155 | cat >expect <<EOF | |
156 | a1 | |
157 | aa1 | |
158 | cba | |
159 | t210 | |
160 | t211 | |
161 | v0.2.1 | |
162 | v1.0 | |
163 | v1.0.1 | |
164 | v1.1.3 | |
165 | EOF | |
166 | test_expect_success 'listing all tags should print them ordered' ' | |
167 | git tag v1.0.1 && | |
168 | git tag t211 && | |
169 | git tag aa1 && | |
170 | git tag v0.2.1 && | |
171 | git tag v1.1.3 && | |
172 | git tag cba && | |
173 | git tag a1 && | |
174 | git tag v1.0 && | |
175 | git tag t210 && | |
5206d130 | 176 | git tag -l > actual && |
3af82863 | 177 | test_cmp expect actual && |
62e09ce9 | 178 | git tag > actual && |
3af82863 | 179 | test_cmp expect actual |
ef5a6fb5 CR |
180 | ' |
181 | ||
182 | cat >expect <<EOF | |
183 | a1 | |
184 | aa1 | |
185 | cba | |
186 | EOF | |
187 | test_expect_success \ | |
188 | 'listing tags with substring as pattern must print those matching' ' | |
0aaaef7b JS |
189 | rm *a* && |
190 | git tag -l "*a*" > current && | |
191 | test_cmp expect current | |
ef5a6fb5 CR |
192 | ' |
193 | ||
194 | cat >expect <<EOF | |
195 | v0.2.1 | |
196 | v1.0.1 | |
ef5a6fb5 CR |
197 | EOF |
198 | test_expect_success \ | |
18e32b5b | 199 | 'listing tags with a suffix as pattern must print those matching' ' |
d592b315 | 200 | git tag -l "*.1" > actual && |
3af82863 | 201 | test_cmp expect actual |
ef5a6fb5 CR |
202 | ' |
203 | ||
204 | cat >expect <<EOF | |
205 | t210 | |
206 | t211 | |
207 | EOF | |
208 | test_expect_success \ | |
18e32b5b | 209 | 'listing tags with a prefix as pattern must print those matching' ' |
d592b315 | 210 | git tag -l "t21*" > actual && |
3af82863 | 211 | test_cmp expect actual |
ef5a6fb5 CR |
212 | ' |
213 | ||
214 | cat >expect <<EOF | |
215 | a1 | |
ef5a6fb5 CR |
216 | EOF |
217 | test_expect_success \ | |
18e32b5b | 218 | 'listing tags using a name as pattern must print that one matching' ' |
d592b315 | 219 | git tag -l a1 > actual && |
3af82863 | 220 | test_cmp expect actual |
ef5a6fb5 CR |
221 | ' |
222 | ||
223 | cat >expect <<EOF | |
224 | v1.0 | |
ef5a6fb5 CR |
225 | EOF |
226 | test_expect_success \ | |
18e32b5b | 227 | 'listing tags using a name as pattern must print that one matching' ' |
d592b315 | 228 | git tag -l v1.0 > actual && |
3af82863 | 229 | test_cmp expect actual |
ef5a6fb5 CR |
230 | ' |
231 | ||
232 | cat >expect <<EOF | |
18e32b5b | 233 | v1.0.1 |
ef5a6fb5 CR |
234 | v1.1.3 |
235 | EOF | |
236 | test_expect_success \ | |
237 | 'listing tags with ? in the pattern should print those matching' ' | |
d592b315 | 238 | git tag -l "v1.?.?" > actual && |
3af82863 | 239 | test_cmp expect actual |
ef5a6fb5 CR |
240 | ' |
241 | ||
242 | >expect | |
243 | test_expect_success \ | |
244 | 'listing tags using v.* should print nothing because none have v.' ' | |
d592b315 | 245 | git tag -l "v.*" > actual && |
3af82863 | 246 | test_cmp expect actual |
ef5a6fb5 CR |
247 | ' |
248 | ||
249 | cat >expect <<EOF | |
250 | v0.2.1 | |
251 | v1.0 | |
252 | v1.0.1 | |
253 | v1.1.3 | |
254 | EOF | |
255 | test_expect_success \ | |
256 | 'listing tags using v* should print only those having v' ' | |
d592b315 | 257 | git tag -l "v*" > actual && |
3af82863 | 258 | test_cmp expect actual |
ef5a6fb5 CR |
259 | ' |
260 | ||
588d0e83 JK |
261 | test_expect_success 'tag -l can accept multiple patterns' ' |
262 | git tag -l "v1*" "v0*" >actual && | |
263 | test_cmp expect actual | |
264 | ' | |
265 | ||
ef5a6fb5 CR |
266 | # creating and verifying lightweight tags: |
267 | ||
268 | test_expect_success \ | |
269 | 'a non-annotated tag created without parameters should point to HEAD' ' | |
d592b315 | 270 | git tag non-annotated-tag && |
5be60078 JH |
271 | test $(git cat-file -t non-annotated-tag) = commit && |
272 | test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) | |
ef5a6fb5 CR |
273 | ' |
274 | ||
41ac414e | 275 | test_expect_success 'trying to verify an unknown tag should fail' \ |
d592b315 | 276 | 'test_must_fail git tag -v unknown-tag' |
ef5a6fb5 | 277 | |
41ac414e | 278 | test_expect_success \ |
ef5a6fb5 | 279 | 'trying to verify a non-annotated and non-signed tag should fail' \ |
d592b315 | 280 | 'test_must_fail git tag -v non-annotated-tag' |
ef5a6fb5 | 281 | |
41ac414e | 282 | test_expect_success \ |
62e09ce9 | 283 | 'trying to verify many non-annotated or unknown tags, should fail' \ |
d592b315 | 284 | 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' |
62e09ce9 | 285 | |
ef5a6fb5 CR |
286 | # creating annotated tags: |
287 | ||
288 | get_tag_msg () { | |
289 | git cat-file tag "$1" | sed -e "/BEGIN PGP/q" | |
290 | } | |
291 | ||
292 | # run test_tick before committing always gives the time in that timezone | |
293 | get_tag_header () { | |
294 | cat <<EOF | |
295 | object $2 | |
296 | type $3 | |
297 | tag $1 | |
298 | tagger C O Mitter <committer@example.com> $4 -0700 | |
299 | ||
300 | EOF | |
301 | } | |
302 | ||
303 | commit=$(git rev-parse HEAD) | |
304 | time=$test_tick | |
305 | ||
306 | get_tag_header annotated-tag $commit commit $time >expect | |
307 | echo "A message" >>expect | |
308 | test_expect_success \ | |
309 | 'creating an annotated tag with -m message should succeed' ' | |
d592b315 | 310 | git tag -m "A message" annotated-tag && |
ef5a6fb5 | 311 | get_tag_msg annotated-tag >actual && |
3af82863 | 312 | test_cmp expect actual |
ef5a6fb5 CR |
313 | ' |
314 | ||
315 | cat >msgfile <<EOF | |
316 | Another message | |
317 | in a file. | |
318 | EOF | |
319 | get_tag_header file-annotated-tag $commit commit $time >expect | |
320 | cat msgfile >>expect | |
321 | test_expect_success \ | |
322 | 'creating an annotated tag with -F messagefile should succeed' ' | |
d592b315 | 323 | git tag -F msgfile file-annotated-tag && |
ef5a6fb5 | 324 | get_tag_msg file-annotated-tag >actual && |
3af82863 | 325 | test_cmp expect actual |
ef5a6fb5 CR |
326 | ' |
327 | ||
62e09ce9 CR |
328 | cat >inputmsg <<EOF |
329 | A message from the | |
330 | standard input | |
331 | EOF | |
332 | get_tag_header stdin-annotated-tag $commit commit $time >expect | |
333 | cat inputmsg >>expect | |
334 | test_expect_success 'creating an annotated tag with -F - should succeed' ' | |
d592b315 | 335 | git tag -F - stdin-annotated-tag <inputmsg && |
62e09ce9 | 336 | get_tag_msg stdin-annotated-tag >actual && |
3af82863 | 337 | test_cmp expect actual |
62e09ce9 CR |
338 | ' |
339 | ||
e317cfaf CR |
340 | test_expect_success \ |
341 | 'trying to create a tag with a non-existing -F file should fail' ' | |
342 | ! test -f nonexistingfile && | |
343 | ! tag_exists notag && | |
d592b315 | 344 | test_must_fail git tag -F nonexistingfile notag && |
e317cfaf CR |
345 | ! tag_exists notag |
346 | ' | |
347 | ||
348 | test_expect_success \ | |
39686585 | 349 | 'trying to create tags giving both -m or -F options should fail' ' |
e317cfaf CR |
350 | echo "message file 1" >msgfile1 && |
351 | echo "message file 2" >msgfile2 && | |
352 | ! tag_exists msgtag && | |
d592b315 | 353 | test_must_fail git tag -m "message 1" -F msgfile1 msgtag && |
e317cfaf | 354 | ! tag_exists msgtag && |
d592b315 | 355 | test_must_fail git tag -F msgfile1 -m "message 1" msgtag && |
e317cfaf | 356 | ! tag_exists msgtag && |
d592b315 | 357 | test_must_fail git tag -m "message 1" -F msgfile1 \ |
d492b31c | 358 | -m "message 2" msgtag && |
e317cfaf CR |
359 | ! tag_exists msgtag |
360 | ' | |
361 | ||
ef5a6fb5 CR |
362 | # blank and empty messages: |
363 | ||
364 | get_tag_header empty-annotated-tag $commit commit $time >expect | |
365 | test_expect_success \ | |
366 | 'creating a tag with an empty -m message should succeed' ' | |
d592b315 | 367 | git tag -m "" empty-annotated-tag && |
ef5a6fb5 | 368 | get_tag_msg empty-annotated-tag >actual && |
3af82863 | 369 | test_cmp expect actual |
ef5a6fb5 CR |
370 | ' |
371 | ||
372 | >emptyfile | |
373 | get_tag_header emptyfile-annotated-tag $commit commit $time >expect | |
374 | test_expect_success \ | |
375 | 'creating a tag with an empty -F messagefile should succeed' ' | |
d592b315 | 376 | git tag -F emptyfile emptyfile-annotated-tag && |
ef5a6fb5 | 377 | get_tag_msg emptyfile-annotated-tag >actual && |
3af82863 | 378 | test_cmp expect actual |
ef5a6fb5 CR |
379 | ' |
380 | ||
381 | printf '\n\n \n\t\nLeading blank lines\n' >blanksfile | |
382 | printf '\n\t \t \nRepeated blank lines\n' >>blanksfile | |
383 | printf '\n\n\nTrailing spaces \t \n' >>blanksfile | |
384 | printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile | |
385 | get_tag_header blanks-annotated-tag $commit commit $time >expect | |
386 | cat >>expect <<EOF | |
387 | Leading blank lines | |
388 | ||
389 | Repeated blank lines | |
390 | ||
391 | Trailing spaces | |
392 | ||
393 | Trailing blank lines | |
394 | EOF | |
395 | test_expect_success \ | |
396 | 'extra blanks in the message for an annotated tag should be removed' ' | |
d592b315 | 397 | git tag -F blanksfile blanks-annotated-tag && |
ef5a6fb5 | 398 | get_tag_msg blanks-annotated-tag >actual && |
3af82863 | 399 | test_cmp expect actual |
ef5a6fb5 CR |
400 | ' |
401 | ||
402 | get_tag_header blank-annotated-tag $commit commit $time >expect | |
403 | test_expect_success \ | |
404 | 'creating a tag with blank -m message with spaces should succeed' ' | |
d592b315 | 405 | git tag -m " " blank-annotated-tag && |
ef5a6fb5 | 406 | get_tag_msg blank-annotated-tag >actual && |
3af82863 | 407 | test_cmp expect actual |
ef5a6fb5 CR |
408 | ' |
409 | ||
410 | echo ' ' >blankfile | |
411 | echo '' >>blankfile | |
412 | echo ' ' >>blankfile | |
413 | get_tag_header blankfile-annotated-tag $commit commit $time >expect | |
414 | test_expect_success \ | |
415 | 'creating a tag with blank -F messagefile with spaces should succeed' ' | |
d592b315 | 416 | git tag -F blankfile blankfile-annotated-tag && |
ef5a6fb5 | 417 | get_tag_msg blankfile-annotated-tag >actual && |
3af82863 | 418 | test_cmp expect actual |
ef5a6fb5 CR |
419 | ' |
420 | ||
421 | printf ' ' >blanknonlfile | |
422 | get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect | |
423 | test_expect_success \ | |
424 | 'creating a tag with -F file of spaces and no newline should succeed' ' | |
d592b315 | 425 | git tag -F blanknonlfile blanknonlfile-annotated-tag && |
ef5a6fb5 | 426 | get_tag_msg blanknonlfile-annotated-tag >actual && |
3af82863 | 427 | test_cmp expect actual |
ef5a6fb5 CR |
428 | ' |
429 | ||
430 | # messages with commented lines: | |
431 | ||
432 | cat >commentsfile <<EOF | |
433 | # A comment | |
434 | ||
435 | ############ | |
436 | The message. | |
437 | ############ | |
438 | One line. | |
439 | ||
440 | ||
441 | # commented lines | |
442 | # commented lines | |
443 | ||
444 | Another line. | |
445 | # comments | |
446 | ||
447 | Last line. | |
448 | EOF | |
449 | get_tag_header comments-annotated-tag $commit commit $time >expect | |
450 | cat >>expect <<EOF | |
451 | The message. | |
452 | One line. | |
453 | ||
454 | Another line. | |
455 | ||
456 | Last line. | |
457 | EOF | |
458 | test_expect_success \ | |
459 | 'creating a tag using a -F messagefile with #comments should succeed' ' | |
d592b315 | 460 | git tag -F commentsfile comments-annotated-tag && |
ef5a6fb5 | 461 | get_tag_msg comments-annotated-tag >actual && |
3af82863 | 462 | test_cmp expect actual |
ef5a6fb5 CR |
463 | ' |
464 | ||
465 | get_tag_header comment-annotated-tag $commit commit $time >expect | |
466 | test_expect_success \ | |
467 | 'creating a tag with a #comment in the -m message should succeed' ' | |
d592b315 | 468 | git tag -m "#comment" comment-annotated-tag && |
ef5a6fb5 | 469 | get_tag_msg comment-annotated-tag >actual && |
3af82863 | 470 | test_cmp expect actual |
ef5a6fb5 CR |
471 | ' |
472 | ||
473 | echo '#comment' >commentfile | |
474 | echo '' >>commentfile | |
475 | echo '####' >>commentfile | |
476 | get_tag_header commentfile-annotated-tag $commit commit $time >expect | |
477 | test_expect_success \ | |
478 | 'creating a tag with #comments in the -F messagefile should succeed' ' | |
d592b315 | 479 | git tag -F commentfile commentfile-annotated-tag && |
ef5a6fb5 | 480 | get_tag_msg commentfile-annotated-tag >actual && |
3af82863 | 481 | test_cmp expect actual |
ef5a6fb5 CR |
482 | ' |
483 | ||
484 | printf '#comment' >commentnonlfile | |
485 | get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect | |
486 | test_expect_success \ | |
487 | 'creating a tag with a file of #comment and no newline should succeed' ' | |
d592b315 | 488 | git tag -F commentnonlfile commentnonlfile-annotated-tag && |
ef5a6fb5 | 489 | get_tag_msg commentnonlfile-annotated-tag >actual && |
3af82863 | 490 | test_cmp expect actual |
ef5a6fb5 CR |
491 | ' |
492 | ||
5206d130 CR |
493 | # listing messages for annotated non-signed tags: |
494 | ||
495 | test_expect_success \ | |
496 | 'listing the one-line message of a non-signed tag should succeed' ' | |
d592b315 | 497 | git tag -m "A msg" tag-one-line && |
5206d130 CR |
498 | |
499 | echo "tag-one-line" >expect && | |
d592b315 | 500 | git tag -l | grep "^tag-one-line" >actual && |
3af82863 | 501 | test_cmp expect actual && |
d592b315 | 502 | git tag -n0 -l | grep "^tag-one-line" >actual && |
3af82863 | 503 | test_cmp expect actual && |
d592b315 | 504 | git tag -n0 -l tag-one-line >actual && |
3af82863 | 505 | test_cmp expect actual && |
5206d130 CR |
506 | |
507 | echo "tag-one-line A msg" >expect && | |
d592b315 | 508 | git tag -n1 -l | grep "^tag-one-line" >actual && |
3af82863 | 509 | test_cmp expect actual && |
d592b315 | 510 | git tag -n -l | grep "^tag-one-line" >actual && |
3af82863 | 511 | test_cmp expect actual && |
d592b315 | 512 | git tag -n1 -l tag-one-line >actual && |
3af82863 | 513 | test_cmp expect actual && |
d592b315 | 514 | git tag -n2 -l tag-one-line >actual && |
3af82863 | 515 | test_cmp expect actual && |
d592b315 | 516 | git tag -n999 -l tag-one-line >actual && |
3af82863 | 517 | test_cmp expect actual |
5206d130 CR |
518 | ' |
519 | ||
520 | test_expect_success \ | |
521 | 'listing the zero-lines message of a non-signed tag should succeed' ' | |
d592b315 | 522 | git tag -m "" tag-zero-lines && |
5206d130 CR |
523 | |
524 | echo "tag-zero-lines" >expect && | |
d592b315 | 525 | git tag -l | grep "^tag-zero-lines" >actual && |
3af82863 | 526 | test_cmp expect actual && |
d592b315 | 527 | git tag -n0 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 528 | test_cmp expect actual && |
d592b315 | 529 | git tag -n0 -l tag-zero-lines >actual && |
3af82863 | 530 | test_cmp expect actual && |
5206d130 CR |
531 | |
532 | echo "tag-zero-lines " >expect && | |
d592b315 | 533 | git tag -n1 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 534 | test_cmp expect actual && |
d592b315 | 535 | git tag -n -l | grep "^tag-zero-lines" >actual && |
3af82863 | 536 | test_cmp expect actual && |
d592b315 | 537 | git tag -n1 -l tag-zero-lines >actual && |
3af82863 | 538 | test_cmp expect actual && |
d592b315 | 539 | git tag -n2 -l tag-zero-lines >actual && |
3af82863 | 540 | test_cmp expect actual && |
d592b315 | 541 | git tag -n999 -l tag-zero-lines >actual && |
3af82863 | 542 | test_cmp expect actual |
5206d130 CR |
543 | ' |
544 | ||
545 | echo 'tag line one' >annotagmsg | |
546 | echo 'tag line two' >>annotagmsg | |
547 | echo 'tag line three' >>annotagmsg | |
548 | test_expect_success \ | |
549 | 'listing many message lines of a non-signed tag should succeed' ' | |
d592b315 | 550 | git tag -F annotagmsg tag-lines && |
5206d130 CR |
551 | |
552 | echo "tag-lines" >expect && | |
d592b315 | 553 | git tag -l | grep "^tag-lines" >actual && |
3af82863 | 554 | test_cmp expect actual && |
d592b315 | 555 | git tag -n0 -l | grep "^tag-lines" >actual && |
3af82863 | 556 | test_cmp expect actual && |
d592b315 | 557 | git tag -n0 -l tag-lines >actual && |
3af82863 | 558 | test_cmp expect actual && |
5206d130 CR |
559 | |
560 | echo "tag-lines tag line one" >expect && | |
d592b315 | 561 | git tag -n1 -l | grep "^tag-lines" >actual && |
3af82863 | 562 | test_cmp expect actual && |
d592b315 | 563 | git tag -n -l | grep "^tag-lines" >actual && |
3af82863 | 564 | test_cmp expect actual && |
d592b315 | 565 | git tag -n1 -l tag-lines >actual && |
3af82863 | 566 | test_cmp expect actual && |
5206d130 CR |
567 | |
568 | echo " tag line two" >>expect && | |
d592b315 | 569 | git tag -n2 -l | grep "^ *tag.line" >actual && |
3af82863 | 570 | test_cmp expect actual && |
d592b315 | 571 | git tag -n2 -l tag-lines >actual && |
3af82863 | 572 | test_cmp expect actual && |
5206d130 CR |
573 | |
574 | echo " tag line three" >>expect && | |
d592b315 | 575 | git tag -n3 -l | grep "^ *tag.line" >actual && |
3af82863 | 576 | test_cmp expect actual && |
d592b315 | 577 | git tag -n3 -l tag-lines >actual && |
3af82863 | 578 | test_cmp expect actual && |
d592b315 | 579 | git tag -n4 -l | grep "^ *tag.line" >actual && |
3af82863 | 580 | test_cmp expect actual && |
d592b315 | 581 | git tag -n4 -l tag-lines >actual && |
3af82863 | 582 | test_cmp expect actual && |
d592b315 | 583 | git tag -n99 -l | grep "^ *tag.line" >actual && |
3af82863 | 584 | test_cmp expect actual && |
d592b315 | 585 | git tag -n99 -l tag-lines >actual && |
3af82863 | 586 | test_cmp expect actual |
5206d130 CR |
587 | ' |
588 | ||
ef5a6fb5 CR |
589 | # trying to verify annotated non-signed tags: |
590 | ||
a4df22ce | 591 | test_expect_success GPG \ |
ef5a6fb5 CR |
592 | 'trying to verify an annotated non-signed tag should fail' ' |
593 | tag_exists annotated-tag && | |
d592b315 | 594 | test_must_fail git tag -v annotated-tag |
ef5a6fb5 CR |
595 | ' |
596 | ||
a4df22ce | 597 | test_expect_success GPG \ |
ef5a6fb5 CR |
598 | 'trying to verify a file-annotated non-signed tag should fail' ' |
599 | tag_exists file-annotated-tag && | |
d592b315 | 600 | test_must_fail git tag -v file-annotated-tag |
ef5a6fb5 CR |
601 | ' |
602 | ||
a4df22ce | 603 | test_expect_success GPG \ |
62e09ce9 CR |
604 | 'trying to verify two annotated non-signed tags should fail' ' |
605 | tag_exists annotated-tag file-annotated-tag && | |
d592b315 | 606 | test_must_fail git tag -v annotated-tag file-annotated-tag |
62e09ce9 CR |
607 | ' |
608 | ||
ef5a6fb5 CR |
609 | # creating and verifying signed tags: |
610 | ||
ef5a6fb5 CR |
611 | get_tag_header signed-tag $commit commit $time >expect |
612 | echo 'A signed tag message' >>expect | |
613 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 614 | test_expect_success GPG 'creating a signed tag with -m message should succeed' ' |
d592b315 | 615 | git tag -s -m "A signed tag message" signed-tag && |
ef5a6fb5 | 616 | get_tag_msg signed-tag >actual && |
3af82863 | 617 | test_cmp expect actual |
ef5a6fb5 CR |
618 | ' |
619 | ||
be15f505 LT |
620 | get_tag_header u-signed-tag $commit commit $time >expect |
621 | echo 'Another message' >>expect | |
622 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 623 | test_expect_success GPG 'sign with a given key id' ' |
be15f505 LT |
624 | |
625 | git tag -u committer@example.com -m "Another message" u-signed-tag && | |
626 | get_tag_msg u-signed-tag >actual && | |
3af82863 | 627 | test_cmp expect actual |
be15f505 LT |
628 | |
629 | ' | |
630 | ||
a4df22ce | 631 | test_expect_success GPG 'sign with an unknown id (1)' ' |
be15f505 | 632 | |
d492b31c SB |
633 | test_must_fail git tag -u author@example.com \ |
634 | -m "Another message" o-signed-tag | |
be15f505 LT |
635 | |
636 | ' | |
637 | ||
a4df22ce | 638 | test_expect_success GPG 'sign with an unknown id (2)' ' |
be15f505 | 639 | |
d492b31c | 640 | test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag |
be15f505 LT |
641 | |
642 | ' | |
643 | ||
644 | cat >fakeeditor <<'EOF' | |
645 | #!/bin/sh | |
646 | test -n "$1" && exec >"$1" | |
647 | echo A signed tag message | |
648 | echo from a fake editor. | |
649 | EOF | |
650 | chmod +x fakeeditor | |
651 | ||
652 | get_tag_header implied-sign $commit commit $time >expect | |
653 | ./fakeeditor >>expect | |
654 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 655 | test_expect_success GPG '-u implies signed tag' ' |
d592b315 | 656 | GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && |
be15f505 | 657 | get_tag_msg implied-sign >actual && |
3af82863 | 658 | test_cmp expect actual |
be15f505 LT |
659 | ' |
660 | ||
62e09ce9 CR |
661 | cat >sigmsgfile <<EOF |
662 | Another signed tag | |
663 | message in a file. | |
664 | EOF | |
665 | get_tag_header file-signed-tag $commit commit $time >expect | |
666 | cat sigmsgfile >>expect | |
667 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 668 | test_expect_success GPG \ |
62e09ce9 | 669 | 'creating a signed tag with -F messagefile should succeed' ' |
d592b315 | 670 | git tag -s -F sigmsgfile file-signed-tag && |
62e09ce9 | 671 | get_tag_msg file-signed-tag >actual && |
3af82863 | 672 | test_cmp expect actual |
62e09ce9 CR |
673 | ' |
674 | ||
675 | cat >siginputmsg <<EOF | |
676 | A signed tag message from | |
677 | the standard input | |
678 | EOF | |
679 | get_tag_header stdin-signed-tag $commit commit $time >expect | |
680 | cat siginputmsg >>expect | |
681 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 682 | test_expect_success GPG 'creating a signed tag with -F - should succeed' ' |
d592b315 | 683 | git tag -s -F - stdin-signed-tag <siginputmsg && |
62e09ce9 | 684 | get_tag_msg stdin-signed-tag >actual && |
3af82863 | 685 | test_cmp expect actual |
62e09ce9 CR |
686 | ' |
687 | ||
10507857 JK |
688 | get_tag_header implied-annotate $commit commit $time >expect |
689 | ./fakeeditor >>expect | |
690 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 691 | test_expect_success GPG '-s implies annotated tag' ' |
d592b315 | 692 | GIT_EDITOR=./fakeeditor git tag -s implied-annotate && |
10507857 | 693 | get_tag_msg implied-annotate >actual && |
3af82863 | 694 | test_cmp expect actual |
10507857 JK |
695 | ' |
696 | ||
a4df22ce | 697 | test_expect_success GPG \ |
e317cfaf CR |
698 | 'trying to create a signed tag with non-existing -F file should fail' ' |
699 | ! test -f nonexistingfile && | |
700 | ! tag_exists nosigtag && | |
d592b315 | 701 | test_must_fail git tag -s -F nonexistingfile nosigtag && |
e317cfaf CR |
702 | ! tag_exists nosigtag |
703 | ' | |
704 | ||
a4df22ce | 705 | test_expect_success GPG 'verifying a signed tag should succeed' \ |
d592b315 | 706 | 'git tag -v signed-tag' |
ef5a6fb5 | 707 | |
a4df22ce | 708 | test_expect_success GPG 'verifying two signed tags in one command should succeed' \ |
d592b315 | 709 | 'git tag -v signed-tag file-signed-tag' |
62e09ce9 | 710 | |
a4df22ce | 711 | test_expect_success GPG \ |
62e09ce9 | 712 | 'verifying many signed and non-signed tags should fail' ' |
d592b315 NS |
713 | test_must_fail git tag -v signed-tag annotated-tag && |
714 | test_must_fail git tag -v file-annotated-tag file-signed-tag && | |
715 | test_must_fail git tag -v annotated-tag \ | |
d492b31c | 716 | file-signed-tag file-annotated-tag && |
d592b315 | 717 | test_must_fail git tag -v signed-tag annotated-tag file-signed-tag |
62e09ce9 CR |
718 | ' |
719 | ||
a4df22ce | 720 | test_expect_success GPG 'verifying a forged tag should fail' ' |
ef5a6fb5 CR |
721 | forged=$(git cat-file tag signed-tag | |
722 | sed -e "s/signed-tag/forged-tag/" | | |
723 | git mktag) && | |
724 | git tag forged-tag $forged && | |
d592b315 | 725 | test_must_fail git tag -v forged-tag |
ef5a6fb5 CR |
726 | ' |
727 | ||
728 | # blank and empty messages for signed tags: | |
729 | ||
730 | get_tag_header empty-signed-tag $commit commit $time >expect | |
731 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 732 | test_expect_success GPG \ |
ef5a6fb5 | 733 | 'creating a signed tag with an empty -m message should succeed' ' |
d592b315 | 734 | git tag -s -m "" empty-signed-tag && |
ef5a6fb5 | 735 | get_tag_msg empty-signed-tag >actual && |
3af82863 | 736 | test_cmp expect actual && |
d592b315 | 737 | git tag -v empty-signed-tag |
ef5a6fb5 CR |
738 | ' |
739 | ||
740 | >sigemptyfile | |
741 | get_tag_header emptyfile-signed-tag $commit commit $time >expect | |
742 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 743 | test_expect_success GPG \ |
ef5a6fb5 | 744 | 'creating a signed tag with an empty -F messagefile should succeed' ' |
d592b315 | 745 | git tag -s -F sigemptyfile emptyfile-signed-tag && |
ef5a6fb5 | 746 | get_tag_msg emptyfile-signed-tag >actual && |
3af82863 | 747 | test_cmp expect actual && |
d592b315 | 748 | git tag -v emptyfile-signed-tag |
ef5a6fb5 CR |
749 | ' |
750 | ||
751 | printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile | |
752 | printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile | |
753 | printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile | |
754 | printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile | |
755 | get_tag_header blanks-signed-tag $commit commit $time >expect | |
756 | cat >>expect <<EOF | |
757 | Leading blank lines | |
758 | ||
759 | Repeated blank lines | |
760 | ||
761 | Trailing spaces | |
762 | ||
763 | Trailing blank lines | |
764 | EOF | |
765 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 766 | test_expect_success GPG \ |
ef5a6fb5 | 767 | 'extra blanks in the message for a signed tag should be removed' ' |
d592b315 | 768 | git tag -s -F sigblanksfile blanks-signed-tag && |
ef5a6fb5 | 769 | get_tag_msg blanks-signed-tag >actual && |
3af82863 | 770 | test_cmp expect actual && |
d592b315 | 771 | git tag -v blanks-signed-tag |
ef5a6fb5 CR |
772 | ' |
773 | ||
774 | get_tag_header blank-signed-tag $commit commit $time >expect | |
775 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 776 | test_expect_success GPG \ |
ef5a6fb5 | 777 | 'creating a signed tag with a blank -m message should succeed' ' |
d592b315 | 778 | git tag -s -m " " blank-signed-tag && |
ef5a6fb5 | 779 | get_tag_msg blank-signed-tag >actual && |
3af82863 | 780 | test_cmp expect actual && |
d592b315 | 781 | git tag -v blank-signed-tag |
ef5a6fb5 CR |
782 | ' |
783 | ||
784 | echo ' ' >sigblankfile | |
785 | echo '' >>sigblankfile | |
786 | echo ' ' >>sigblankfile | |
787 | get_tag_header blankfile-signed-tag $commit commit $time >expect | |
788 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 789 | test_expect_success GPG \ |
ef5a6fb5 | 790 | 'creating a signed tag with blank -F file with spaces should succeed' ' |
d592b315 | 791 | git tag -s -F sigblankfile blankfile-signed-tag && |
ef5a6fb5 | 792 | get_tag_msg blankfile-signed-tag >actual && |
3af82863 | 793 | test_cmp expect actual && |
d592b315 | 794 | git tag -v blankfile-signed-tag |
ef5a6fb5 CR |
795 | ' |
796 | ||
797 | printf ' ' >sigblanknonlfile | |
798 | get_tag_header blanknonlfile-signed-tag $commit commit $time >expect | |
799 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 800 | test_expect_success GPG \ |
ef5a6fb5 | 801 | 'creating a signed tag with spaces and no newline should succeed' ' |
d592b315 | 802 | git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && |
ef5a6fb5 | 803 | get_tag_msg blanknonlfile-signed-tag >actual && |
3af82863 | 804 | test_cmp expect actual && |
d592b315 | 805 | git tag -v signed-tag |
ef5a6fb5 CR |
806 | ' |
807 | ||
808 | # messages with commented lines for signed tags: | |
809 | ||
810 | cat >sigcommentsfile <<EOF | |
811 | # A comment | |
812 | ||
813 | ############ | |
814 | The message. | |
815 | ############ | |
816 | One line. | |
817 | ||
818 | ||
819 | # commented lines | |
820 | # commented lines | |
821 | ||
822 | Another line. | |
823 | # comments | |
824 | ||
825 | Last line. | |
826 | EOF | |
827 | get_tag_header comments-signed-tag $commit commit $time >expect | |
828 | cat >>expect <<EOF | |
829 | The message. | |
830 | One line. | |
831 | ||
832 | Another line. | |
833 | ||
834 | Last line. | |
835 | EOF | |
836 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 837 | test_expect_success GPG \ |
ef5a6fb5 | 838 | 'creating a signed tag with a -F file with #comments should succeed' ' |
d592b315 | 839 | git tag -s -F sigcommentsfile comments-signed-tag && |
ef5a6fb5 | 840 | get_tag_msg comments-signed-tag >actual && |
3af82863 | 841 | test_cmp expect actual && |
d592b315 | 842 | git tag -v comments-signed-tag |
ef5a6fb5 CR |
843 | ' |
844 | ||
845 | get_tag_header comment-signed-tag $commit commit $time >expect | |
846 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 847 | test_expect_success GPG \ |
ef5a6fb5 | 848 | 'creating a signed tag with #commented -m message should succeed' ' |
d592b315 | 849 | git tag -s -m "#comment" comment-signed-tag && |
ef5a6fb5 | 850 | get_tag_msg comment-signed-tag >actual && |
3af82863 | 851 | test_cmp expect actual && |
d592b315 | 852 | git tag -v comment-signed-tag |
ef5a6fb5 CR |
853 | ' |
854 | ||
855 | echo '#comment' >sigcommentfile | |
856 | echo '' >>sigcommentfile | |
857 | echo '####' >>sigcommentfile | |
858 | get_tag_header commentfile-signed-tag $commit commit $time >expect | |
859 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 860 | test_expect_success GPG \ |
ef5a6fb5 | 861 | 'creating a signed tag with #commented -F messagefile should succeed' ' |
d592b315 | 862 | git tag -s -F sigcommentfile commentfile-signed-tag && |
ef5a6fb5 | 863 | get_tag_msg commentfile-signed-tag >actual && |
3af82863 | 864 | test_cmp expect actual && |
d592b315 | 865 | git tag -v commentfile-signed-tag |
ef5a6fb5 CR |
866 | ' |
867 | ||
868 | printf '#comment' >sigcommentnonlfile | |
869 | get_tag_header commentnonlfile-signed-tag $commit commit $time >expect | |
870 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 871 | test_expect_success GPG \ |
ef5a6fb5 | 872 | 'creating a signed tag with a #comment and no newline should succeed' ' |
d592b315 | 873 | git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && |
ef5a6fb5 | 874 | get_tag_msg commentnonlfile-signed-tag >actual && |
3af82863 | 875 | test_cmp expect actual && |
d592b315 | 876 | git tag -v commentnonlfile-signed-tag |
ef5a6fb5 CR |
877 | ' |
878 | ||
5206d130 CR |
879 | # listing messages for signed tags: |
880 | ||
a4df22ce | 881 | test_expect_success GPG \ |
5206d130 | 882 | 'listing the one-line message of a signed tag should succeed' ' |
d592b315 | 883 | git tag -s -m "A message line signed" stag-one-line && |
5206d130 CR |
884 | |
885 | echo "stag-one-line" >expect && | |
d592b315 | 886 | git tag -l | grep "^stag-one-line" >actual && |
3af82863 | 887 | test_cmp expect actual && |
d592b315 | 888 | git tag -n0 -l | grep "^stag-one-line" >actual && |
3af82863 | 889 | test_cmp expect actual && |
d592b315 | 890 | git tag -n0 -l stag-one-line >actual && |
3af82863 | 891 | test_cmp expect actual && |
5206d130 CR |
892 | |
893 | echo "stag-one-line A message line signed" >expect && | |
d592b315 | 894 | git tag -n1 -l | grep "^stag-one-line" >actual && |
3af82863 | 895 | test_cmp expect actual && |
d592b315 | 896 | git tag -n -l | grep "^stag-one-line" >actual && |
3af82863 | 897 | test_cmp expect actual && |
d592b315 | 898 | git tag -n1 -l stag-one-line >actual && |
3af82863 | 899 | test_cmp expect actual && |
d592b315 | 900 | git tag -n2 -l stag-one-line >actual && |
3af82863 | 901 | test_cmp expect actual && |
d592b315 | 902 | git tag -n999 -l stag-one-line >actual && |
3af82863 | 903 | test_cmp expect actual |
5206d130 CR |
904 | ' |
905 | ||
a4df22ce | 906 | test_expect_success GPG \ |
5206d130 | 907 | 'listing the zero-lines message of a signed tag should succeed' ' |
d592b315 | 908 | git tag -s -m "" stag-zero-lines && |
5206d130 CR |
909 | |
910 | echo "stag-zero-lines" >expect && | |
d592b315 | 911 | git tag -l | grep "^stag-zero-lines" >actual && |
3af82863 | 912 | test_cmp expect actual && |
d592b315 | 913 | git tag -n0 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 914 | test_cmp expect actual && |
d592b315 | 915 | git tag -n0 -l stag-zero-lines >actual && |
3af82863 | 916 | test_cmp expect actual && |
5206d130 CR |
917 | |
918 | echo "stag-zero-lines " >expect && | |
d592b315 | 919 | git tag -n1 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 920 | test_cmp expect actual && |
d592b315 | 921 | git tag -n -l | grep "^stag-zero-lines" >actual && |
3af82863 | 922 | test_cmp expect actual && |
d592b315 | 923 | git tag -n1 -l stag-zero-lines >actual && |
3af82863 | 924 | test_cmp expect actual && |
d592b315 | 925 | git tag -n2 -l stag-zero-lines >actual && |
3af82863 | 926 | test_cmp expect actual && |
d592b315 | 927 | git tag -n999 -l stag-zero-lines >actual && |
3af82863 | 928 | test_cmp expect actual |
5206d130 CR |
929 | ' |
930 | ||
931 | echo 'stag line one' >sigtagmsg | |
932 | echo 'stag line two' >>sigtagmsg | |
933 | echo 'stag line three' >>sigtagmsg | |
a4df22ce | 934 | test_expect_success GPG \ |
5206d130 | 935 | 'listing many message lines of a signed tag should succeed' ' |
d592b315 | 936 | git tag -s -F sigtagmsg stag-lines && |
5206d130 CR |
937 | |
938 | echo "stag-lines" >expect && | |
d592b315 | 939 | git tag -l | grep "^stag-lines" >actual && |
3af82863 | 940 | test_cmp expect actual && |
d592b315 | 941 | git tag -n0 -l | grep "^stag-lines" >actual && |
3af82863 | 942 | test_cmp expect actual && |
d592b315 | 943 | git tag -n0 -l stag-lines >actual && |
3af82863 | 944 | test_cmp expect actual && |
5206d130 CR |
945 | |
946 | echo "stag-lines stag line one" >expect && | |
d592b315 | 947 | git tag -n1 -l | grep "^stag-lines" >actual && |
3af82863 | 948 | test_cmp expect actual && |
d592b315 | 949 | git tag -n -l | grep "^stag-lines" >actual && |
3af82863 | 950 | test_cmp expect actual && |
d592b315 | 951 | git tag -n1 -l stag-lines >actual && |
3af82863 | 952 | test_cmp expect actual && |
5206d130 CR |
953 | |
954 | echo " stag line two" >>expect && | |
d592b315 | 955 | git tag -n2 -l | grep "^ *stag.line" >actual && |
3af82863 | 956 | test_cmp expect actual && |
d592b315 | 957 | git tag -n2 -l stag-lines >actual && |
3af82863 | 958 | test_cmp expect actual && |
5206d130 CR |
959 | |
960 | echo " stag line three" >>expect && | |
d592b315 | 961 | git tag -n3 -l | grep "^ *stag.line" >actual && |
3af82863 | 962 | test_cmp expect actual && |
d592b315 | 963 | git tag -n3 -l stag-lines >actual && |
3af82863 | 964 | test_cmp expect actual && |
d592b315 | 965 | git tag -n4 -l | grep "^ *stag.line" >actual && |
3af82863 | 966 | test_cmp expect actual && |
d592b315 | 967 | git tag -n4 -l stag-lines >actual && |
3af82863 | 968 | test_cmp expect actual && |
d592b315 | 969 | git tag -n99 -l | grep "^ *stag.line" >actual && |
3af82863 | 970 | test_cmp expect actual && |
d592b315 | 971 | git tag -n99 -l stag-lines >actual && |
3af82863 | 972 | test_cmp expect actual |
5206d130 CR |
973 | ' |
974 | ||
ef5a6fb5 CR |
975 | # tags pointing to objects different from commits: |
976 | ||
977 | tree=$(git rev-parse HEAD^{tree}) | |
978 | blob=$(git rev-parse HEAD:foo) | |
a4df22ce | 979 | tag=$(git rev-parse signed-tag 2>/dev/null) |
ef5a6fb5 CR |
980 | |
981 | get_tag_header tree-signed-tag $tree tree $time >expect | |
982 | echo "A message for a tree" >>expect | |
983 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 984 | test_expect_success GPG \ |
ef5a6fb5 | 985 | 'creating a signed tag pointing to a tree should succeed' ' |
d592b315 | 986 | git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && |
ef5a6fb5 | 987 | get_tag_msg tree-signed-tag >actual && |
3af82863 | 988 | test_cmp expect actual |
ef5a6fb5 CR |
989 | ' |
990 | ||
991 | get_tag_header blob-signed-tag $blob blob $time >expect | |
992 | echo "A message for a blob" >>expect | |
993 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 994 | test_expect_success GPG \ |
ef5a6fb5 | 995 | 'creating a signed tag pointing to a blob should succeed' ' |
d592b315 | 996 | git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && |
ef5a6fb5 | 997 | get_tag_msg blob-signed-tag >actual && |
3af82863 | 998 | test_cmp expect actual |
ef5a6fb5 CR |
999 | ' |
1000 | ||
1001 | get_tag_header tag-signed-tag $tag tag $time >expect | |
1002 | echo "A message for another tag" >>expect | |
1003 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1004 | test_expect_success GPG \ |
ef5a6fb5 | 1005 | 'creating a signed tag pointing to another tag should succeed' ' |
d592b315 | 1006 | git tag -s -m "A message for another tag" tag-signed-tag signed-tag && |
ef5a6fb5 | 1007 | get_tag_msg tag-signed-tag >actual && |
3af82863 | 1008 | test_cmp expect actual |
ef5a6fb5 CR |
1009 | ' |
1010 | ||
c8525c30 MG |
1011 | # usage with rfc1991 signatures |
1012 | echo "rfc1991" > gpghome/gpg.conf | |
1013 | get_tag_header rfc1991-signed-tag $commit commit $time >expect | |
1014 | echo "RFC1991 signed tag" >>expect | |
1015 | echo '-----BEGIN PGP MESSAGE-----' >>expect | |
1016 | test_expect_success GPG \ | |
1017 | 'creating a signed tag with rfc1991' ' | |
1018 | git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && | |
1019 | get_tag_msg rfc1991-signed-tag >actual && | |
1020 | test_cmp expect actual | |
1021 | ' | |
1022 | ||
1023 | cat >fakeeditor <<'EOF' | |
1024 | #!/bin/sh | |
1025 | cp "$1" actual | |
1026 | EOF | |
1027 | chmod +x fakeeditor | |
1028 | ||
3d5854e7 | 1029 | test_expect_success GPG \ |
c8525c30 MG |
1030 | 'reediting a signed tag body omits signature' ' |
1031 | echo "RFC1991 signed tag" >expect && | |
1032 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1033 | test_cmp expect actual | |
1034 | ' | |
1035 | ||
3d5854e7 | 1036 | test_expect_success GPG \ |
c8525c30 MG |
1037 | 'verifying rfc1991 signature' ' |
1038 | git tag -v rfc1991-signed-tag | |
1039 | ' | |
1040 | ||
3d5854e7 | 1041 | test_expect_success GPG \ |
c8525c30 MG |
1042 | 'list tag with rfc1991 signature' ' |
1043 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && | |
1044 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1045 | test_cmp expect actual && | |
1046 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1047 | test_cmp expect actual && | |
1048 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1049 | test_cmp expect actual | |
1050 | ' | |
1051 | ||
1052 | rm -f gpghome/gpg.conf | |
1053 | ||
3d5854e7 | 1054 | test_expect_success GPG \ |
c8525c30 MG |
1055 | 'verifying rfc1991 signature without --rfc1991' ' |
1056 | git tag -v rfc1991-signed-tag | |
1057 | ' | |
1058 | ||
3d5854e7 | 1059 | test_expect_success GPG \ |
c8525c30 MG |
1060 | 'list tag with rfc1991 signature without --rfc1991' ' |
1061 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && | |
1062 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1063 | test_cmp expect actual && | |
1064 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1065 | test_cmp expect actual && | |
1066 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1067 | test_cmp expect actual | |
1068 | ' | |
1069 | ||
3d5854e7 | 1070 | test_expect_success GPG \ |
c8525c30 MG |
1071 | 'reediting a signed tag body omits signature' ' |
1072 | echo "RFC1991 signed tag" >expect && | |
1073 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1074 | test_cmp expect actual | |
1075 | ' | |
1076 | ||
aba91192 CR |
1077 | # try to sign with bad user.signingkey |
1078 | git config user.signingkey BobTheMouse | |
a4df22ce | 1079 | test_expect_success GPG \ |
d592b315 | 1080 | 'git tag -s fails if gpg is misconfigured' \ |
d492b31c | 1081 | 'test_must_fail git tag -s -m tail tag-gpg-failure' |
aba91192 CR |
1082 | git config --unset user.signingkey |
1083 | ||
ef5a6fb5 CR |
1084 | # try to verify without gpg: |
1085 | ||
1086 | rm -rf gpghome | |
a4df22ce | 1087 | test_expect_success GPG \ |
ef5a6fb5 | 1088 | 'verify signed tag fails when public key is not present' \ |
d592b315 | 1089 | 'test_must_fail git tag -v signed-tag' |
ef5a6fb5 | 1090 | |
41ac414e | 1091 | test_expect_success \ |
d592b315 | 1092 | 'git tag -a fails if tag annotation is empty' ' |
41ac414e | 1093 | ! (GIT_EDITOR=cat git tag -a initial-comment) |
eb9d2b91 MH |
1094 | ' |
1095 | ||
4d8b1dc8 MH |
1096 | test_expect_success \ |
1097 | 'message in editor has initial comment' ' | |
5649bd9a ÆAB |
1098 | ! (GIT_EDITOR=cat git tag -a initial-comment > actual) |
1099 | ' | |
1100 | ||
b3e1900a | 1101 | test_expect_success 'message in editor has initial comment: first line' ' |
eb9d2b91 | 1102 | # check the first line --- should be empty |
5649bd9a ÆAB |
1103 | echo >first.expect && |
1104 | sed -e 1q <actual >first.actual && | |
b3e1900a | 1105 | test_i18ncmp first.expect first.actual |
5649bd9a ÆAB |
1106 | ' |
1107 | ||
1108 | test_expect_success \ | |
1109 | 'message in editor has initial comment: remainder' ' | |
eb9d2b91 | 1110 | # remove commented lines from the remainder -- should be empty |
5649bd9a ÆAB |
1111 | >rest.expect |
1112 | sed -e 1d -e '/^#/d' <actual >rest.actual && | |
1113 | test_cmp rest.expect rest.actual | |
4d8b1dc8 MH |
1114 | ' |
1115 | ||
1116 | get_tag_header reuse $commit commit $time >expect | |
1117 | echo "An annotation to be reused" >> expect | |
1118 | test_expect_success \ | |
1119 | 'overwriting an annoted tag should use its previous body' ' | |
1120 | git tag -a -m "An annotation to be reused" reuse && | |
1121 | GIT_EDITOR=true git tag -f -a reuse && | |
1122 | get_tag_msg reuse >actual && | |
3af82863 | 1123 | test_cmp expect actual |
4d8b1dc8 MH |
1124 | ' |
1125 | ||
dbd0f5c7 JH |
1126 | test_expect_success 'filename for the message is relative to cwd' ' |
1127 | mkdir subdir && | |
1128 | echo "Tag message in top directory" >msgfile-5 && | |
1129 | echo "Tag message in sub directory" >subdir/msgfile-5 && | |
1130 | ( | |
1131 | cd subdir && | |
1132 | git tag -a -F msgfile-5 tag-from-subdir | |
1133 | ) && | |
1134 | git cat-file tag tag-from-subdir | grep "in sub directory" | |
1135 | ' | |
1136 | ||
1137 | test_expect_success 'filename for the message is relative to cwd' ' | |
1138 | echo "Tag message in sub directory" >subdir/msgfile-6 && | |
1139 | ( | |
1140 | cd subdir && | |
1141 | git tag -a -F msgfile-6 tag-from-subdir-2 | |
1142 | ) && | |
1143 | git cat-file tag tag-from-subdir-2 | grep "in sub directory" | |
1144 | ' | |
1145 | ||
32c35cfb JG |
1146 | # create a few more commits to test --contains |
1147 | ||
1148 | hash1=$(git rev-parse HEAD) | |
1149 | ||
1150 | test_expect_success 'creating second commit and tag' ' | |
1151 | echo foo-2.0 >foo && | |
1152 | git add foo && | |
2dec68cf | 1153 | git commit -m second && |
32c35cfb JG |
1154 | git tag v2.0 |
1155 | ' | |
1156 | ||
1157 | hash2=$(git rev-parse HEAD) | |
1158 | ||
1159 | test_expect_success 'creating third commit without tag' ' | |
1160 | echo foo-dev >foo && | |
1161 | git add foo && | |
1162 | git commit -m third | |
1163 | ' | |
1164 | ||
1165 | hash3=$(git rev-parse HEAD) | |
1166 | ||
1167 | # simple linear checks of --continue | |
1168 | ||
1169 | cat > expected <<EOF | |
1170 | v0.2.1 | |
1171 | v1.0 | |
1172 | v1.0.1 | |
1173 | v1.1.3 | |
1174 | v2.0 | |
1175 | EOF | |
1176 | ||
1177 | test_expect_success 'checking that first commit is in all tags (hash)' " | |
2dec68cf | 1178 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1179 | test_cmp expected actual |
1180 | " | |
1181 | ||
1182 | # other ways of specifying the commit | |
1183 | test_expect_success 'checking that first commit is in all tags (tag)' " | |
2dec68cf | 1184 | git tag -l --contains v1.0 v* >actual && |
32c35cfb JG |
1185 | test_cmp expected actual |
1186 | " | |
1187 | ||
1188 | test_expect_success 'checking that first commit is in all tags (relative)' " | |
2dec68cf | 1189 | git tag -l --contains HEAD~2 v* >actual && |
32c35cfb JG |
1190 | test_cmp expected actual |
1191 | " | |
1192 | ||
1193 | cat > expected <<EOF | |
1194 | v2.0 | |
1195 | EOF | |
1196 | ||
1197 | test_expect_success 'checking that second commit only has one tag' " | |
2dec68cf | 1198 | git tag -l --contains $hash2 v* >actual && |
32c35cfb JG |
1199 | test_cmp expected actual |
1200 | " | |
1201 | ||
1202 | ||
1203 | cat > expected <<EOF | |
1204 | EOF | |
1205 | ||
1206 | test_expect_success 'checking that third commit has no tags' " | |
2dec68cf | 1207 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1208 | test_cmp expected actual |
1209 | " | |
1210 | ||
1211 | # how about a simple merge? | |
1212 | ||
1213 | test_expect_success 'creating simple branch' ' | |
1214 | git branch stable v2.0 && | |
1215 | git checkout stable && | |
1216 | echo foo-3.0 > foo && | |
2dec68cf | 1217 | git commit foo -m fourth && |
32c35cfb JG |
1218 | git tag v3.0 |
1219 | ' | |
1220 | ||
1221 | hash4=$(git rev-parse HEAD) | |
1222 | ||
1223 | cat > expected <<EOF | |
1224 | v3.0 | |
1225 | EOF | |
1226 | ||
1227 | test_expect_success 'checking that branch head only has one tag' " | |
2dec68cf | 1228 | git tag -l --contains $hash4 v* >actual && |
32c35cfb JG |
1229 | test_cmp expected actual |
1230 | " | |
1231 | ||
1232 | test_expect_success 'merging original branch into this branch' ' | |
1233 | git merge --strategy=ours master && | |
1234 | git tag v4.0 | |
1235 | ' | |
1236 | ||
1237 | cat > expected <<EOF | |
1238 | v4.0 | |
1239 | EOF | |
1240 | ||
1241 | test_expect_success 'checking that original branch head has one tag now' " | |
2dec68cf | 1242 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1243 | test_cmp expected actual |
1244 | " | |
1245 | ||
1246 | cat > expected <<EOF | |
1247 | v0.2.1 | |
1248 | v1.0 | |
1249 | v1.0.1 | |
1250 | v1.1.3 | |
1251 | v2.0 | |
1252 | v3.0 | |
1253 | v4.0 | |
1254 | EOF | |
1255 | ||
1256 | test_expect_success 'checking that initial commit is in all tags' " | |
2dec68cf | 1257 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1258 | test_cmp expected actual |
1259 | " | |
1260 | ||
e0e03a73 ST |
1261 | # mixing modes and options: |
1262 | ||
1263 | test_expect_success 'mixing incompatibles modes and options is forbidden' ' | |
2dec68cf JN |
1264 | test_must_fail git tag -a && |
1265 | test_must_fail git tag -l -v && | |
1266 | test_must_fail git tag -n 100 && | |
1267 | test_must_fail git tag -l -m msg && | |
1268 | test_must_fail git tag -l -F some file && | |
e0e03a73 ST |
1269 | test_must_fail git tag -v -s |
1270 | ' | |
1271 | ||
ef5a6fb5 | 1272 | test_done |