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