]>
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 | ||
d96e3c15 NTND |
266 | test_expect_success 'listing tags in column' ' |
267 | COLUMNS=40 git tag -l --column=row >actual && | |
268 | cat >expected <<\EOF && | |
269 | a1 aa1 cba t210 t211 | |
270 | v0.2.1 v1.0 v1.0.1 v1.1.3 | |
271 | EOF | |
272 | test_cmp expected actual | |
273 | ' | |
274 | ||
275 | test_expect_success 'listing tags in column with column.*' ' | |
276 | git config column.tag row && | |
277 | git config column.ui dense && | |
278 | COLUMNS=40 git tag -l >actual && | |
279 | git config --unset column.ui && | |
280 | git config --unset column.tag && | |
281 | cat >expected <<\EOF && | |
282 | a1 aa1 cba t210 t211 | |
283 | v0.2.1 v1.0 v1.0.1 v1.1.3 | |
284 | EOF | |
285 | test_cmp expected actual | |
286 | ' | |
287 | ||
288 | test_expect_success 'listing tag with -n --column should fail' ' | |
289 | test_must_fail git tag --column -n | |
290 | ' | |
291 | ||
292 | test_expect_success 'listing tags -n in column with column.ui ignored' ' | |
293 | git config column.ui "row dense" && | |
294 | COLUMNS=40 git tag -l -n >actual && | |
295 | git config --unset column.ui && | |
296 | cat >expected <<\EOF && | |
297 | a1 Foo | |
298 | aa1 Foo | |
299 | cba Foo | |
300 | t210 Foo | |
301 | t211 Foo | |
302 | v0.2.1 Foo | |
303 | v1.0 Foo | |
304 | v1.0.1 Foo | |
305 | v1.1.3 Foo | |
306 | EOF | |
307 | test_cmp expected actual | |
308 | ' | |
309 | ||
ef5a6fb5 CR |
310 | # creating and verifying lightweight tags: |
311 | ||
312 | test_expect_success \ | |
313 | 'a non-annotated tag created without parameters should point to HEAD' ' | |
d592b315 | 314 | git tag non-annotated-tag && |
5be60078 JH |
315 | test $(git cat-file -t non-annotated-tag) = commit && |
316 | test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) | |
ef5a6fb5 CR |
317 | ' |
318 | ||
41ac414e | 319 | test_expect_success 'trying to verify an unknown tag should fail' \ |
d592b315 | 320 | 'test_must_fail git tag -v unknown-tag' |
ef5a6fb5 | 321 | |
41ac414e | 322 | test_expect_success \ |
ef5a6fb5 | 323 | 'trying to verify a non-annotated and non-signed tag should fail' \ |
d592b315 | 324 | 'test_must_fail git tag -v non-annotated-tag' |
ef5a6fb5 | 325 | |
41ac414e | 326 | test_expect_success \ |
62e09ce9 | 327 | 'trying to verify many non-annotated or unknown tags, should fail' \ |
d592b315 | 328 | 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' |
62e09ce9 | 329 | |
ef5a6fb5 CR |
330 | # creating annotated tags: |
331 | ||
332 | get_tag_msg () { | |
333 | git cat-file tag "$1" | sed -e "/BEGIN PGP/q" | |
334 | } | |
335 | ||
336 | # run test_tick before committing always gives the time in that timezone | |
337 | get_tag_header () { | |
338 | cat <<EOF | |
339 | object $2 | |
340 | type $3 | |
341 | tag $1 | |
342 | tagger C O Mitter <committer@example.com> $4 -0700 | |
343 | ||
344 | EOF | |
345 | } | |
346 | ||
347 | commit=$(git rev-parse HEAD) | |
348 | time=$test_tick | |
349 | ||
350 | get_tag_header annotated-tag $commit commit $time >expect | |
351 | echo "A message" >>expect | |
352 | test_expect_success \ | |
353 | 'creating an annotated tag with -m message should succeed' ' | |
d592b315 | 354 | git tag -m "A message" annotated-tag && |
ef5a6fb5 | 355 | get_tag_msg annotated-tag >actual && |
3af82863 | 356 | test_cmp expect actual |
ef5a6fb5 CR |
357 | ' |
358 | ||
359 | cat >msgfile <<EOF | |
360 | Another message | |
361 | in a file. | |
362 | EOF | |
363 | get_tag_header file-annotated-tag $commit commit $time >expect | |
364 | cat msgfile >>expect | |
365 | test_expect_success \ | |
366 | 'creating an annotated tag with -F messagefile should succeed' ' | |
d592b315 | 367 | git tag -F msgfile file-annotated-tag && |
ef5a6fb5 | 368 | get_tag_msg file-annotated-tag >actual && |
3af82863 | 369 | test_cmp expect actual |
ef5a6fb5 CR |
370 | ' |
371 | ||
62e09ce9 CR |
372 | cat >inputmsg <<EOF |
373 | A message from the | |
374 | standard input | |
375 | EOF | |
376 | get_tag_header stdin-annotated-tag $commit commit $time >expect | |
377 | cat inputmsg >>expect | |
378 | test_expect_success 'creating an annotated tag with -F - should succeed' ' | |
d592b315 | 379 | git tag -F - stdin-annotated-tag <inputmsg && |
62e09ce9 | 380 | get_tag_msg stdin-annotated-tag >actual && |
3af82863 | 381 | test_cmp expect actual |
62e09ce9 CR |
382 | ' |
383 | ||
e317cfaf CR |
384 | test_expect_success \ |
385 | 'trying to create a tag with a non-existing -F file should fail' ' | |
386 | ! test -f nonexistingfile && | |
387 | ! tag_exists notag && | |
d592b315 | 388 | test_must_fail git tag -F nonexistingfile notag && |
e317cfaf CR |
389 | ! tag_exists notag |
390 | ' | |
391 | ||
392 | test_expect_success \ | |
39686585 | 393 | 'trying to create tags giving both -m or -F options should fail' ' |
e317cfaf CR |
394 | echo "message file 1" >msgfile1 && |
395 | echo "message file 2" >msgfile2 && | |
396 | ! tag_exists msgtag && | |
d592b315 | 397 | test_must_fail git tag -m "message 1" -F msgfile1 msgtag && |
e317cfaf | 398 | ! tag_exists msgtag && |
d592b315 | 399 | test_must_fail git tag -F msgfile1 -m "message 1" msgtag && |
e317cfaf | 400 | ! tag_exists msgtag && |
d592b315 | 401 | test_must_fail git tag -m "message 1" -F msgfile1 \ |
d492b31c | 402 | -m "message 2" msgtag && |
e317cfaf CR |
403 | ! tag_exists msgtag |
404 | ' | |
405 | ||
ef5a6fb5 CR |
406 | # blank and empty messages: |
407 | ||
408 | get_tag_header empty-annotated-tag $commit commit $time >expect | |
409 | test_expect_success \ | |
410 | 'creating a tag with an empty -m message should succeed' ' | |
d592b315 | 411 | git tag -m "" empty-annotated-tag && |
ef5a6fb5 | 412 | get_tag_msg empty-annotated-tag >actual && |
3af82863 | 413 | test_cmp expect actual |
ef5a6fb5 CR |
414 | ' |
415 | ||
416 | >emptyfile | |
417 | get_tag_header emptyfile-annotated-tag $commit commit $time >expect | |
418 | test_expect_success \ | |
419 | 'creating a tag with an empty -F messagefile should succeed' ' | |
d592b315 | 420 | git tag -F emptyfile emptyfile-annotated-tag && |
ef5a6fb5 | 421 | get_tag_msg emptyfile-annotated-tag >actual && |
3af82863 | 422 | test_cmp expect actual |
ef5a6fb5 CR |
423 | ' |
424 | ||
425 | printf '\n\n \n\t\nLeading blank lines\n' >blanksfile | |
426 | printf '\n\t \t \nRepeated blank lines\n' >>blanksfile | |
427 | printf '\n\n\nTrailing spaces \t \n' >>blanksfile | |
428 | printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile | |
429 | get_tag_header blanks-annotated-tag $commit commit $time >expect | |
430 | cat >>expect <<EOF | |
431 | Leading blank lines | |
432 | ||
433 | Repeated blank lines | |
434 | ||
435 | Trailing spaces | |
436 | ||
437 | Trailing blank lines | |
438 | EOF | |
439 | test_expect_success \ | |
440 | 'extra blanks in the message for an annotated tag should be removed' ' | |
d592b315 | 441 | git tag -F blanksfile blanks-annotated-tag && |
ef5a6fb5 | 442 | get_tag_msg blanks-annotated-tag >actual && |
3af82863 | 443 | test_cmp expect actual |
ef5a6fb5 CR |
444 | ' |
445 | ||
446 | get_tag_header blank-annotated-tag $commit commit $time >expect | |
447 | test_expect_success \ | |
448 | 'creating a tag with blank -m message with spaces should succeed' ' | |
d592b315 | 449 | git tag -m " " blank-annotated-tag && |
ef5a6fb5 | 450 | get_tag_msg blank-annotated-tag >actual && |
3af82863 | 451 | test_cmp expect actual |
ef5a6fb5 CR |
452 | ' |
453 | ||
454 | echo ' ' >blankfile | |
455 | echo '' >>blankfile | |
456 | echo ' ' >>blankfile | |
457 | get_tag_header blankfile-annotated-tag $commit commit $time >expect | |
458 | test_expect_success \ | |
459 | 'creating a tag with blank -F messagefile with spaces should succeed' ' | |
d592b315 | 460 | git tag -F blankfile blankfile-annotated-tag && |
ef5a6fb5 | 461 | get_tag_msg blankfile-annotated-tag >actual && |
3af82863 | 462 | test_cmp expect actual |
ef5a6fb5 CR |
463 | ' |
464 | ||
465 | printf ' ' >blanknonlfile | |
466 | get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect | |
467 | test_expect_success \ | |
468 | 'creating a tag with -F file of spaces and no newline should succeed' ' | |
d592b315 | 469 | git tag -F blanknonlfile blanknonlfile-annotated-tag && |
ef5a6fb5 | 470 | get_tag_msg blanknonlfile-annotated-tag >actual && |
3af82863 | 471 | test_cmp expect actual |
ef5a6fb5 CR |
472 | ' |
473 | ||
474 | # messages with commented lines: | |
475 | ||
476 | cat >commentsfile <<EOF | |
477 | # A comment | |
478 | ||
479 | ############ | |
480 | The message. | |
481 | ############ | |
482 | One line. | |
483 | ||
484 | ||
485 | # commented lines | |
486 | # commented lines | |
487 | ||
488 | Another line. | |
489 | # comments | |
490 | ||
491 | Last line. | |
492 | EOF | |
493 | get_tag_header comments-annotated-tag $commit commit $time >expect | |
494 | cat >>expect <<EOF | |
495 | The message. | |
496 | One line. | |
497 | ||
498 | Another line. | |
499 | ||
500 | Last line. | |
501 | EOF | |
502 | test_expect_success \ | |
503 | 'creating a tag using a -F messagefile with #comments should succeed' ' | |
d592b315 | 504 | git tag -F commentsfile comments-annotated-tag && |
ef5a6fb5 | 505 | get_tag_msg comments-annotated-tag >actual && |
3af82863 | 506 | test_cmp expect actual |
ef5a6fb5 CR |
507 | ' |
508 | ||
509 | get_tag_header comment-annotated-tag $commit commit $time >expect | |
510 | test_expect_success \ | |
511 | 'creating a tag with a #comment in the -m message should succeed' ' | |
d592b315 | 512 | git tag -m "#comment" comment-annotated-tag && |
ef5a6fb5 | 513 | get_tag_msg comment-annotated-tag >actual && |
3af82863 | 514 | test_cmp expect actual |
ef5a6fb5 CR |
515 | ' |
516 | ||
517 | echo '#comment' >commentfile | |
518 | echo '' >>commentfile | |
519 | echo '####' >>commentfile | |
520 | get_tag_header commentfile-annotated-tag $commit commit $time >expect | |
521 | test_expect_success \ | |
522 | 'creating a tag with #comments in the -F messagefile should succeed' ' | |
d592b315 | 523 | git tag -F commentfile commentfile-annotated-tag && |
ef5a6fb5 | 524 | get_tag_msg commentfile-annotated-tag >actual && |
3af82863 | 525 | test_cmp expect actual |
ef5a6fb5 CR |
526 | ' |
527 | ||
528 | printf '#comment' >commentnonlfile | |
529 | get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect | |
530 | test_expect_success \ | |
531 | 'creating a tag with a file of #comment and no newline should succeed' ' | |
d592b315 | 532 | git tag -F commentnonlfile commentnonlfile-annotated-tag && |
ef5a6fb5 | 533 | get_tag_msg commentnonlfile-annotated-tag >actual && |
3af82863 | 534 | test_cmp expect actual |
ef5a6fb5 CR |
535 | ' |
536 | ||
5206d130 CR |
537 | # listing messages for annotated non-signed tags: |
538 | ||
539 | test_expect_success \ | |
540 | 'listing the one-line message of a non-signed tag should succeed' ' | |
d592b315 | 541 | git tag -m "A msg" tag-one-line && |
5206d130 CR |
542 | |
543 | echo "tag-one-line" >expect && | |
d592b315 | 544 | git tag -l | grep "^tag-one-line" >actual && |
3af82863 | 545 | test_cmp expect actual && |
d592b315 | 546 | git tag -n0 -l | grep "^tag-one-line" >actual && |
3af82863 | 547 | test_cmp expect actual && |
d592b315 | 548 | git tag -n0 -l tag-one-line >actual && |
3af82863 | 549 | test_cmp expect actual && |
5206d130 CR |
550 | |
551 | echo "tag-one-line A msg" >expect && | |
d592b315 | 552 | git tag -n1 -l | grep "^tag-one-line" >actual && |
3af82863 | 553 | test_cmp expect actual && |
d592b315 | 554 | git tag -n -l | grep "^tag-one-line" >actual && |
3af82863 | 555 | test_cmp expect actual && |
d592b315 | 556 | git tag -n1 -l tag-one-line >actual && |
3af82863 | 557 | test_cmp expect actual && |
d592b315 | 558 | git tag -n2 -l tag-one-line >actual && |
3af82863 | 559 | test_cmp expect actual && |
d592b315 | 560 | git tag -n999 -l tag-one-line >actual && |
3af82863 | 561 | test_cmp expect actual |
5206d130 CR |
562 | ' |
563 | ||
564 | test_expect_success \ | |
565 | 'listing the zero-lines message of a non-signed tag should succeed' ' | |
d592b315 | 566 | git tag -m "" tag-zero-lines && |
5206d130 CR |
567 | |
568 | echo "tag-zero-lines" >expect && | |
d592b315 | 569 | git tag -l | grep "^tag-zero-lines" >actual && |
3af82863 | 570 | test_cmp expect actual && |
d592b315 | 571 | git tag -n0 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 572 | test_cmp expect actual && |
d592b315 | 573 | git tag -n0 -l tag-zero-lines >actual && |
3af82863 | 574 | test_cmp expect actual && |
5206d130 CR |
575 | |
576 | echo "tag-zero-lines " >expect && | |
d592b315 | 577 | git tag -n1 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 578 | test_cmp expect actual && |
d592b315 | 579 | git tag -n -l | grep "^tag-zero-lines" >actual && |
3af82863 | 580 | test_cmp expect actual && |
d592b315 | 581 | git tag -n1 -l tag-zero-lines >actual && |
3af82863 | 582 | test_cmp expect actual && |
d592b315 | 583 | git tag -n2 -l tag-zero-lines >actual && |
3af82863 | 584 | test_cmp expect actual && |
d592b315 | 585 | git tag -n999 -l tag-zero-lines >actual && |
3af82863 | 586 | test_cmp expect actual |
5206d130 CR |
587 | ' |
588 | ||
589 | echo 'tag line one' >annotagmsg | |
590 | echo 'tag line two' >>annotagmsg | |
591 | echo 'tag line three' >>annotagmsg | |
592 | test_expect_success \ | |
593 | 'listing many message lines of a non-signed tag should succeed' ' | |
d592b315 | 594 | git tag -F annotagmsg tag-lines && |
5206d130 CR |
595 | |
596 | echo "tag-lines" >expect && | |
d592b315 | 597 | git tag -l | grep "^tag-lines" >actual && |
3af82863 | 598 | test_cmp expect actual && |
d592b315 | 599 | git tag -n0 -l | grep "^tag-lines" >actual && |
3af82863 | 600 | test_cmp expect actual && |
d592b315 | 601 | git tag -n0 -l tag-lines >actual && |
3af82863 | 602 | test_cmp expect actual && |
5206d130 CR |
603 | |
604 | echo "tag-lines tag line one" >expect && | |
d592b315 | 605 | git tag -n1 -l | grep "^tag-lines" >actual && |
3af82863 | 606 | test_cmp expect actual && |
d592b315 | 607 | git tag -n -l | grep "^tag-lines" >actual && |
3af82863 | 608 | test_cmp expect actual && |
d592b315 | 609 | git tag -n1 -l tag-lines >actual && |
3af82863 | 610 | test_cmp expect actual && |
5206d130 CR |
611 | |
612 | echo " tag line two" >>expect && | |
d592b315 | 613 | git tag -n2 -l | grep "^ *tag.line" >actual && |
3af82863 | 614 | test_cmp expect actual && |
d592b315 | 615 | git tag -n2 -l tag-lines >actual && |
3af82863 | 616 | test_cmp expect actual && |
5206d130 CR |
617 | |
618 | echo " tag line three" >>expect && | |
d592b315 | 619 | git tag -n3 -l | grep "^ *tag.line" >actual && |
3af82863 | 620 | test_cmp expect actual && |
d592b315 | 621 | git tag -n3 -l tag-lines >actual && |
3af82863 | 622 | test_cmp expect actual && |
d592b315 | 623 | git tag -n4 -l | grep "^ *tag.line" >actual && |
3af82863 | 624 | test_cmp expect actual && |
d592b315 | 625 | git tag -n4 -l tag-lines >actual && |
3af82863 | 626 | test_cmp expect actual && |
d592b315 | 627 | git tag -n99 -l | grep "^ *tag.line" >actual && |
3af82863 | 628 | test_cmp expect actual && |
d592b315 | 629 | git tag -n99 -l tag-lines >actual && |
3af82863 | 630 | test_cmp expect actual |
5206d130 CR |
631 | ' |
632 | ||
31fd8d72 JH |
633 | test_expect_success 'annotations for blobs are empty' ' |
634 | blob=$(git hash-object -w --stdin <<-\EOF | |
635 | Blob paragraph 1. | |
636 | ||
637 | Blob paragraph 2. | |
638 | EOF | |
639 | ) && | |
640 | git tag tag-blob $blob && | |
641 | echo "tag-blob " >expect && | |
642 | git tag -n1 -l tag-blob >actual && | |
643 | test_cmp expect actual | |
644 | ' | |
645 | ||
ef5a6fb5 CR |
646 | # trying to verify annotated non-signed tags: |
647 | ||
a4df22ce | 648 | test_expect_success GPG \ |
ef5a6fb5 CR |
649 | 'trying to verify an annotated non-signed tag should fail' ' |
650 | tag_exists annotated-tag && | |
d592b315 | 651 | test_must_fail git tag -v annotated-tag |
ef5a6fb5 CR |
652 | ' |
653 | ||
a4df22ce | 654 | test_expect_success GPG \ |
ef5a6fb5 CR |
655 | 'trying to verify a file-annotated non-signed tag should fail' ' |
656 | tag_exists file-annotated-tag && | |
d592b315 | 657 | test_must_fail git tag -v file-annotated-tag |
ef5a6fb5 CR |
658 | ' |
659 | ||
a4df22ce | 660 | test_expect_success GPG \ |
62e09ce9 CR |
661 | 'trying to verify two annotated non-signed tags should fail' ' |
662 | tag_exists annotated-tag file-annotated-tag && | |
d592b315 | 663 | test_must_fail git tag -v annotated-tag file-annotated-tag |
62e09ce9 CR |
664 | ' |
665 | ||
ef5a6fb5 CR |
666 | # creating and verifying signed tags: |
667 | ||
ef5a6fb5 CR |
668 | get_tag_header signed-tag $commit commit $time >expect |
669 | echo 'A signed tag message' >>expect | |
670 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 671 | test_expect_success GPG 'creating a signed tag with -m message should succeed' ' |
d592b315 | 672 | git tag -s -m "A signed tag message" signed-tag && |
ef5a6fb5 | 673 | get_tag_msg signed-tag >actual && |
3af82863 | 674 | test_cmp expect actual |
ef5a6fb5 CR |
675 | ' |
676 | ||
be15f505 LT |
677 | get_tag_header u-signed-tag $commit commit $time >expect |
678 | echo 'Another message' >>expect | |
679 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 680 | test_expect_success GPG 'sign with a given key id' ' |
be15f505 LT |
681 | |
682 | git tag -u committer@example.com -m "Another message" u-signed-tag && | |
683 | get_tag_msg u-signed-tag >actual && | |
3af82863 | 684 | test_cmp expect actual |
be15f505 LT |
685 | |
686 | ' | |
687 | ||
a4df22ce | 688 | test_expect_success GPG 'sign with an unknown id (1)' ' |
be15f505 | 689 | |
d492b31c SB |
690 | test_must_fail git tag -u author@example.com \ |
691 | -m "Another message" o-signed-tag | |
be15f505 LT |
692 | |
693 | ' | |
694 | ||
a4df22ce | 695 | test_expect_success GPG 'sign with an unknown id (2)' ' |
be15f505 | 696 | |
d492b31c | 697 | test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag |
be15f505 LT |
698 | |
699 | ' | |
700 | ||
701 | cat >fakeeditor <<'EOF' | |
702 | #!/bin/sh | |
703 | test -n "$1" && exec >"$1" | |
704 | echo A signed tag message | |
705 | echo from a fake editor. | |
706 | EOF | |
707 | chmod +x fakeeditor | |
708 | ||
709 | get_tag_header implied-sign $commit commit $time >expect | |
710 | ./fakeeditor >>expect | |
711 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 712 | test_expect_success GPG '-u implies signed tag' ' |
d592b315 | 713 | GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && |
be15f505 | 714 | get_tag_msg implied-sign >actual && |
3af82863 | 715 | test_cmp expect actual |
be15f505 LT |
716 | ' |
717 | ||
62e09ce9 CR |
718 | cat >sigmsgfile <<EOF |
719 | Another signed tag | |
720 | message in a file. | |
721 | EOF | |
722 | get_tag_header file-signed-tag $commit commit $time >expect | |
723 | cat sigmsgfile >>expect | |
724 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 725 | test_expect_success GPG \ |
62e09ce9 | 726 | 'creating a signed tag with -F messagefile should succeed' ' |
d592b315 | 727 | git tag -s -F sigmsgfile file-signed-tag && |
62e09ce9 | 728 | get_tag_msg file-signed-tag >actual && |
3af82863 | 729 | test_cmp expect actual |
62e09ce9 CR |
730 | ' |
731 | ||
732 | cat >siginputmsg <<EOF | |
733 | A signed tag message from | |
734 | the standard input | |
735 | EOF | |
736 | get_tag_header stdin-signed-tag $commit commit $time >expect | |
737 | cat siginputmsg >>expect | |
738 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 739 | test_expect_success GPG 'creating a signed tag with -F - should succeed' ' |
d592b315 | 740 | git tag -s -F - stdin-signed-tag <siginputmsg && |
62e09ce9 | 741 | get_tag_msg stdin-signed-tag >actual && |
3af82863 | 742 | test_cmp expect actual |
62e09ce9 CR |
743 | ' |
744 | ||
10507857 JK |
745 | get_tag_header implied-annotate $commit commit $time >expect |
746 | ./fakeeditor >>expect | |
747 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 748 | test_expect_success GPG '-s implies annotated tag' ' |
d592b315 | 749 | GIT_EDITOR=./fakeeditor git tag -s implied-annotate && |
10507857 | 750 | get_tag_msg implied-annotate >actual && |
3af82863 | 751 | test_cmp expect actual |
10507857 JK |
752 | ' |
753 | ||
a4df22ce | 754 | test_expect_success GPG \ |
e317cfaf CR |
755 | 'trying to create a signed tag with non-existing -F file should fail' ' |
756 | ! test -f nonexistingfile && | |
757 | ! tag_exists nosigtag && | |
d592b315 | 758 | test_must_fail git tag -s -F nonexistingfile nosigtag && |
e317cfaf CR |
759 | ! tag_exists nosigtag |
760 | ' | |
761 | ||
a4df22ce | 762 | test_expect_success GPG 'verifying a signed tag should succeed' \ |
d592b315 | 763 | 'git tag -v signed-tag' |
ef5a6fb5 | 764 | |
a4df22ce | 765 | test_expect_success GPG 'verifying two signed tags in one command should succeed' \ |
d592b315 | 766 | 'git tag -v signed-tag file-signed-tag' |
62e09ce9 | 767 | |
a4df22ce | 768 | test_expect_success GPG \ |
62e09ce9 | 769 | 'verifying many signed and non-signed tags should fail' ' |
d592b315 NS |
770 | test_must_fail git tag -v signed-tag annotated-tag && |
771 | test_must_fail git tag -v file-annotated-tag file-signed-tag && | |
772 | test_must_fail git tag -v annotated-tag \ | |
d492b31c | 773 | file-signed-tag file-annotated-tag && |
d592b315 | 774 | test_must_fail git tag -v signed-tag annotated-tag file-signed-tag |
62e09ce9 CR |
775 | ' |
776 | ||
a4df22ce | 777 | test_expect_success GPG 'verifying a forged tag should fail' ' |
ef5a6fb5 CR |
778 | forged=$(git cat-file tag signed-tag | |
779 | sed -e "s/signed-tag/forged-tag/" | | |
780 | git mktag) && | |
781 | git tag forged-tag $forged && | |
d592b315 | 782 | test_must_fail git tag -v forged-tag |
ef5a6fb5 CR |
783 | ' |
784 | ||
785 | # blank and empty messages for signed tags: | |
786 | ||
787 | get_tag_header empty-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 an empty -m message should succeed' ' |
d592b315 | 791 | git tag -s -m "" empty-signed-tag && |
ef5a6fb5 | 792 | get_tag_msg empty-signed-tag >actual && |
3af82863 | 793 | test_cmp expect actual && |
d592b315 | 794 | git tag -v empty-signed-tag |
ef5a6fb5 CR |
795 | ' |
796 | ||
797 | >sigemptyfile | |
798 | get_tag_header emptyfile-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 an empty -F messagefile should succeed' ' |
d592b315 | 802 | git tag -s -F sigemptyfile emptyfile-signed-tag && |
ef5a6fb5 | 803 | get_tag_msg emptyfile-signed-tag >actual && |
3af82863 | 804 | test_cmp expect actual && |
d592b315 | 805 | git tag -v emptyfile-signed-tag |
ef5a6fb5 CR |
806 | ' |
807 | ||
808 | printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile | |
809 | printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile | |
810 | printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile | |
811 | printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile | |
812 | get_tag_header blanks-signed-tag $commit commit $time >expect | |
813 | cat >>expect <<EOF | |
814 | Leading blank lines | |
815 | ||
816 | Repeated blank lines | |
817 | ||
818 | Trailing spaces | |
819 | ||
820 | Trailing blank lines | |
821 | EOF | |
822 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 823 | test_expect_success GPG \ |
ef5a6fb5 | 824 | 'extra blanks in the message for a signed tag should be removed' ' |
d592b315 | 825 | git tag -s -F sigblanksfile blanks-signed-tag && |
ef5a6fb5 | 826 | get_tag_msg blanks-signed-tag >actual && |
3af82863 | 827 | test_cmp expect actual && |
d592b315 | 828 | git tag -v blanks-signed-tag |
ef5a6fb5 CR |
829 | ' |
830 | ||
831 | get_tag_header blank-signed-tag $commit commit $time >expect | |
832 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 833 | test_expect_success GPG \ |
ef5a6fb5 | 834 | 'creating a signed tag with a blank -m message should succeed' ' |
d592b315 | 835 | git tag -s -m " " blank-signed-tag && |
ef5a6fb5 | 836 | get_tag_msg blank-signed-tag >actual && |
3af82863 | 837 | test_cmp expect actual && |
d592b315 | 838 | git tag -v blank-signed-tag |
ef5a6fb5 CR |
839 | ' |
840 | ||
841 | echo ' ' >sigblankfile | |
842 | echo '' >>sigblankfile | |
843 | echo ' ' >>sigblankfile | |
844 | get_tag_header blankfile-signed-tag $commit commit $time >expect | |
845 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 846 | test_expect_success GPG \ |
ef5a6fb5 | 847 | 'creating a signed tag with blank -F file with spaces should succeed' ' |
d592b315 | 848 | git tag -s -F sigblankfile blankfile-signed-tag && |
ef5a6fb5 | 849 | get_tag_msg blankfile-signed-tag >actual && |
3af82863 | 850 | test_cmp expect actual && |
d592b315 | 851 | git tag -v blankfile-signed-tag |
ef5a6fb5 CR |
852 | ' |
853 | ||
854 | printf ' ' >sigblanknonlfile | |
855 | get_tag_header blanknonlfile-signed-tag $commit commit $time >expect | |
856 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 857 | test_expect_success GPG \ |
ef5a6fb5 | 858 | 'creating a signed tag with spaces and no newline should succeed' ' |
d592b315 | 859 | git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && |
ef5a6fb5 | 860 | get_tag_msg blanknonlfile-signed-tag >actual && |
3af82863 | 861 | test_cmp expect actual && |
d592b315 | 862 | git tag -v signed-tag |
ef5a6fb5 CR |
863 | ' |
864 | ||
865 | # messages with commented lines for signed tags: | |
866 | ||
867 | cat >sigcommentsfile <<EOF | |
868 | # A comment | |
869 | ||
870 | ############ | |
871 | The message. | |
872 | ############ | |
873 | One line. | |
874 | ||
875 | ||
876 | # commented lines | |
877 | # commented lines | |
878 | ||
879 | Another line. | |
880 | # comments | |
881 | ||
882 | Last line. | |
883 | EOF | |
884 | get_tag_header comments-signed-tag $commit commit $time >expect | |
885 | cat >>expect <<EOF | |
886 | The message. | |
887 | One line. | |
888 | ||
889 | Another line. | |
890 | ||
891 | Last line. | |
892 | EOF | |
893 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 894 | test_expect_success GPG \ |
ef5a6fb5 | 895 | 'creating a signed tag with a -F file with #comments should succeed' ' |
d592b315 | 896 | git tag -s -F sigcommentsfile comments-signed-tag && |
ef5a6fb5 | 897 | get_tag_msg comments-signed-tag >actual && |
3af82863 | 898 | test_cmp expect actual && |
d592b315 | 899 | git tag -v comments-signed-tag |
ef5a6fb5 CR |
900 | ' |
901 | ||
902 | get_tag_header comment-signed-tag $commit commit $time >expect | |
903 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 904 | test_expect_success GPG \ |
ef5a6fb5 | 905 | 'creating a signed tag with #commented -m message should succeed' ' |
d592b315 | 906 | git tag -s -m "#comment" comment-signed-tag && |
ef5a6fb5 | 907 | get_tag_msg comment-signed-tag >actual && |
3af82863 | 908 | test_cmp expect actual && |
d592b315 | 909 | git tag -v comment-signed-tag |
ef5a6fb5 CR |
910 | ' |
911 | ||
912 | echo '#comment' >sigcommentfile | |
913 | echo '' >>sigcommentfile | |
914 | echo '####' >>sigcommentfile | |
915 | get_tag_header commentfile-signed-tag $commit commit $time >expect | |
916 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 917 | test_expect_success GPG \ |
ef5a6fb5 | 918 | 'creating a signed tag with #commented -F messagefile should succeed' ' |
d592b315 | 919 | git tag -s -F sigcommentfile commentfile-signed-tag && |
ef5a6fb5 | 920 | get_tag_msg commentfile-signed-tag >actual && |
3af82863 | 921 | test_cmp expect actual && |
d592b315 | 922 | git tag -v commentfile-signed-tag |
ef5a6fb5 CR |
923 | ' |
924 | ||
925 | printf '#comment' >sigcommentnonlfile | |
926 | get_tag_header commentnonlfile-signed-tag $commit commit $time >expect | |
927 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 928 | test_expect_success GPG \ |
ef5a6fb5 | 929 | 'creating a signed tag with a #comment and no newline should succeed' ' |
d592b315 | 930 | git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && |
ef5a6fb5 | 931 | get_tag_msg commentnonlfile-signed-tag >actual && |
3af82863 | 932 | test_cmp expect actual && |
d592b315 | 933 | git tag -v commentnonlfile-signed-tag |
ef5a6fb5 CR |
934 | ' |
935 | ||
5206d130 CR |
936 | # listing messages for signed tags: |
937 | ||
a4df22ce | 938 | test_expect_success GPG \ |
5206d130 | 939 | 'listing the one-line message of a signed tag should succeed' ' |
d592b315 | 940 | git tag -s -m "A message line signed" stag-one-line && |
5206d130 CR |
941 | |
942 | echo "stag-one-line" >expect && | |
d592b315 | 943 | git tag -l | grep "^stag-one-line" >actual && |
3af82863 | 944 | test_cmp expect actual && |
d592b315 | 945 | git tag -n0 -l | grep "^stag-one-line" >actual && |
3af82863 | 946 | test_cmp expect actual && |
d592b315 | 947 | git tag -n0 -l stag-one-line >actual && |
3af82863 | 948 | test_cmp expect actual && |
5206d130 CR |
949 | |
950 | echo "stag-one-line A message line signed" >expect && | |
d592b315 | 951 | git tag -n1 -l | grep "^stag-one-line" >actual && |
3af82863 | 952 | test_cmp expect actual && |
d592b315 | 953 | git tag -n -l | grep "^stag-one-line" >actual && |
3af82863 | 954 | test_cmp expect actual && |
d592b315 | 955 | git tag -n1 -l stag-one-line >actual && |
3af82863 | 956 | test_cmp expect actual && |
d592b315 | 957 | git tag -n2 -l stag-one-line >actual && |
3af82863 | 958 | test_cmp expect actual && |
d592b315 | 959 | git tag -n999 -l stag-one-line >actual && |
3af82863 | 960 | test_cmp expect actual |
5206d130 CR |
961 | ' |
962 | ||
a4df22ce | 963 | test_expect_success GPG \ |
5206d130 | 964 | 'listing the zero-lines message of a signed tag should succeed' ' |
d592b315 | 965 | git tag -s -m "" stag-zero-lines && |
5206d130 CR |
966 | |
967 | echo "stag-zero-lines" >expect && | |
d592b315 | 968 | git tag -l | grep "^stag-zero-lines" >actual && |
3af82863 | 969 | test_cmp expect actual && |
d592b315 | 970 | git tag -n0 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 971 | test_cmp expect actual && |
d592b315 | 972 | git tag -n0 -l stag-zero-lines >actual && |
3af82863 | 973 | test_cmp expect actual && |
5206d130 CR |
974 | |
975 | echo "stag-zero-lines " >expect && | |
d592b315 | 976 | git tag -n1 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 977 | test_cmp expect actual && |
d592b315 | 978 | git tag -n -l | grep "^stag-zero-lines" >actual && |
3af82863 | 979 | test_cmp expect actual && |
d592b315 | 980 | git tag -n1 -l stag-zero-lines >actual && |
3af82863 | 981 | test_cmp expect actual && |
d592b315 | 982 | git tag -n2 -l stag-zero-lines >actual && |
3af82863 | 983 | test_cmp expect actual && |
d592b315 | 984 | git tag -n999 -l stag-zero-lines >actual && |
3af82863 | 985 | test_cmp expect actual |
5206d130 CR |
986 | ' |
987 | ||
988 | echo 'stag line one' >sigtagmsg | |
989 | echo 'stag line two' >>sigtagmsg | |
990 | echo 'stag line three' >>sigtagmsg | |
a4df22ce | 991 | test_expect_success GPG \ |
5206d130 | 992 | 'listing many message lines of a signed tag should succeed' ' |
d592b315 | 993 | git tag -s -F sigtagmsg stag-lines && |
5206d130 CR |
994 | |
995 | echo "stag-lines" >expect && | |
d592b315 | 996 | git tag -l | grep "^stag-lines" >actual && |
3af82863 | 997 | test_cmp expect actual && |
d592b315 | 998 | git tag -n0 -l | grep "^stag-lines" >actual && |
3af82863 | 999 | test_cmp expect actual && |
d592b315 | 1000 | git tag -n0 -l stag-lines >actual && |
3af82863 | 1001 | test_cmp expect actual && |
5206d130 CR |
1002 | |
1003 | echo "stag-lines stag line one" >expect && | |
d592b315 | 1004 | git tag -n1 -l | grep "^stag-lines" >actual && |
3af82863 | 1005 | test_cmp expect actual && |
d592b315 | 1006 | git tag -n -l | grep "^stag-lines" >actual && |
3af82863 | 1007 | test_cmp expect actual && |
d592b315 | 1008 | git tag -n1 -l stag-lines >actual && |
3af82863 | 1009 | test_cmp expect actual && |
5206d130 CR |
1010 | |
1011 | echo " stag line two" >>expect && | |
d592b315 | 1012 | git tag -n2 -l | grep "^ *stag.line" >actual && |
3af82863 | 1013 | test_cmp expect actual && |
d592b315 | 1014 | git tag -n2 -l stag-lines >actual && |
3af82863 | 1015 | test_cmp expect actual && |
5206d130 CR |
1016 | |
1017 | echo " stag line three" >>expect && | |
d592b315 | 1018 | git tag -n3 -l | grep "^ *stag.line" >actual && |
3af82863 | 1019 | test_cmp expect actual && |
d592b315 | 1020 | git tag -n3 -l stag-lines >actual && |
3af82863 | 1021 | test_cmp expect actual && |
d592b315 | 1022 | git tag -n4 -l | grep "^ *stag.line" >actual && |
3af82863 | 1023 | test_cmp expect actual && |
d592b315 | 1024 | git tag -n4 -l stag-lines >actual && |
3af82863 | 1025 | test_cmp expect actual && |
d592b315 | 1026 | git tag -n99 -l | grep "^ *stag.line" >actual && |
3af82863 | 1027 | test_cmp expect actual && |
d592b315 | 1028 | git tag -n99 -l stag-lines >actual && |
3af82863 | 1029 | test_cmp expect actual |
5206d130 CR |
1030 | ' |
1031 | ||
ef5a6fb5 CR |
1032 | # tags pointing to objects different from commits: |
1033 | ||
1034 | tree=$(git rev-parse HEAD^{tree}) | |
1035 | blob=$(git rev-parse HEAD:foo) | |
a4df22ce | 1036 | tag=$(git rev-parse signed-tag 2>/dev/null) |
ef5a6fb5 CR |
1037 | |
1038 | get_tag_header tree-signed-tag $tree tree $time >expect | |
1039 | echo "A message for a tree" >>expect | |
1040 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1041 | test_expect_success GPG \ |
ef5a6fb5 | 1042 | 'creating a signed tag pointing to a tree should succeed' ' |
d592b315 | 1043 | git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && |
ef5a6fb5 | 1044 | get_tag_msg tree-signed-tag >actual && |
3af82863 | 1045 | test_cmp expect actual |
ef5a6fb5 CR |
1046 | ' |
1047 | ||
1048 | get_tag_header blob-signed-tag $blob blob $time >expect | |
1049 | echo "A message for a blob" >>expect | |
1050 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1051 | test_expect_success GPG \ |
ef5a6fb5 | 1052 | 'creating a signed tag pointing to a blob should succeed' ' |
d592b315 | 1053 | git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && |
ef5a6fb5 | 1054 | get_tag_msg blob-signed-tag >actual && |
3af82863 | 1055 | test_cmp expect actual |
ef5a6fb5 CR |
1056 | ' |
1057 | ||
1058 | get_tag_header tag-signed-tag $tag tag $time >expect | |
1059 | echo "A message for another tag" >>expect | |
1060 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1061 | test_expect_success GPG \ |
ef5a6fb5 | 1062 | 'creating a signed tag pointing to another tag should succeed' ' |
d592b315 | 1063 | git tag -s -m "A message for another tag" tag-signed-tag signed-tag && |
ef5a6fb5 | 1064 | get_tag_msg tag-signed-tag >actual && |
3af82863 | 1065 | test_cmp expect actual |
ef5a6fb5 CR |
1066 | ' |
1067 | ||
c8525c30 MG |
1068 | # usage with rfc1991 signatures |
1069 | echo "rfc1991" > gpghome/gpg.conf | |
1070 | get_tag_header rfc1991-signed-tag $commit commit $time >expect | |
1071 | echo "RFC1991 signed tag" >>expect | |
1072 | echo '-----BEGIN PGP MESSAGE-----' >>expect | |
1073 | test_expect_success GPG \ | |
1074 | 'creating a signed tag with rfc1991' ' | |
1075 | git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && | |
1076 | get_tag_msg rfc1991-signed-tag >actual && | |
1077 | test_cmp expect actual | |
1078 | ' | |
1079 | ||
1080 | cat >fakeeditor <<'EOF' | |
1081 | #!/bin/sh | |
1082 | cp "$1" actual | |
1083 | EOF | |
1084 | chmod +x fakeeditor | |
1085 | ||
3d5854e7 | 1086 | test_expect_success GPG \ |
c8525c30 MG |
1087 | 'reediting a signed tag body omits signature' ' |
1088 | echo "RFC1991 signed tag" >expect && | |
1089 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1090 | test_cmp expect actual | |
1091 | ' | |
1092 | ||
3d5854e7 | 1093 | test_expect_success GPG \ |
c8525c30 MG |
1094 | 'verifying rfc1991 signature' ' |
1095 | git tag -v rfc1991-signed-tag | |
1096 | ' | |
1097 | ||
3d5854e7 | 1098 | test_expect_success GPG \ |
c8525c30 MG |
1099 | 'list tag with rfc1991 signature' ' |
1100 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && | |
1101 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1102 | test_cmp expect actual && | |
1103 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1104 | test_cmp expect actual && | |
1105 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1106 | test_cmp expect actual | |
1107 | ' | |
1108 | ||
1109 | rm -f gpghome/gpg.conf | |
1110 | ||
3d5854e7 | 1111 | test_expect_success GPG \ |
c8525c30 MG |
1112 | 'verifying rfc1991 signature without --rfc1991' ' |
1113 | git tag -v rfc1991-signed-tag | |
1114 | ' | |
1115 | ||
3d5854e7 | 1116 | test_expect_success GPG \ |
c8525c30 MG |
1117 | 'list tag with rfc1991 signature without --rfc1991' ' |
1118 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && | |
1119 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1120 | test_cmp expect actual && | |
1121 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1122 | test_cmp expect actual && | |
1123 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1124 | test_cmp expect actual | |
1125 | ' | |
1126 | ||
3d5854e7 | 1127 | test_expect_success GPG \ |
c8525c30 MG |
1128 | 'reediting a signed tag body omits signature' ' |
1129 | echo "RFC1991 signed tag" >expect && | |
1130 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1131 | test_cmp expect actual | |
1132 | ' | |
1133 | ||
aba91192 CR |
1134 | # try to sign with bad user.signingkey |
1135 | git config user.signingkey BobTheMouse | |
a4df22ce | 1136 | test_expect_success GPG \ |
d592b315 | 1137 | 'git tag -s fails if gpg is misconfigured' \ |
d492b31c | 1138 | 'test_must_fail git tag -s -m tail tag-gpg-failure' |
aba91192 CR |
1139 | git config --unset user.signingkey |
1140 | ||
ef5a6fb5 CR |
1141 | # try to verify without gpg: |
1142 | ||
1143 | rm -rf gpghome | |
a4df22ce | 1144 | test_expect_success GPG \ |
ef5a6fb5 | 1145 | 'verify signed tag fails when public key is not present' \ |
d592b315 | 1146 | 'test_must_fail git tag -v signed-tag' |
ef5a6fb5 | 1147 | |
41ac414e | 1148 | test_expect_success \ |
d592b315 | 1149 | 'git tag -a fails if tag annotation is empty' ' |
41ac414e | 1150 | ! (GIT_EDITOR=cat git tag -a initial-comment) |
eb9d2b91 MH |
1151 | ' |
1152 | ||
4d8b1dc8 MH |
1153 | test_expect_success \ |
1154 | 'message in editor has initial comment' ' | |
5649bd9a ÆAB |
1155 | ! (GIT_EDITOR=cat git tag -a initial-comment > actual) |
1156 | ' | |
1157 | ||
b3e1900a | 1158 | test_expect_success 'message in editor has initial comment: first line' ' |
eb9d2b91 | 1159 | # check the first line --- should be empty |
5649bd9a ÆAB |
1160 | echo >first.expect && |
1161 | sed -e 1q <actual >first.actual && | |
b3e1900a | 1162 | test_i18ncmp first.expect first.actual |
5649bd9a ÆAB |
1163 | ' |
1164 | ||
1165 | test_expect_success \ | |
1166 | 'message in editor has initial comment: remainder' ' | |
eb9d2b91 | 1167 | # remove commented lines from the remainder -- should be empty |
5649bd9a ÆAB |
1168 | >rest.expect |
1169 | sed -e 1d -e '/^#/d' <actual >rest.actual && | |
1170 | test_cmp rest.expect rest.actual | |
4d8b1dc8 MH |
1171 | ' |
1172 | ||
1173 | get_tag_header reuse $commit commit $time >expect | |
1174 | echo "An annotation to be reused" >> expect | |
1175 | test_expect_success \ | |
1176 | 'overwriting an annoted tag should use its previous body' ' | |
1177 | git tag -a -m "An annotation to be reused" reuse && | |
1178 | GIT_EDITOR=true git tag -f -a reuse && | |
1179 | get_tag_msg reuse >actual && | |
3af82863 | 1180 | test_cmp expect actual |
4d8b1dc8 MH |
1181 | ' |
1182 | ||
dbd0f5c7 JH |
1183 | test_expect_success 'filename for the message is relative to cwd' ' |
1184 | mkdir subdir && | |
1185 | echo "Tag message in top directory" >msgfile-5 && | |
1186 | echo "Tag message in sub directory" >subdir/msgfile-5 && | |
1187 | ( | |
1188 | cd subdir && | |
1189 | git tag -a -F msgfile-5 tag-from-subdir | |
1190 | ) && | |
1191 | git cat-file tag tag-from-subdir | grep "in sub directory" | |
1192 | ' | |
1193 | ||
1194 | test_expect_success 'filename for the message is relative to cwd' ' | |
1195 | echo "Tag message in sub directory" >subdir/msgfile-6 && | |
1196 | ( | |
1197 | cd subdir && | |
1198 | git tag -a -F msgfile-6 tag-from-subdir-2 | |
1199 | ) && | |
1200 | git cat-file tag tag-from-subdir-2 | grep "in sub directory" | |
1201 | ' | |
1202 | ||
32c35cfb JG |
1203 | # create a few more commits to test --contains |
1204 | ||
1205 | hash1=$(git rev-parse HEAD) | |
1206 | ||
1207 | test_expect_success 'creating second commit and tag' ' | |
1208 | echo foo-2.0 >foo && | |
1209 | git add foo && | |
2dec68cf | 1210 | git commit -m second && |
32c35cfb JG |
1211 | git tag v2.0 |
1212 | ' | |
1213 | ||
1214 | hash2=$(git rev-parse HEAD) | |
1215 | ||
1216 | test_expect_success 'creating third commit without tag' ' | |
1217 | echo foo-dev >foo && | |
1218 | git add foo && | |
1219 | git commit -m third | |
1220 | ' | |
1221 | ||
1222 | hash3=$(git rev-parse HEAD) | |
1223 | ||
1224 | # simple linear checks of --continue | |
1225 | ||
1226 | cat > expected <<EOF | |
1227 | v0.2.1 | |
1228 | v1.0 | |
1229 | v1.0.1 | |
1230 | v1.1.3 | |
1231 | v2.0 | |
1232 | EOF | |
1233 | ||
1234 | test_expect_success 'checking that first commit is in all tags (hash)' " | |
2dec68cf | 1235 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1236 | test_cmp expected actual |
1237 | " | |
1238 | ||
1239 | # other ways of specifying the commit | |
1240 | test_expect_success 'checking that first commit is in all tags (tag)' " | |
2dec68cf | 1241 | git tag -l --contains v1.0 v* >actual && |
32c35cfb JG |
1242 | test_cmp expected actual |
1243 | " | |
1244 | ||
1245 | test_expect_success 'checking that first commit is in all tags (relative)' " | |
2dec68cf | 1246 | git tag -l --contains HEAD~2 v* >actual && |
32c35cfb JG |
1247 | test_cmp expected actual |
1248 | " | |
1249 | ||
1250 | cat > expected <<EOF | |
1251 | v2.0 | |
1252 | EOF | |
1253 | ||
1254 | test_expect_success 'checking that second commit only has one tag' " | |
2dec68cf | 1255 | git tag -l --contains $hash2 v* >actual && |
32c35cfb JG |
1256 | test_cmp expected actual |
1257 | " | |
1258 | ||
1259 | ||
1260 | cat > expected <<EOF | |
1261 | EOF | |
1262 | ||
1263 | test_expect_success 'checking that third commit has no tags' " | |
2dec68cf | 1264 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1265 | test_cmp expected actual |
1266 | " | |
1267 | ||
1268 | # how about a simple merge? | |
1269 | ||
1270 | test_expect_success 'creating simple branch' ' | |
1271 | git branch stable v2.0 && | |
1272 | git checkout stable && | |
1273 | echo foo-3.0 > foo && | |
2dec68cf | 1274 | git commit foo -m fourth && |
32c35cfb JG |
1275 | git tag v3.0 |
1276 | ' | |
1277 | ||
1278 | hash4=$(git rev-parse HEAD) | |
1279 | ||
1280 | cat > expected <<EOF | |
1281 | v3.0 | |
1282 | EOF | |
1283 | ||
1284 | test_expect_success 'checking that branch head only has one tag' " | |
2dec68cf | 1285 | git tag -l --contains $hash4 v* >actual && |
32c35cfb JG |
1286 | test_cmp expected actual |
1287 | " | |
1288 | ||
1289 | test_expect_success 'merging original branch into this branch' ' | |
1290 | git merge --strategy=ours master && | |
1291 | git tag v4.0 | |
1292 | ' | |
1293 | ||
1294 | cat > expected <<EOF | |
1295 | v4.0 | |
1296 | EOF | |
1297 | ||
1298 | test_expect_success 'checking that original branch head has one tag now' " | |
2dec68cf | 1299 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1300 | test_cmp expected actual |
1301 | " | |
1302 | ||
1303 | cat > expected <<EOF | |
1304 | v0.2.1 | |
1305 | v1.0 | |
1306 | v1.0.1 | |
1307 | v1.1.3 | |
1308 | v2.0 | |
1309 | v3.0 | |
1310 | v4.0 | |
1311 | EOF | |
1312 | ||
1313 | test_expect_success 'checking that initial commit is in all tags' " | |
2dec68cf | 1314 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1315 | test_cmp expected actual |
1316 | " | |
1317 | ||
e0e03a73 ST |
1318 | # mixing modes and options: |
1319 | ||
1320 | test_expect_success 'mixing incompatibles modes and options is forbidden' ' | |
2dec68cf JN |
1321 | test_must_fail git tag -a && |
1322 | test_must_fail git tag -l -v && | |
1323 | test_must_fail git tag -n 100 && | |
1324 | test_must_fail git tag -l -m msg && | |
1325 | test_must_fail git tag -l -F some file && | |
e0e03a73 ST |
1326 | test_must_fail git tag -v -s |
1327 | ' | |
1328 | ||
ae7706b9 TG |
1329 | # check points-at |
1330 | ||
1331 | test_expect_success '--points-at cannot be used in non-list mode' ' | |
1332 | test_must_fail git tag --points-at=v4.0 foo | |
1333 | ' | |
1334 | ||
1335 | test_expect_success '--points-at finds lightweight tags' ' | |
1336 | echo v4.0 >expect && | |
1337 | git tag --points-at v4.0 >actual && | |
1338 | test_cmp expect actual | |
1339 | ' | |
1340 | ||
1341 | test_expect_success '--points-at finds annotated tags of commits' ' | |
1342 | git tag -m "v4.0, annotated" annotated-v4.0 v4.0 && | |
1343 | echo annotated-v4.0 >expect && | |
1344 | git tag -l --points-at v4.0 "annotated*" >actual && | |
1345 | test_cmp expect actual | |
1346 | ' | |
1347 | ||
1348 | test_expect_success '--points-at finds annotated tags of tags' ' | |
1349 | git tag -m "describing the v4.0 tag object" \ | |
1350 | annotated-again-v4.0 annotated-v4.0 && | |
1351 | cat >expect <<-\EOF && | |
1352 | annotated-again-v4.0 | |
1353 | annotated-v4.0 | |
1354 | EOF | |
1355 | git tag --points-at=annotated-v4.0 >actual && | |
1356 | test_cmp expect actual | |
1357 | ' | |
1358 | ||
1359 | test_expect_success 'multiple --points-at are OR-ed together' ' | |
1360 | cat >expect <<-\EOF && | |
1361 | v2.0 | |
1362 | v3.0 | |
1363 | EOF | |
1364 | git tag --points-at=v2.0 --points-at=v3.0 >actual && | |
1365 | test_cmp expect actual | |
1366 | ' | |
1367 | ||
ef5a6fb5 | 1368 | test_done |