]>
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 | ||
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' ' |
63873a0a EP |
25 | test $(git tag -l | wc -l) -eq 0 && |
26 | test $(git tag | wc -l) -eq 0 | |
62e09ce9 | 27 | ' |
ef5a6fb5 | 28 | |
3bb16a8b NTND |
29 | test_expect_success 'sort tags, ignore case' ' |
30 | ( | |
31 | git init sort && | |
32 | cd sort && | |
33 | test_commit initial && | |
34 | git tag tag-one && | |
35 | git tag TAG-two && | |
36 | git tag -l >actual && | |
37 | cat >expected <<-\EOF && | |
38 | TAG-two | |
39 | initial | |
40 | tag-one | |
41 | EOF | |
42 | test_cmp expected actual && | |
43 | git tag -l -i >actual && | |
44 | cat >expected <<-\EOF && | |
45 | initial | |
46 | tag-one | |
47 | TAG-two | |
48 | EOF | |
49 | test_cmp expected actual | |
50 | ) | |
51 | ' | |
52 | ||
41ac414e JH |
53 | test_expect_success 'looking for a tag in an empty tree should fail' \ |
54 | '! (tag_exists mytag)' | |
ef5a6fb5 CR |
55 | |
56 | test_expect_success 'creating a tag in an empty tree should fail' ' | |
d592b315 | 57 | test_must_fail git tag mynotag && |
ef5a6fb5 CR |
58 | ! tag_exists mynotag |
59 | ' | |
60 | ||
61 | test_expect_success 'creating a tag for HEAD in an empty tree should fail' ' | |
d592b315 | 62 | test_must_fail git tag mytaghead HEAD && |
ef5a6fb5 CR |
63 | ! tag_exists mytaghead |
64 | ' | |
65 | ||
66 | test_expect_success 'creating a tag for an unknown revision should fail' ' | |
d592b315 | 67 | test_must_fail git tag mytagnorev aaaaaaaaaaa && |
ef5a6fb5 CR |
68 | ! tag_exists mytagnorev |
69 | ' | |
70 | ||
71 | # commit used in the tests, test_tick is also called here to freeze the date: | |
72 | test_expect_success 'creating a tag using default HEAD should succeed' ' | |
341fb286 | 73 | test_config core.logAllRefUpdates true && |
ef5a6fb5 CR |
74 | test_tick && |
75 | echo foo >foo && | |
76 | git add foo && | |
77 | git commit -m Foo && | |
144c76fa DT |
78 | git tag mytag && |
79 | test_must_fail git reflog exists refs/tags/mytag | |
80 | ' | |
81 | ||
82 | test_expect_success 'creating a tag with --create-reflog should create reflog' ' | |
df8512ed CW |
83 | git log -1 \ |
84 | --format="format:tag: tagging %h (%s, %cd)%n" \ | |
85 | --date=format:%Y-%m-%d >expected && | |
144c76fa DT |
86 | test_when_finished "git tag -d tag_with_reflog" && |
87 | git tag --create-reflog tag_with_reflog && | |
df8512ed CW |
88 | git reflog exists refs/tags/tag_with_reflog && |
89 | sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual && | |
90 | test_cmp expected actual | |
91 | ' | |
92 | ||
93 | test_expect_success 'annotated tag with --create-reflog has correct message' ' | |
94 | git log -1 \ | |
95 | --format="format:tag: tagging %h (%s, %cd)%n" \ | |
96 | --date=format:%Y-%m-%d >expected && | |
97 | test_when_finished "git tag -d tag_with_reflog" && | |
98 | git tag -m "annotated tag" --create-reflog tag_with_reflog && | |
99 | git reflog exists refs/tags/tag_with_reflog && | |
100 | sed -e "s/^.* //" .git/logs/refs/tags/tag_with_reflog >actual && | |
101 | test_cmp expected actual | |
144c76fa DT |
102 | ' |
103 | ||
104 | test_expect_success '--create-reflog does not create reflog on failure' ' | |
105 | test_must_fail git tag --create-reflog mytag && | |
106 | test_must_fail git reflog exists refs/tags/mytag | |
ef5a6fb5 CR |
107 | ' |
108 | ||
341fb286 CW |
109 | test_expect_success 'option core.logAllRefUpdates=always creates reflog' ' |
110 | test_when_finished "git tag -d tag_with_reflog" && | |
111 | test_config core.logAllRefUpdates always && | |
112 | git tag tag_with_reflog && | |
113 | git reflog exists refs/tags/tag_with_reflog | |
114 | ' | |
115 | ||
62e09ce9 | 116 | test_expect_success 'listing all tags if one exists should succeed' ' |
d592b315 NS |
117 | git tag -l && |
118 | git tag | |
62e09ce9 | 119 | ' |
ef5a6fb5 | 120 | |
c485b24c ÆAB |
121 | cat >expect <<EOF |
122 | mytag | |
123 | EOF | |
124 | test_expect_success 'Multiple -l or --list options are equivalent to one -l option' ' | |
125 | git tag -l -l >actual && | |
126 | test_cmp expect actual && | |
127 | git tag --list --list >actual && | |
128 | test_cmp expect actual && | |
129 | git tag --list -l --list >actual && | |
130 | test_cmp expect actual | |
131 | ' | |
132 | ||
62e09ce9 | 133 | test_expect_success 'listing all tags if one exists should output that tag' ' |
63873a0a EP |
134 | test $(git tag -l) = mytag && |
135 | test $(git tag) = mytag | |
62e09ce9 | 136 | ' |
ef5a6fb5 CR |
137 | |
138 | # pattern matching: | |
139 | ||
140 | test_expect_success 'listing a tag using a matching pattern should succeed' \ | |
d592b315 | 141 | 'git tag -l mytag' |
ef5a6fb5 | 142 | |
3bb16a8b NTND |
143 | test_expect_success 'listing a tag with --ignore-case' \ |
144 | 'test $(git tag -l --ignore-case MYTAG) = mytag' | |
145 | ||
ef5a6fb5 CR |
146 | test_expect_success \ |
147 | 'listing a tag using a matching pattern should output that tag' \ | |
63873a0a | 148 | 'test $(git tag -l mytag) = mytag' |
ef5a6fb5 | 149 | |
ef5a6fb5 | 150 | test_expect_success \ |
682b29f9 | 151 | 'listing tags using a non-matching pattern should succeed' \ |
d592b315 | 152 | 'git tag -l xxx' |
ef5a6fb5 CR |
153 | |
154 | test_expect_success \ | |
155 | 'listing tags using a non-matching pattern should output nothing' \ | |
63873a0a | 156 | 'test $(git tag -l xxx | wc -l) -eq 0' |
ef5a6fb5 CR |
157 | |
158 | # special cases for creating tags: | |
159 | ||
41ac414e | 160 | test_expect_success \ |
ef5a6fb5 | 161 | 'trying to create a tag with the name of one existing should fail' \ |
d492b31c | 162 | 'test_must_fail git tag mytag' |
ef5a6fb5 CR |
163 | |
164 | test_expect_success \ | |
165 | 'trying to create a tag with a non-valid name should fail' ' | |
63873a0a | 166 | test $(git tag -l | wc -l) -eq 1 && |
d492b31c SB |
167 | test_must_fail git tag "" && |
168 | test_must_fail git tag .othertag && | |
169 | test_must_fail git tag "other tag" && | |
170 | test_must_fail git tag "othertag^" && | |
171 | test_must_fail git tag "other~tag" && | |
63873a0a | 172 | test $(git tag -l | wc -l) -eq 1 |
ef5a6fb5 CR |
173 | ' |
174 | ||
175 | test_expect_success 'creating a tag using HEAD directly should succeed' ' | |
176 | git tag myhead HEAD && | |
177 | tag_exists myhead | |
178 | ' | |
179 | ||
3ae851e6 PH |
180 | test_expect_success '--force can create a tag with the name of one existing' ' |
181 | tag_exists mytag && | |
182 | git tag --force mytag && | |
183 | tag_exists mytag' | |
184 | ||
185 | test_expect_success '--force is moot with a non-existing tag name' ' | |
eba286e3 | 186 | test_when_finished git tag -d newtag forcetag && |
3ae851e6 PH |
187 | git tag newtag >expect && |
188 | git tag --force forcetag >actual && | |
189 | test_cmp expect actual | |
190 | ' | |
3ae851e6 | 191 | |
ef5a6fb5 CR |
192 | # deleting tags: |
193 | ||
194 | test_expect_success 'trying to delete an unknown tag should fail' ' | |
195 | ! tag_exists unknown-tag && | |
d592b315 | 196 | test_must_fail git tag -d unknown-tag |
ef5a6fb5 CR |
197 | ' |
198 | ||
199 | cat >expect <<EOF | |
200 | myhead | |
201 | mytag | |
202 | EOF | |
203 | test_expect_success \ | |
204 | 'trying to delete tags without params should succeed and do nothing' ' | |
3af82863 | 205 | git tag -l > actual && test_cmp expect actual && |
d592b315 | 206 | git tag -d && |
3af82863 | 207 | git tag -l > actual && test_cmp expect actual |
ef5a6fb5 CR |
208 | ' |
209 | ||
210 | test_expect_success \ | |
211 | 'deleting two existing tags in one command should succeed' ' | |
212 | tag_exists mytag && | |
213 | tag_exists myhead && | |
d592b315 | 214 | git tag -d mytag myhead && |
ef5a6fb5 CR |
215 | ! tag_exists mytag && |
216 | ! tag_exists myhead | |
217 | ' | |
218 | ||
219 | test_expect_success \ | |
220 | 'creating a tag with the name of another deleted one should succeed' ' | |
221 | ! tag_exists mytag && | |
d592b315 | 222 | git tag mytag && |
ef5a6fb5 CR |
223 | tag_exists mytag |
224 | ' | |
225 | ||
226 | test_expect_success \ | |
227 | 'trying to delete two tags, existing and not, should fail in the 2nd' ' | |
228 | tag_exists mytag && | |
229 | ! tag_exists myhead && | |
d592b315 | 230 | test_must_fail git tag -d mytag anothertag && |
ef5a6fb5 CR |
231 | ! tag_exists mytag && |
232 | ! tag_exists myhead | |
233 | ' | |
234 | ||
41ac414e | 235 | test_expect_success 'trying to delete an already deleted tag should fail' \ |
d592b315 | 236 | 'test_must_fail git tag -d mytag' |
ef5a6fb5 CR |
237 | |
238 | # listing various tags with pattern matching: | |
239 | ||
240 | cat >expect <<EOF | |
241 | a1 | |
242 | aa1 | |
243 | cba | |
244 | t210 | |
245 | t211 | |
246 | v0.2.1 | |
247 | v1.0 | |
248 | v1.0.1 | |
249 | v1.1.3 | |
250 | EOF | |
251 | test_expect_success 'listing all tags should print them ordered' ' | |
252 | git tag v1.0.1 && | |
253 | git tag t211 && | |
254 | git tag aa1 && | |
255 | git tag v0.2.1 && | |
256 | git tag v1.1.3 && | |
257 | git tag cba && | |
258 | git tag a1 && | |
259 | git tag v1.0 && | |
260 | git tag t210 && | |
5206d130 | 261 | git tag -l > actual && |
3af82863 | 262 | test_cmp expect actual && |
62e09ce9 | 263 | git tag > actual && |
3af82863 | 264 | test_cmp expect actual |
ef5a6fb5 CR |
265 | ' |
266 | ||
267 | cat >expect <<EOF | |
268 | a1 | |
269 | aa1 | |
270 | cba | |
271 | EOF | |
272 | test_expect_success \ | |
273 | 'listing tags with substring as pattern must print those matching' ' | |
0aaaef7b JS |
274 | rm *a* && |
275 | git tag -l "*a*" > current && | |
276 | test_cmp expect current | |
ef5a6fb5 CR |
277 | ' |
278 | ||
279 | cat >expect <<EOF | |
280 | v0.2.1 | |
281 | v1.0.1 | |
ef5a6fb5 CR |
282 | EOF |
283 | test_expect_success \ | |
18e32b5b | 284 | 'listing tags with a suffix as pattern must print those matching' ' |
d592b315 | 285 | git tag -l "*.1" > actual && |
3af82863 | 286 | test_cmp expect actual |
ef5a6fb5 CR |
287 | ' |
288 | ||
289 | cat >expect <<EOF | |
290 | t210 | |
291 | t211 | |
292 | EOF | |
293 | test_expect_success \ | |
18e32b5b | 294 | 'listing tags with a prefix as pattern must print those matching' ' |
d592b315 | 295 | git tag -l "t21*" > actual && |
3af82863 | 296 | test_cmp expect actual |
ef5a6fb5 CR |
297 | ' |
298 | ||
299 | cat >expect <<EOF | |
300 | a1 | |
ef5a6fb5 CR |
301 | EOF |
302 | test_expect_success \ | |
18e32b5b | 303 | 'listing tags using a name as pattern must print that one matching' ' |
d592b315 | 304 | git tag -l a1 > actual && |
3af82863 | 305 | test_cmp expect actual |
ef5a6fb5 CR |
306 | ' |
307 | ||
308 | cat >expect <<EOF | |
309 | v1.0 | |
ef5a6fb5 CR |
310 | EOF |
311 | test_expect_success \ | |
18e32b5b | 312 | 'listing tags using a name as pattern must print that one matching' ' |
d592b315 | 313 | git tag -l v1.0 > actual && |
3af82863 | 314 | test_cmp expect actual |
ef5a6fb5 CR |
315 | ' |
316 | ||
317 | cat >expect <<EOF | |
18e32b5b | 318 | v1.0.1 |
ef5a6fb5 CR |
319 | v1.1.3 |
320 | EOF | |
321 | test_expect_success \ | |
322 | 'listing tags with ? in the pattern should print those matching' ' | |
d592b315 | 323 | git tag -l "v1.?.?" > actual && |
3af82863 | 324 | test_cmp expect actual |
ef5a6fb5 CR |
325 | ' |
326 | ||
327 | >expect | |
328 | test_expect_success \ | |
329 | 'listing tags using v.* should print nothing because none have v.' ' | |
d592b315 | 330 | git tag -l "v.*" > actual && |
3af82863 | 331 | test_cmp expect actual |
ef5a6fb5 CR |
332 | ' |
333 | ||
334 | cat >expect <<EOF | |
335 | v0.2.1 | |
336 | v1.0 | |
337 | v1.0.1 | |
338 | v1.1.3 | |
339 | EOF | |
340 | test_expect_success \ | |
341 | 'listing tags using v* should print only those having v' ' | |
d592b315 | 342 | git tag -l "v*" > actual && |
3af82863 | 343 | test_cmp expect actual |
ef5a6fb5 CR |
344 | ' |
345 | ||
588d0e83 JK |
346 | test_expect_success 'tag -l can accept multiple patterns' ' |
347 | git tag -l "v1*" "v0*" >actual && | |
348 | test_cmp expect actual | |
349 | ' | |
350 | ||
c485b24c ÆAB |
351 | # Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation |
352 | # could leave you with the impression that "-l <pattern> -l <pattern>" | |
353 | # was how we wanted to accept multiple patterns. | |
354 | # | |
355 | # This test should not imply that this is a sane thing to support. but | |
356 | # since the documentation was worded like it was let's at least find | |
357 | # out if we're going to break this long-documented form of taking | |
358 | # multiple patterns. | |
359 | test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' ' | |
360 | git tag -l "v1*" -l "v0*" >actual && | |
361 | test_cmp expect actual | |
362 | ' | |
363 | ||
d96e3c15 NTND |
364 | test_expect_success 'listing tags in column' ' |
365 | COLUMNS=40 git tag -l --column=row >actual && | |
366 | cat >expected <<\EOF && | |
367 | a1 aa1 cba t210 t211 | |
368 | v0.2.1 v1.0 v1.0.1 v1.1.3 | |
369 | EOF | |
370 | test_cmp expected actual | |
371 | ' | |
372 | ||
373 | test_expect_success 'listing tags in column with column.*' ' | |
9ffda48f SG |
374 | test_config column.tag row && |
375 | test_config column.ui dense && | |
d96e3c15 | 376 | COLUMNS=40 git tag -l >actual && |
d96e3c15 NTND |
377 | cat >expected <<\EOF && |
378 | a1 aa1 cba t210 t211 | |
379 | v0.2.1 v1.0 v1.0.1 v1.1.3 | |
380 | EOF | |
381 | test_cmp expected actual | |
382 | ' | |
383 | ||
384 | test_expect_success 'listing tag with -n --column should fail' ' | |
385 | test_must_fail git tag --column -n | |
386 | ' | |
387 | ||
388 | test_expect_success 'listing tags -n in column with column.ui ignored' ' | |
9ffda48f | 389 | test_config column.ui "row dense" && |
d96e3c15 | 390 | COLUMNS=40 git tag -l -n >actual && |
d96e3c15 NTND |
391 | cat >expected <<\EOF && |
392 | a1 Foo | |
393 | aa1 Foo | |
394 | cba Foo | |
395 | t210 Foo | |
396 | t211 Foo | |
397 | v0.2.1 Foo | |
398 | v1.0 Foo | |
399 | v1.0.1 Foo | |
400 | v1.1.3 Foo | |
401 | EOF | |
402 | test_cmp expected actual | |
403 | ' | |
404 | ||
ef5a6fb5 CR |
405 | # creating and verifying lightweight tags: |
406 | ||
407 | test_expect_success \ | |
408 | 'a non-annotated tag created without parameters should point to HEAD' ' | |
d592b315 | 409 | git tag non-annotated-tag && |
5be60078 JH |
410 | test $(git cat-file -t non-annotated-tag) = commit && |
411 | test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD) | |
ef5a6fb5 CR |
412 | ' |
413 | ||
41ac414e | 414 | test_expect_success 'trying to verify an unknown tag should fail' \ |
d592b315 | 415 | 'test_must_fail git tag -v unknown-tag' |
ef5a6fb5 | 416 | |
41ac414e | 417 | test_expect_success \ |
ef5a6fb5 | 418 | 'trying to verify a non-annotated and non-signed tag should fail' \ |
d592b315 | 419 | 'test_must_fail git tag -v non-annotated-tag' |
ef5a6fb5 | 420 | |
41ac414e | 421 | test_expect_success \ |
62e09ce9 | 422 | 'trying to verify many non-annotated or unknown tags, should fail' \ |
d592b315 | 423 | 'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2' |
62e09ce9 | 424 | |
ef5a6fb5 CR |
425 | # creating annotated tags: |
426 | ||
427 | get_tag_msg () { | |
428 | git cat-file tag "$1" | sed -e "/BEGIN PGP/q" | |
429 | } | |
430 | ||
431 | # run test_tick before committing always gives the time in that timezone | |
432 | get_tag_header () { | |
433 | cat <<EOF | |
434 | object $2 | |
435 | type $3 | |
436 | tag $1 | |
437 | tagger C O Mitter <committer@example.com> $4 -0700 | |
438 | ||
439 | EOF | |
440 | } | |
441 | ||
442 | commit=$(git rev-parse HEAD) | |
443 | time=$test_tick | |
444 | ||
445 | get_tag_header annotated-tag $commit commit $time >expect | |
446 | echo "A message" >>expect | |
447 | test_expect_success \ | |
448 | 'creating an annotated tag with -m message should succeed' ' | |
d592b315 | 449 | git tag -m "A message" annotated-tag && |
ef5a6fb5 | 450 | get_tag_msg annotated-tag >actual && |
3af82863 | 451 | test_cmp expect actual |
ef5a6fb5 CR |
452 | ' |
453 | ||
454 | cat >msgfile <<EOF | |
455 | Another message | |
456 | in a file. | |
457 | EOF | |
458 | get_tag_header file-annotated-tag $commit commit $time >expect | |
459 | cat msgfile >>expect | |
460 | test_expect_success \ | |
461 | 'creating an annotated tag with -F messagefile should succeed' ' | |
d592b315 | 462 | git tag -F msgfile file-annotated-tag && |
ef5a6fb5 | 463 | get_tag_msg file-annotated-tag >actual && |
3af82863 | 464 | test_cmp expect actual |
ef5a6fb5 CR |
465 | ' |
466 | ||
62e09ce9 CR |
467 | cat >inputmsg <<EOF |
468 | A message from the | |
469 | standard input | |
470 | EOF | |
471 | get_tag_header stdin-annotated-tag $commit commit $time >expect | |
472 | cat inputmsg >>expect | |
473 | test_expect_success 'creating an annotated tag with -F - should succeed' ' | |
d592b315 | 474 | git tag -F - stdin-annotated-tag <inputmsg && |
62e09ce9 | 475 | get_tag_msg stdin-annotated-tag >actual && |
3af82863 | 476 | test_cmp expect actual |
62e09ce9 CR |
477 | ' |
478 | ||
e317cfaf CR |
479 | test_expect_success \ |
480 | 'trying to create a tag with a non-existing -F file should fail' ' | |
481 | ! test -f nonexistingfile && | |
482 | ! tag_exists notag && | |
d592b315 | 483 | test_must_fail git tag -F nonexistingfile notag && |
e317cfaf CR |
484 | ! tag_exists notag |
485 | ' | |
486 | ||
487 | test_expect_success \ | |
39686585 | 488 | 'trying to create tags giving both -m or -F options should fail' ' |
e317cfaf CR |
489 | echo "message file 1" >msgfile1 && |
490 | echo "message file 2" >msgfile2 && | |
491 | ! tag_exists msgtag && | |
d592b315 | 492 | test_must_fail git tag -m "message 1" -F msgfile1 msgtag && |
e317cfaf | 493 | ! tag_exists msgtag && |
d592b315 | 494 | test_must_fail git tag -F msgfile1 -m "message 1" msgtag && |
e317cfaf | 495 | ! tag_exists msgtag && |
d592b315 | 496 | test_must_fail git tag -m "message 1" -F msgfile1 \ |
d492b31c | 497 | -m "message 2" msgtag && |
e317cfaf CR |
498 | ! tag_exists msgtag |
499 | ' | |
500 | ||
ef5a6fb5 CR |
501 | # blank and empty messages: |
502 | ||
503 | get_tag_header empty-annotated-tag $commit commit $time >expect | |
504 | test_expect_success \ | |
505 | 'creating a tag with an empty -m message should succeed' ' | |
d592b315 | 506 | git tag -m "" empty-annotated-tag && |
ef5a6fb5 | 507 | get_tag_msg empty-annotated-tag >actual && |
3af82863 | 508 | test_cmp expect actual |
ef5a6fb5 CR |
509 | ' |
510 | ||
511 | >emptyfile | |
512 | get_tag_header emptyfile-annotated-tag $commit commit $time >expect | |
513 | test_expect_success \ | |
514 | 'creating a tag with an empty -F messagefile should succeed' ' | |
d592b315 | 515 | git tag -F emptyfile emptyfile-annotated-tag && |
ef5a6fb5 | 516 | get_tag_msg emptyfile-annotated-tag >actual && |
3af82863 | 517 | test_cmp expect actual |
ef5a6fb5 CR |
518 | ' |
519 | ||
520 | printf '\n\n \n\t\nLeading blank lines\n' >blanksfile | |
521 | printf '\n\t \t \nRepeated blank lines\n' >>blanksfile | |
522 | printf '\n\n\nTrailing spaces \t \n' >>blanksfile | |
523 | printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile | |
524 | get_tag_header blanks-annotated-tag $commit commit $time >expect | |
525 | cat >>expect <<EOF | |
526 | Leading blank lines | |
527 | ||
528 | Repeated blank lines | |
529 | ||
530 | Trailing spaces | |
531 | ||
532 | Trailing blank lines | |
533 | EOF | |
534 | test_expect_success \ | |
535 | 'extra blanks in the message for an annotated tag should be removed' ' | |
d592b315 | 536 | git tag -F blanksfile blanks-annotated-tag && |
ef5a6fb5 | 537 | get_tag_msg blanks-annotated-tag >actual && |
3af82863 | 538 | test_cmp expect actual |
ef5a6fb5 CR |
539 | ' |
540 | ||
541 | get_tag_header blank-annotated-tag $commit commit $time >expect | |
542 | test_expect_success \ | |
543 | 'creating a tag with blank -m message with spaces should succeed' ' | |
d592b315 | 544 | git tag -m " " blank-annotated-tag && |
ef5a6fb5 | 545 | get_tag_msg blank-annotated-tag >actual && |
3af82863 | 546 | test_cmp expect actual |
ef5a6fb5 CR |
547 | ' |
548 | ||
549 | echo ' ' >blankfile | |
550 | echo '' >>blankfile | |
551 | echo ' ' >>blankfile | |
552 | get_tag_header blankfile-annotated-tag $commit commit $time >expect | |
553 | test_expect_success \ | |
554 | 'creating a tag with blank -F messagefile with spaces should succeed' ' | |
d592b315 | 555 | git tag -F blankfile blankfile-annotated-tag && |
ef5a6fb5 | 556 | get_tag_msg blankfile-annotated-tag >actual && |
3af82863 | 557 | test_cmp expect actual |
ef5a6fb5 CR |
558 | ' |
559 | ||
560 | printf ' ' >blanknonlfile | |
561 | get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect | |
562 | test_expect_success \ | |
563 | 'creating a tag with -F file of spaces and no newline should succeed' ' | |
d592b315 | 564 | git tag -F blanknonlfile blanknonlfile-annotated-tag && |
ef5a6fb5 | 565 | get_tag_msg blanknonlfile-annotated-tag >actual && |
3af82863 | 566 | test_cmp expect actual |
ef5a6fb5 CR |
567 | ' |
568 | ||
569 | # messages with commented lines: | |
570 | ||
571 | cat >commentsfile <<EOF | |
572 | # A comment | |
573 | ||
574 | ############ | |
575 | The message. | |
576 | ############ | |
577 | One line. | |
578 | ||
579 | ||
580 | # commented lines | |
581 | # commented lines | |
582 | ||
583 | Another line. | |
584 | # comments | |
585 | ||
586 | Last line. | |
587 | EOF | |
588 | get_tag_header comments-annotated-tag $commit commit $time >expect | |
589 | cat >>expect <<EOF | |
590 | The message. | |
591 | One line. | |
592 | ||
593 | Another line. | |
594 | ||
595 | Last line. | |
596 | EOF | |
597 | test_expect_success \ | |
598 | 'creating a tag using a -F messagefile with #comments should succeed' ' | |
d592b315 | 599 | git tag -F commentsfile comments-annotated-tag && |
ef5a6fb5 | 600 | get_tag_msg comments-annotated-tag >actual && |
3af82863 | 601 | test_cmp expect actual |
ef5a6fb5 CR |
602 | ' |
603 | ||
604 | get_tag_header comment-annotated-tag $commit commit $time >expect | |
605 | test_expect_success \ | |
606 | 'creating a tag with a #comment in the -m message should succeed' ' | |
d592b315 | 607 | git tag -m "#comment" comment-annotated-tag && |
ef5a6fb5 | 608 | get_tag_msg comment-annotated-tag >actual && |
3af82863 | 609 | test_cmp expect actual |
ef5a6fb5 CR |
610 | ' |
611 | ||
612 | echo '#comment' >commentfile | |
613 | echo '' >>commentfile | |
614 | echo '####' >>commentfile | |
615 | get_tag_header commentfile-annotated-tag $commit commit $time >expect | |
616 | test_expect_success \ | |
617 | 'creating a tag with #comments in the -F messagefile should succeed' ' | |
d592b315 | 618 | git tag -F commentfile commentfile-annotated-tag && |
ef5a6fb5 | 619 | get_tag_msg commentfile-annotated-tag >actual && |
3af82863 | 620 | test_cmp expect actual |
ef5a6fb5 CR |
621 | ' |
622 | ||
623 | printf '#comment' >commentnonlfile | |
624 | get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect | |
625 | test_expect_success \ | |
626 | 'creating a tag with a file of #comment and no newline should succeed' ' | |
d592b315 | 627 | git tag -F commentnonlfile commentnonlfile-annotated-tag && |
ef5a6fb5 | 628 | get_tag_msg commentnonlfile-annotated-tag >actual && |
3af82863 | 629 | test_cmp expect actual |
ef5a6fb5 CR |
630 | ' |
631 | ||
5206d130 CR |
632 | # listing messages for annotated non-signed tags: |
633 | ||
634 | test_expect_success \ | |
635 | 'listing the one-line message of a non-signed tag should succeed' ' | |
d592b315 | 636 | git tag -m "A msg" tag-one-line && |
5206d130 CR |
637 | |
638 | echo "tag-one-line" >expect && | |
d592b315 | 639 | git tag -l | grep "^tag-one-line" >actual && |
3af82863 | 640 | test_cmp expect actual && |
d592b315 | 641 | git tag -n0 -l | grep "^tag-one-line" >actual && |
3af82863 | 642 | test_cmp expect actual && |
d592b315 | 643 | git tag -n0 -l tag-one-line >actual && |
3af82863 | 644 | test_cmp expect actual && |
5206d130 | 645 | |
6a338149 ÆAB |
646 | git tag -n0 | grep "^tag-one-line" >actual && |
647 | test_cmp expect actual && | |
648 | git tag -n0 tag-one-line >actual && | |
649 | test_cmp expect actual && | |
650 | ||
5206d130 | 651 | echo "tag-one-line A msg" >expect && |
d592b315 | 652 | git tag -n1 -l | grep "^tag-one-line" >actual && |
3af82863 | 653 | test_cmp expect actual && |
d592b315 | 654 | git tag -n -l | grep "^tag-one-line" >actual && |
3af82863 | 655 | test_cmp expect actual && |
d592b315 | 656 | git tag -n1 -l tag-one-line >actual && |
3af82863 | 657 | test_cmp expect actual && |
d592b315 | 658 | git tag -n2 -l tag-one-line >actual && |
3af82863 | 659 | test_cmp expect actual && |
d592b315 | 660 | git tag -n999 -l tag-one-line >actual && |
3af82863 | 661 | test_cmp expect actual |
5206d130 CR |
662 | ' |
663 | ||
6a338149 ÆAB |
664 | test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' ' |
665 | >expect && | |
666 | git tag -n 100 >actual && | |
667 | test_cmp expect actual && | |
668 | ||
669 | git tag -m "A msg" 100 && | |
670 | echo "100 A msg" >expect && | |
671 | git tag -n 100 >actual && | |
672 | test_cmp expect actual | |
673 | ' | |
674 | ||
5206d130 CR |
675 | test_expect_success \ |
676 | 'listing the zero-lines message of a non-signed tag should succeed' ' | |
d592b315 | 677 | git tag -m "" tag-zero-lines && |
5206d130 CR |
678 | |
679 | echo "tag-zero-lines" >expect && | |
d592b315 | 680 | git tag -l | grep "^tag-zero-lines" >actual && |
3af82863 | 681 | test_cmp expect actual && |
d592b315 | 682 | git tag -n0 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 683 | test_cmp expect actual && |
d592b315 | 684 | git tag -n0 -l tag-zero-lines >actual && |
3af82863 | 685 | test_cmp expect actual && |
5206d130 CR |
686 | |
687 | echo "tag-zero-lines " >expect && | |
d592b315 | 688 | git tag -n1 -l | grep "^tag-zero-lines" >actual && |
3af82863 | 689 | test_cmp expect actual && |
d592b315 | 690 | git tag -n -l | grep "^tag-zero-lines" >actual && |
3af82863 | 691 | test_cmp expect actual && |
d592b315 | 692 | git tag -n1 -l tag-zero-lines >actual && |
3af82863 | 693 | test_cmp expect actual && |
d592b315 | 694 | git tag -n2 -l tag-zero-lines >actual && |
3af82863 | 695 | test_cmp expect actual && |
d592b315 | 696 | git tag -n999 -l tag-zero-lines >actual && |
3af82863 | 697 | test_cmp expect actual |
5206d130 CR |
698 | ' |
699 | ||
700 | echo 'tag line one' >annotagmsg | |
701 | echo 'tag line two' >>annotagmsg | |
702 | echo 'tag line three' >>annotagmsg | |
703 | test_expect_success \ | |
704 | 'listing many message lines of a non-signed tag should succeed' ' | |
d592b315 | 705 | git tag -F annotagmsg tag-lines && |
5206d130 CR |
706 | |
707 | echo "tag-lines" >expect && | |
d592b315 | 708 | git tag -l | grep "^tag-lines" >actual && |
3af82863 | 709 | test_cmp expect actual && |
d592b315 | 710 | git tag -n0 -l | grep "^tag-lines" >actual && |
3af82863 | 711 | test_cmp expect actual && |
d592b315 | 712 | git tag -n0 -l tag-lines >actual && |
3af82863 | 713 | test_cmp expect actual && |
5206d130 CR |
714 | |
715 | echo "tag-lines tag line one" >expect && | |
d592b315 | 716 | git tag -n1 -l | grep "^tag-lines" >actual && |
3af82863 | 717 | test_cmp expect actual && |
d592b315 | 718 | git tag -n -l | grep "^tag-lines" >actual && |
3af82863 | 719 | test_cmp expect actual && |
d592b315 | 720 | git tag -n1 -l tag-lines >actual && |
3af82863 | 721 | test_cmp expect actual && |
5206d130 CR |
722 | |
723 | echo " tag line two" >>expect && | |
d592b315 | 724 | git tag -n2 -l | grep "^ *tag.line" >actual && |
3af82863 | 725 | test_cmp expect actual && |
d592b315 | 726 | git tag -n2 -l tag-lines >actual && |
3af82863 | 727 | test_cmp expect actual && |
5206d130 CR |
728 | |
729 | echo " tag line three" >>expect && | |
d592b315 | 730 | git tag -n3 -l | grep "^ *tag.line" >actual && |
3af82863 | 731 | test_cmp expect actual && |
d592b315 | 732 | git tag -n3 -l tag-lines >actual && |
3af82863 | 733 | test_cmp expect actual && |
d592b315 | 734 | git tag -n4 -l | grep "^ *tag.line" >actual && |
3af82863 | 735 | test_cmp expect actual && |
d592b315 | 736 | git tag -n4 -l tag-lines >actual && |
3af82863 | 737 | test_cmp expect actual && |
d592b315 | 738 | git tag -n99 -l | grep "^ *tag.line" >actual && |
3af82863 | 739 | test_cmp expect actual && |
d592b315 | 740 | git tag -n99 -l tag-lines >actual && |
3af82863 | 741 | test_cmp expect actual |
5206d130 CR |
742 | ' |
743 | ||
31fd8d72 JH |
744 | test_expect_success 'annotations for blobs are empty' ' |
745 | blob=$(git hash-object -w --stdin <<-\EOF | |
746 | Blob paragraph 1. | |
747 | ||
748 | Blob paragraph 2. | |
749 | EOF | |
750 | ) && | |
751 | git tag tag-blob $blob && | |
752 | echo "tag-blob " >expect && | |
753 | git tag -n1 -l tag-blob >actual && | |
754 | test_cmp expect actual | |
755 | ' | |
756 | ||
ef5a6fb5 CR |
757 | # trying to verify annotated non-signed tags: |
758 | ||
a4df22ce | 759 | test_expect_success GPG \ |
ef5a6fb5 CR |
760 | 'trying to verify an annotated non-signed tag should fail' ' |
761 | tag_exists annotated-tag && | |
d592b315 | 762 | test_must_fail git tag -v annotated-tag |
ef5a6fb5 CR |
763 | ' |
764 | ||
a4df22ce | 765 | test_expect_success GPG \ |
ef5a6fb5 CR |
766 | 'trying to verify a file-annotated non-signed tag should fail' ' |
767 | tag_exists file-annotated-tag && | |
d592b315 | 768 | test_must_fail git tag -v file-annotated-tag |
ef5a6fb5 CR |
769 | ' |
770 | ||
a4df22ce | 771 | test_expect_success GPG \ |
62e09ce9 CR |
772 | 'trying to verify two annotated non-signed tags should fail' ' |
773 | tag_exists annotated-tag file-annotated-tag && | |
d592b315 | 774 | test_must_fail git tag -v annotated-tag file-annotated-tag |
62e09ce9 CR |
775 | ' |
776 | ||
ef5a6fb5 CR |
777 | # creating and verifying signed tags: |
778 | ||
ef5a6fb5 CR |
779 | get_tag_header signed-tag $commit commit $time >expect |
780 | echo 'A signed tag message' >>expect | |
781 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 782 | test_expect_success GPG 'creating a signed tag with -m message should succeed' ' |
d592b315 | 783 | git tag -s -m "A signed tag message" signed-tag && |
ef5a6fb5 | 784 | get_tag_msg signed-tag >actual && |
3af82863 | 785 | test_cmp expect actual |
ef5a6fb5 CR |
786 | ' |
787 | ||
be15f505 LT |
788 | get_tag_header u-signed-tag $commit commit $time >expect |
789 | echo 'Another message' >>expect | |
790 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 791 | test_expect_success GPG 'sign with a given key id' ' |
be15f505 LT |
792 | |
793 | git tag -u committer@example.com -m "Another message" u-signed-tag && | |
794 | get_tag_msg u-signed-tag >actual && | |
3af82863 | 795 | test_cmp expect actual |
be15f505 LT |
796 | |
797 | ' | |
798 | ||
a4df22ce | 799 | test_expect_success GPG 'sign with an unknown id (1)' ' |
be15f505 | 800 | |
d492b31c SB |
801 | test_must_fail git tag -u author@example.com \ |
802 | -m "Another message" o-signed-tag | |
be15f505 LT |
803 | |
804 | ' | |
805 | ||
a4df22ce | 806 | test_expect_success GPG 'sign with an unknown id (2)' ' |
be15f505 | 807 | |
d492b31c | 808 | test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag |
be15f505 LT |
809 | |
810 | ' | |
811 | ||
812 | cat >fakeeditor <<'EOF' | |
813 | #!/bin/sh | |
814 | test -n "$1" && exec >"$1" | |
815 | echo A signed tag message | |
816 | echo from a fake editor. | |
817 | EOF | |
818 | chmod +x fakeeditor | |
819 | ||
820 | get_tag_header implied-sign $commit commit $time >expect | |
821 | ./fakeeditor >>expect | |
822 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 823 | test_expect_success GPG '-u implies signed tag' ' |
d592b315 | 824 | GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign && |
be15f505 | 825 | get_tag_msg implied-sign >actual && |
3af82863 | 826 | test_cmp expect actual |
be15f505 LT |
827 | ' |
828 | ||
62e09ce9 CR |
829 | cat >sigmsgfile <<EOF |
830 | Another signed tag | |
831 | message in a file. | |
832 | EOF | |
833 | get_tag_header file-signed-tag $commit commit $time >expect | |
834 | cat sigmsgfile >>expect | |
835 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 836 | test_expect_success GPG \ |
62e09ce9 | 837 | 'creating a signed tag with -F messagefile should succeed' ' |
d592b315 | 838 | git tag -s -F sigmsgfile file-signed-tag && |
62e09ce9 | 839 | get_tag_msg file-signed-tag >actual && |
3af82863 | 840 | test_cmp expect actual |
62e09ce9 CR |
841 | ' |
842 | ||
843 | cat >siginputmsg <<EOF | |
844 | A signed tag message from | |
845 | the standard input | |
846 | EOF | |
847 | get_tag_header stdin-signed-tag $commit commit $time >expect | |
848 | cat siginputmsg >>expect | |
849 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 850 | test_expect_success GPG 'creating a signed tag with -F - should succeed' ' |
d592b315 | 851 | git tag -s -F - stdin-signed-tag <siginputmsg && |
62e09ce9 | 852 | get_tag_msg stdin-signed-tag >actual && |
3af82863 | 853 | test_cmp expect actual |
62e09ce9 CR |
854 | ' |
855 | ||
10507857 JK |
856 | get_tag_header implied-annotate $commit commit $time >expect |
857 | ./fakeeditor >>expect | |
858 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 859 | test_expect_success GPG '-s implies annotated tag' ' |
d592b315 | 860 | GIT_EDITOR=./fakeeditor git tag -s implied-annotate && |
10507857 | 861 | get_tag_msg implied-annotate >actual && |
3af82863 | 862 | test_cmp expect actual |
10507857 JK |
863 | ' |
864 | ||
61c2fe0c LA |
865 | get_tag_header forcesignannotated-implied-sign $commit commit $time >expect |
866 | echo "A message" >>expect | |
867 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
868 | test_expect_success GPG \ | |
869 | 'git tag -s implied if configured with tag.forcesignannotated' \ | |
870 | 'test_config tag.forcesignannotated true && | |
871 | git tag -m "A message" forcesignannotated-implied-sign && | |
872 | get_tag_msg forcesignannotated-implied-sign >actual && | |
873 | test_cmp expect actual | |
874 | ' | |
875 | ||
876 | test_expect_success GPG \ | |
877 | 'lightweight with no message when configured with tag.forcesignannotated' \ | |
878 | 'test_config tag.forcesignannotated true && | |
879 | git tag forcesignannotated-lightweight && | |
880 | tag_exists forcesignannotated-lightweight && | |
881 | test_must_fail git tag -v forcesignannotated-no-message | |
882 | ' | |
883 | ||
884 | get_tag_header forcesignannotated-annotate $commit commit $time >expect | |
885 | echo "A message" >>expect | |
886 | test_expect_success GPG \ | |
887 | 'git tag -a disable configured tag.forcesignannotated' \ | |
888 | 'test_config tag.forcesignannotated true && | |
889 | git tag -a -m "A message" forcesignannotated-annotate && | |
890 | get_tag_msg forcesignannotated-annotate >actual && | |
891 | test_cmp expect actual && | |
892 | test_must_fail git tag -v forcesignannotated-annotate | |
893 | ' | |
894 | ||
895 | get_tag_header forcesignannotated-disabled $commit commit $time >expect | |
896 | echo "A message" >>expect | |
897 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
898 | test_expect_success GPG \ | |
899 | 'git tag --sign enable GPG sign' \ | |
900 | 'test_config tag.forcesignannotated false && | |
901 | git tag --sign -m "A message" forcesignannotated-disabled && | |
902 | get_tag_msg forcesignannotated-disabled >actual && | |
903 | test_cmp expect actual | |
904 | ' | |
905 | ||
a4df22ce | 906 | test_expect_success GPG \ |
e317cfaf CR |
907 | 'trying to create a signed tag with non-existing -F file should fail' ' |
908 | ! test -f nonexistingfile && | |
909 | ! tag_exists nosigtag && | |
d592b315 | 910 | test_must_fail git tag -s -F nonexistingfile nosigtag && |
e317cfaf CR |
911 | ! tag_exists nosigtag |
912 | ' | |
913 | ||
a4df22ce | 914 | test_expect_success GPG 'verifying a signed tag should succeed' \ |
d592b315 | 915 | 'git tag -v signed-tag' |
ef5a6fb5 | 916 | |
a4df22ce | 917 | test_expect_success GPG 'verifying two signed tags in one command should succeed' \ |
d592b315 | 918 | 'git tag -v signed-tag file-signed-tag' |
62e09ce9 | 919 | |
a4df22ce | 920 | test_expect_success GPG \ |
62e09ce9 | 921 | 'verifying many signed and non-signed tags should fail' ' |
d592b315 NS |
922 | test_must_fail git tag -v signed-tag annotated-tag && |
923 | test_must_fail git tag -v file-annotated-tag file-signed-tag && | |
924 | test_must_fail git tag -v annotated-tag \ | |
d492b31c | 925 | file-signed-tag file-annotated-tag && |
d592b315 | 926 | test_must_fail git tag -v signed-tag annotated-tag file-signed-tag |
62e09ce9 CR |
927 | ' |
928 | ||
a4df22ce | 929 | test_expect_success GPG 'verifying a forged tag should fail' ' |
ef5a6fb5 CR |
930 | forged=$(git cat-file tag signed-tag | |
931 | sed -e "s/signed-tag/forged-tag/" | | |
932 | git mktag) && | |
933 | git tag forged-tag $forged && | |
d592b315 | 934 | test_must_fail git tag -v forged-tag |
ef5a6fb5 CR |
935 | ' |
936 | ||
4fea72f4 ST |
937 | test_expect_success 'verifying a proper tag with --format pass and format accordingly' ' |
938 | cat >expect <<-\EOF | |
939 | tagname : signed-tag | |
940 | EOF && | |
941 | git tag -v --format="tagname : %(tag)" "signed-tag" >actual && | |
942 | test_cmp expect actual | |
943 | ' | |
944 | ||
945 | test_expect_success 'verifying a forged tag with --format fail and format accordingly' ' | |
946 | cat >expect <<-\EOF | |
947 | tagname : forged-tag | |
948 | EOF && | |
949 | test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual && | |
950 | test_cmp expect actual | |
951 | ' | |
952 | ||
ef5a6fb5 CR |
953 | # blank and empty messages for signed tags: |
954 | ||
955 | get_tag_header empty-signed-tag $commit commit $time >expect | |
956 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 957 | test_expect_success GPG \ |
ef5a6fb5 | 958 | 'creating a signed tag with an empty -m message should succeed' ' |
d592b315 | 959 | git tag -s -m "" empty-signed-tag && |
ef5a6fb5 | 960 | get_tag_msg empty-signed-tag >actual && |
3af82863 | 961 | test_cmp expect actual && |
d592b315 | 962 | git tag -v empty-signed-tag |
ef5a6fb5 CR |
963 | ' |
964 | ||
965 | >sigemptyfile | |
966 | get_tag_header emptyfile-signed-tag $commit commit $time >expect | |
967 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 968 | test_expect_success GPG \ |
ef5a6fb5 | 969 | 'creating a signed tag with an empty -F messagefile should succeed' ' |
d592b315 | 970 | git tag -s -F sigemptyfile emptyfile-signed-tag && |
ef5a6fb5 | 971 | get_tag_msg emptyfile-signed-tag >actual && |
3af82863 | 972 | test_cmp expect actual && |
d592b315 | 973 | git tag -v emptyfile-signed-tag |
ef5a6fb5 CR |
974 | ' |
975 | ||
976 | printf '\n\n \n\t\nLeading blank lines\n' > sigblanksfile | |
977 | printf '\n\t \t \nRepeated blank lines\n' >>sigblanksfile | |
978 | printf '\n\n\nTrailing spaces \t \n' >>sigblanksfile | |
979 | printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile | |
980 | get_tag_header blanks-signed-tag $commit commit $time >expect | |
981 | cat >>expect <<EOF | |
982 | Leading blank lines | |
983 | ||
984 | Repeated blank lines | |
985 | ||
986 | Trailing spaces | |
987 | ||
988 | Trailing blank lines | |
989 | EOF | |
990 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 991 | test_expect_success GPG \ |
ef5a6fb5 | 992 | 'extra blanks in the message for a signed tag should be removed' ' |
d592b315 | 993 | git tag -s -F sigblanksfile blanks-signed-tag && |
ef5a6fb5 | 994 | get_tag_msg blanks-signed-tag >actual && |
3af82863 | 995 | test_cmp expect actual && |
d592b315 | 996 | git tag -v blanks-signed-tag |
ef5a6fb5 CR |
997 | ' |
998 | ||
999 | get_tag_header blank-signed-tag $commit commit $time >expect | |
1000 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1001 | test_expect_success GPG \ |
ef5a6fb5 | 1002 | 'creating a signed tag with a blank -m message should succeed' ' |
d592b315 | 1003 | git tag -s -m " " blank-signed-tag && |
ef5a6fb5 | 1004 | get_tag_msg blank-signed-tag >actual && |
3af82863 | 1005 | test_cmp expect actual && |
d592b315 | 1006 | git tag -v blank-signed-tag |
ef5a6fb5 CR |
1007 | ' |
1008 | ||
1009 | echo ' ' >sigblankfile | |
1010 | echo '' >>sigblankfile | |
1011 | echo ' ' >>sigblankfile | |
1012 | get_tag_header blankfile-signed-tag $commit commit $time >expect | |
1013 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1014 | test_expect_success GPG \ |
ef5a6fb5 | 1015 | 'creating a signed tag with blank -F file with spaces should succeed' ' |
d592b315 | 1016 | git tag -s -F sigblankfile blankfile-signed-tag && |
ef5a6fb5 | 1017 | get_tag_msg blankfile-signed-tag >actual && |
3af82863 | 1018 | test_cmp expect actual && |
d592b315 | 1019 | git tag -v blankfile-signed-tag |
ef5a6fb5 CR |
1020 | ' |
1021 | ||
1022 | printf ' ' >sigblanknonlfile | |
1023 | get_tag_header blanknonlfile-signed-tag $commit commit $time >expect | |
1024 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1025 | test_expect_success GPG \ |
ef5a6fb5 | 1026 | 'creating a signed tag with spaces and no newline should succeed' ' |
d592b315 | 1027 | git tag -s -F sigblanknonlfile blanknonlfile-signed-tag && |
ef5a6fb5 | 1028 | get_tag_msg blanknonlfile-signed-tag >actual && |
3af82863 | 1029 | test_cmp expect actual && |
d592b315 | 1030 | git tag -v signed-tag |
ef5a6fb5 CR |
1031 | ' |
1032 | ||
1033 | # messages with commented lines for signed tags: | |
1034 | ||
1035 | cat >sigcommentsfile <<EOF | |
1036 | # A comment | |
1037 | ||
1038 | ############ | |
1039 | The message. | |
1040 | ############ | |
1041 | One line. | |
1042 | ||
1043 | ||
1044 | # commented lines | |
1045 | # commented lines | |
1046 | ||
1047 | Another line. | |
1048 | # comments | |
1049 | ||
1050 | Last line. | |
1051 | EOF | |
1052 | get_tag_header comments-signed-tag $commit commit $time >expect | |
1053 | cat >>expect <<EOF | |
1054 | The message. | |
1055 | One line. | |
1056 | ||
1057 | Another line. | |
1058 | ||
1059 | Last line. | |
1060 | EOF | |
1061 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1062 | test_expect_success GPG \ |
ef5a6fb5 | 1063 | 'creating a signed tag with a -F file with #comments should succeed' ' |
d592b315 | 1064 | git tag -s -F sigcommentsfile comments-signed-tag && |
ef5a6fb5 | 1065 | get_tag_msg comments-signed-tag >actual && |
3af82863 | 1066 | test_cmp expect actual && |
d592b315 | 1067 | git tag -v comments-signed-tag |
ef5a6fb5 CR |
1068 | ' |
1069 | ||
1070 | get_tag_header comment-signed-tag $commit commit $time >expect | |
1071 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1072 | test_expect_success GPG \ |
ef5a6fb5 | 1073 | 'creating a signed tag with #commented -m message should succeed' ' |
d592b315 | 1074 | git tag -s -m "#comment" comment-signed-tag && |
ef5a6fb5 | 1075 | get_tag_msg comment-signed-tag >actual && |
3af82863 | 1076 | test_cmp expect actual && |
d592b315 | 1077 | git tag -v comment-signed-tag |
ef5a6fb5 CR |
1078 | ' |
1079 | ||
1080 | echo '#comment' >sigcommentfile | |
1081 | echo '' >>sigcommentfile | |
1082 | echo '####' >>sigcommentfile | |
1083 | get_tag_header commentfile-signed-tag $commit commit $time >expect | |
1084 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1085 | test_expect_success GPG \ |
ef5a6fb5 | 1086 | 'creating a signed tag with #commented -F messagefile should succeed' ' |
d592b315 | 1087 | git tag -s -F sigcommentfile commentfile-signed-tag && |
ef5a6fb5 | 1088 | get_tag_msg commentfile-signed-tag >actual && |
3af82863 | 1089 | test_cmp expect actual && |
d592b315 | 1090 | git tag -v commentfile-signed-tag |
ef5a6fb5 CR |
1091 | ' |
1092 | ||
1093 | printf '#comment' >sigcommentnonlfile | |
1094 | get_tag_header commentnonlfile-signed-tag $commit commit $time >expect | |
1095 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1096 | test_expect_success GPG \ |
ef5a6fb5 | 1097 | 'creating a signed tag with a #comment and no newline should succeed' ' |
d592b315 | 1098 | git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag && |
ef5a6fb5 | 1099 | get_tag_msg commentnonlfile-signed-tag >actual && |
3af82863 | 1100 | test_cmp expect actual && |
d592b315 | 1101 | git tag -v commentnonlfile-signed-tag |
ef5a6fb5 CR |
1102 | ' |
1103 | ||
5206d130 CR |
1104 | # listing messages for signed tags: |
1105 | ||
a4df22ce | 1106 | test_expect_success GPG \ |
5206d130 | 1107 | 'listing the one-line message of a signed tag should succeed' ' |
d592b315 | 1108 | git tag -s -m "A message line signed" stag-one-line && |
5206d130 CR |
1109 | |
1110 | echo "stag-one-line" >expect && | |
d592b315 | 1111 | git tag -l | grep "^stag-one-line" >actual && |
3af82863 | 1112 | test_cmp expect actual && |
d592b315 | 1113 | git tag -n0 -l | grep "^stag-one-line" >actual && |
3af82863 | 1114 | test_cmp expect actual && |
d592b315 | 1115 | git tag -n0 -l stag-one-line >actual && |
3af82863 | 1116 | test_cmp expect actual && |
5206d130 CR |
1117 | |
1118 | echo "stag-one-line A message line signed" >expect && | |
d592b315 | 1119 | git tag -n1 -l | grep "^stag-one-line" >actual && |
3af82863 | 1120 | test_cmp expect actual && |
d592b315 | 1121 | git tag -n -l | grep "^stag-one-line" >actual && |
3af82863 | 1122 | test_cmp expect actual && |
d592b315 | 1123 | git tag -n1 -l stag-one-line >actual && |
3af82863 | 1124 | test_cmp expect actual && |
d592b315 | 1125 | git tag -n2 -l stag-one-line >actual && |
3af82863 | 1126 | test_cmp expect actual && |
d592b315 | 1127 | git tag -n999 -l stag-one-line >actual && |
3af82863 | 1128 | test_cmp expect actual |
5206d130 CR |
1129 | ' |
1130 | ||
a4df22ce | 1131 | test_expect_success GPG \ |
5206d130 | 1132 | 'listing the zero-lines message of a signed tag should succeed' ' |
d592b315 | 1133 | git tag -s -m "" stag-zero-lines && |
5206d130 CR |
1134 | |
1135 | echo "stag-zero-lines" >expect && | |
d592b315 | 1136 | git tag -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1137 | test_cmp expect actual && |
d592b315 | 1138 | git tag -n0 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1139 | test_cmp expect actual && |
d592b315 | 1140 | git tag -n0 -l stag-zero-lines >actual && |
3af82863 | 1141 | test_cmp expect actual && |
5206d130 CR |
1142 | |
1143 | echo "stag-zero-lines " >expect && | |
d592b315 | 1144 | git tag -n1 -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1145 | test_cmp expect actual && |
d592b315 | 1146 | git tag -n -l | grep "^stag-zero-lines" >actual && |
3af82863 | 1147 | test_cmp expect actual && |
d592b315 | 1148 | git tag -n1 -l stag-zero-lines >actual && |
3af82863 | 1149 | test_cmp expect actual && |
d592b315 | 1150 | git tag -n2 -l stag-zero-lines >actual && |
3af82863 | 1151 | test_cmp expect actual && |
d592b315 | 1152 | git tag -n999 -l stag-zero-lines >actual && |
3af82863 | 1153 | test_cmp expect actual |
5206d130 CR |
1154 | ' |
1155 | ||
1156 | echo 'stag line one' >sigtagmsg | |
1157 | echo 'stag line two' >>sigtagmsg | |
1158 | echo 'stag line three' >>sigtagmsg | |
a4df22ce | 1159 | test_expect_success GPG \ |
5206d130 | 1160 | 'listing many message lines of a signed tag should succeed' ' |
d592b315 | 1161 | git tag -s -F sigtagmsg stag-lines && |
5206d130 CR |
1162 | |
1163 | echo "stag-lines" >expect && | |
d592b315 | 1164 | git tag -l | grep "^stag-lines" >actual && |
3af82863 | 1165 | test_cmp expect actual && |
d592b315 | 1166 | git tag -n0 -l | grep "^stag-lines" >actual && |
3af82863 | 1167 | test_cmp expect actual && |
d592b315 | 1168 | git tag -n0 -l stag-lines >actual && |
3af82863 | 1169 | test_cmp expect actual && |
5206d130 CR |
1170 | |
1171 | echo "stag-lines stag line one" >expect && | |
d592b315 | 1172 | git tag -n1 -l | grep "^stag-lines" >actual && |
3af82863 | 1173 | test_cmp expect actual && |
d592b315 | 1174 | git tag -n -l | grep "^stag-lines" >actual && |
3af82863 | 1175 | test_cmp expect actual && |
d592b315 | 1176 | git tag -n1 -l stag-lines >actual && |
3af82863 | 1177 | test_cmp expect actual && |
5206d130 CR |
1178 | |
1179 | echo " stag line two" >>expect && | |
d592b315 | 1180 | git tag -n2 -l | grep "^ *stag.line" >actual && |
3af82863 | 1181 | test_cmp expect actual && |
d592b315 | 1182 | git tag -n2 -l stag-lines >actual && |
3af82863 | 1183 | test_cmp expect actual && |
5206d130 CR |
1184 | |
1185 | echo " stag line three" >>expect && | |
d592b315 | 1186 | git tag -n3 -l | grep "^ *stag.line" >actual && |
3af82863 | 1187 | test_cmp expect actual && |
d592b315 | 1188 | git tag -n3 -l stag-lines >actual && |
3af82863 | 1189 | test_cmp expect actual && |
d592b315 | 1190 | git tag -n4 -l | grep "^ *stag.line" >actual && |
3af82863 | 1191 | test_cmp expect actual && |
d592b315 | 1192 | git tag -n4 -l stag-lines >actual && |
3af82863 | 1193 | test_cmp expect actual && |
d592b315 | 1194 | git tag -n99 -l | grep "^ *stag.line" >actual && |
3af82863 | 1195 | test_cmp expect actual && |
d592b315 | 1196 | git tag -n99 -l stag-lines >actual && |
3af82863 | 1197 | test_cmp expect actual |
5206d130 CR |
1198 | ' |
1199 | ||
ef5a6fb5 CR |
1200 | # tags pointing to objects different from commits: |
1201 | ||
1202 | tree=$(git rev-parse HEAD^{tree}) | |
1203 | blob=$(git rev-parse HEAD:foo) | |
a4df22ce | 1204 | tag=$(git rev-parse signed-tag 2>/dev/null) |
ef5a6fb5 CR |
1205 | |
1206 | get_tag_header tree-signed-tag $tree tree $time >expect | |
1207 | echo "A message for a tree" >>expect | |
1208 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1209 | test_expect_success GPG \ |
ef5a6fb5 | 1210 | 'creating a signed tag pointing to a tree should succeed' ' |
d592b315 | 1211 | git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} && |
ef5a6fb5 | 1212 | get_tag_msg tree-signed-tag >actual && |
3af82863 | 1213 | test_cmp expect actual |
ef5a6fb5 CR |
1214 | ' |
1215 | ||
1216 | get_tag_header blob-signed-tag $blob blob $time >expect | |
1217 | echo "A message for a blob" >>expect | |
1218 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1219 | test_expect_success GPG \ |
ef5a6fb5 | 1220 | 'creating a signed tag pointing to a blob should succeed' ' |
d592b315 | 1221 | git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo && |
ef5a6fb5 | 1222 | get_tag_msg blob-signed-tag >actual && |
3af82863 | 1223 | test_cmp expect actual |
ef5a6fb5 CR |
1224 | ' |
1225 | ||
1226 | get_tag_header tag-signed-tag $tag tag $time >expect | |
1227 | echo "A message for another tag" >>expect | |
1228 | echo '-----BEGIN PGP SIGNATURE-----' >>expect | |
a4df22ce | 1229 | test_expect_success GPG \ |
ef5a6fb5 | 1230 | 'creating a signed tag pointing to another tag should succeed' ' |
d592b315 | 1231 | git tag -s -m "A message for another tag" tag-signed-tag signed-tag && |
ef5a6fb5 | 1232 | get_tag_msg tag-signed-tag >actual && |
3af82863 | 1233 | test_cmp expect actual |
ef5a6fb5 CR |
1234 | ' |
1235 | ||
c8525c30 | 1236 | # usage with rfc1991 signatures |
c8525c30 MG |
1237 | get_tag_header rfc1991-signed-tag $commit commit $time >expect |
1238 | echo "RFC1991 signed tag" >>expect | |
1239 | echo '-----BEGIN PGP MESSAGE-----' >>expect | |
c0e0ed6e | 1240 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1241 | 'creating a signed tag with rfc1991' ' |
086cb911 | 1242 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1243 | git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit && |
1244 | get_tag_msg rfc1991-signed-tag >actual && | |
1245 | test_cmp expect actual | |
1246 | ' | |
1247 | ||
1248 | cat >fakeeditor <<'EOF' | |
1249 | #!/bin/sh | |
1250 | cp "$1" actual | |
1251 | EOF | |
1252 | chmod +x fakeeditor | |
1253 | ||
c0e0ed6e | 1254 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1255 | 'reediting a signed tag body omits signature' ' |
086cb911 | 1256 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1257 | echo "RFC1991 signed tag" >expect && |
1258 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1259 | test_cmp expect actual | |
1260 | ' | |
1261 | ||
c0e0ed6e | 1262 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1263 | 'verifying rfc1991 signature' ' |
086cb911 | 1264 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1265 | git tag -v rfc1991-signed-tag |
1266 | ' | |
1267 | ||
c0e0ed6e | 1268 | test_expect_success GPG,RFC1991 \ |
c8525c30 | 1269 | 'list tag with rfc1991 signature' ' |
086cb911 | 1270 | echo "rfc1991" >gpghome/gpg.conf && |
c8525c30 MG |
1271 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && |
1272 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1273 | test_cmp expect actual && | |
1274 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1275 | test_cmp expect actual && | |
1276 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1277 | test_cmp expect actual | |
1278 | ' | |
1279 | ||
1280 | rm -f gpghome/gpg.conf | |
1281 | ||
c0e0ed6e | 1282 | test_expect_success GPG,RFC1991 \ |
c8525c30 MG |
1283 | 'verifying rfc1991 signature without --rfc1991' ' |
1284 | git tag -v rfc1991-signed-tag | |
1285 | ' | |
1286 | ||
c0e0ed6e | 1287 | test_expect_success GPG,RFC1991 \ |
c8525c30 MG |
1288 | 'list tag with rfc1991 signature without --rfc1991' ' |
1289 | echo "rfc1991-signed-tag RFC1991 signed tag" >expect && | |
1290 | git tag -l -n1 rfc1991-signed-tag >actual && | |
1291 | test_cmp expect actual && | |
1292 | git tag -l -n2 rfc1991-signed-tag >actual && | |
1293 | test_cmp expect actual && | |
1294 | git tag -l -n999 rfc1991-signed-tag >actual && | |
1295 | test_cmp expect actual | |
1296 | ' | |
1297 | ||
c0e0ed6e | 1298 | test_expect_success GPG,RFC1991 \ |
c8525c30 MG |
1299 | 'reediting a signed tag body omits signature' ' |
1300 | echo "RFC1991 signed tag" >expect && | |
1301 | GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit && | |
1302 | test_cmp expect actual | |
1303 | ' | |
1304 | ||
aba91192 | 1305 | # try to sign with bad user.signingkey |
a4df22ce | 1306 | test_expect_success GPG \ |
efee9553 | 1307 | 'git tag -s fails if gpg is misconfigured (bad key)' \ |
9ffda48f SG |
1308 | 'test_config user.signingkey BobTheMouse && |
1309 | test_must_fail git tag -s -m tail tag-gpg-failure' | |
aba91192 | 1310 | |
efee9553 MG |
1311 | # try to produce invalid signature |
1312 | test_expect_success GPG \ | |
1313 | 'git tag -s fails if gpg is misconfigured (bad signature format)' \ | |
1314 | 'test_config gpg.program echo && | |
1315 | test_must_fail git tag -s -m tail tag-gpg-failure' | |
1316 | ||
1317 | ||
ef5a6fb5 CR |
1318 | # try to verify without gpg: |
1319 | ||
1320 | rm -rf gpghome | |
a4df22ce | 1321 | test_expect_success GPG \ |
ef5a6fb5 | 1322 | 'verify signed tag fails when public key is not present' \ |
d592b315 | 1323 | 'test_must_fail git tag -v signed-tag' |
ef5a6fb5 | 1324 | |
41ac414e | 1325 | test_expect_success \ |
d592b315 | 1326 | 'git tag -a fails if tag annotation is empty' ' |
41ac414e | 1327 | ! (GIT_EDITOR=cat git tag -a initial-comment) |
eb9d2b91 MH |
1328 | ' |
1329 | ||
4d8b1dc8 MH |
1330 | test_expect_success \ |
1331 | 'message in editor has initial comment' ' | |
5649bd9a ÆAB |
1332 | ! (GIT_EDITOR=cat git tag -a initial-comment > actual) |
1333 | ' | |
1334 | ||
b3e1900a | 1335 | test_expect_success 'message in editor has initial comment: first line' ' |
eb9d2b91 | 1336 | # check the first line --- should be empty |
5649bd9a ÆAB |
1337 | echo >first.expect && |
1338 | sed -e 1q <actual >first.actual && | |
b3e1900a | 1339 | test_i18ncmp first.expect first.actual |
5649bd9a ÆAB |
1340 | ' |
1341 | ||
1342 | test_expect_success \ | |
1343 | 'message in editor has initial comment: remainder' ' | |
eb9d2b91 | 1344 | # remove commented lines from the remainder -- should be empty |
99094a7a | 1345 | >rest.expect && |
11f228b0 | 1346 | sed -e 1d -e "/^#/d" <actual >rest.actual && |
5649bd9a | 1347 | test_cmp rest.expect rest.actual |
4d8b1dc8 MH |
1348 | ' |
1349 | ||
1350 | get_tag_header reuse $commit commit $time >expect | |
1351 | echo "An annotation to be reused" >> expect | |
1352 | test_expect_success \ | |
1353 | 'overwriting an annoted tag should use its previous body' ' | |
1354 | git tag -a -m "An annotation to be reused" reuse && | |
1355 | GIT_EDITOR=true git tag -f -a reuse && | |
1356 | get_tag_msg reuse >actual && | |
3af82863 | 1357 | test_cmp expect actual |
4d8b1dc8 MH |
1358 | ' |
1359 | ||
dbd0f5c7 JH |
1360 | test_expect_success 'filename for the message is relative to cwd' ' |
1361 | mkdir subdir && | |
1362 | echo "Tag message in top directory" >msgfile-5 && | |
1363 | echo "Tag message in sub directory" >subdir/msgfile-5 && | |
1364 | ( | |
1365 | cd subdir && | |
1366 | git tag -a -F msgfile-5 tag-from-subdir | |
1367 | ) && | |
1368 | git cat-file tag tag-from-subdir | grep "in sub directory" | |
1369 | ' | |
1370 | ||
1371 | test_expect_success 'filename for the message is relative to cwd' ' | |
1372 | echo "Tag message in sub directory" >subdir/msgfile-6 && | |
1373 | ( | |
1374 | cd subdir && | |
1375 | git tag -a -F msgfile-6 tag-from-subdir-2 | |
1376 | ) && | |
1377 | git cat-file tag tag-from-subdir-2 | grep "in sub directory" | |
1378 | ' | |
1379 | ||
32c35cfb JG |
1380 | # create a few more commits to test --contains |
1381 | ||
1382 | hash1=$(git rev-parse HEAD) | |
1383 | ||
1384 | test_expect_success 'creating second commit and tag' ' | |
1385 | echo foo-2.0 >foo && | |
1386 | git add foo && | |
2dec68cf | 1387 | git commit -m second && |
32c35cfb JG |
1388 | git tag v2.0 |
1389 | ' | |
1390 | ||
1391 | hash2=$(git rev-parse HEAD) | |
1392 | ||
1393 | test_expect_success 'creating third commit without tag' ' | |
1394 | echo foo-dev >foo && | |
1395 | git add foo && | |
1396 | git commit -m third | |
1397 | ' | |
1398 | ||
1399 | hash3=$(git rev-parse HEAD) | |
1400 | ||
1401 | # simple linear checks of --continue | |
1402 | ||
1403 | cat > expected <<EOF | |
1404 | v0.2.1 | |
1405 | v1.0 | |
1406 | v1.0.1 | |
1407 | v1.1.3 | |
1408 | v2.0 | |
1409 | EOF | |
1410 | ||
1411 | test_expect_success 'checking that first commit is in all tags (hash)' " | |
2dec68cf | 1412 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1413 | test_cmp expected actual |
1414 | " | |
1415 | ||
1416 | # other ways of specifying the commit | |
1417 | test_expect_success 'checking that first commit is in all tags (tag)' " | |
2dec68cf | 1418 | git tag -l --contains v1.0 v* >actual && |
32c35cfb JG |
1419 | test_cmp expected actual |
1420 | " | |
1421 | ||
1422 | test_expect_success 'checking that first commit is in all tags (relative)' " | |
2dec68cf | 1423 | git tag -l --contains HEAD~2 v* >actual && |
32c35cfb JG |
1424 | test_cmp expected actual |
1425 | " | |
1426 | ||
1427 | cat > expected <<EOF | |
1428 | v2.0 | |
1429 | EOF | |
1430 | ||
1431 | test_expect_success 'checking that second commit only has one tag' " | |
2dec68cf | 1432 | git tag -l --contains $hash2 v* >actual && |
32c35cfb JG |
1433 | test_cmp expected actual |
1434 | " | |
1435 | ||
1436 | ||
1437 | cat > expected <<EOF | |
1438 | EOF | |
1439 | ||
1440 | test_expect_success 'checking that third commit has no tags' " | |
2dec68cf | 1441 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1442 | test_cmp expected actual |
1443 | " | |
1444 | ||
1445 | # how about a simple merge? | |
1446 | ||
1447 | test_expect_success 'creating simple branch' ' | |
1448 | git branch stable v2.0 && | |
1449 | git checkout stable && | |
1450 | echo foo-3.0 > foo && | |
2dec68cf | 1451 | git commit foo -m fourth && |
32c35cfb JG |
1452 | git tag v3.0 |
1453 | ' | |
1454 | ||
1455 | hash4=$(git rev-parse HEAD) | |
1456 | ||
1457 | cat > expected <<EOF | |
1458 | v3.0 | |
1459 | EOF | |
1460 | ||
1461 | test_expect_success 'checking that branch head only has one tag' " | |
2dec68cf | 1462 | git tag -l --contains $hash4 v* >actual && |
32c35cfb JG |
1463 | test_cmp expected actual |
1464 | " | |
1465 | ||
1466 | test_expect_success 'merging original branch into this branch' ' | |
1467 | git merge --strategy=ours master && | |
1468 | git tag v4.0 | |
1469 | ' | |
1470 | ||
1471 | cat > expected <<EOF | |
1472 | v4.0 | |
1473 | EOF | |
1474 | ||
1475 | test_expect_success 'checking that original branch head has one tag now' " | |
2dec68cf | 1476 | git tag -l --contains $hash3 v* >actual && |
32c35cfb JG |
1477 | test_cmp expected actual |
1478 | " | |
1479 | ||
1480 | cat > expected <<EOF | |
1481 | v0.2.1 | |
1482 | v1.0 | |
1483 | v1.0.1 | |
1484 | v1.1.3 | |
1485 | v2.0 | |
1486 | v3.0 | |
1487 | v4.0 | |
1488 | EOF | |
1489 | ||
1490 | test_expect_success 'checking that initial commit is in all tags' " | |
2dec68cf | 1491 | git tag -l --contains $hash1 v* >actual && |
32c35cfb JG |
1492 | test_cmp expected actual |
1493 | " | |
1494 | ||
6a338149 ÆAB |
1495 | test_expect_success 'checking that --contains can be used in non-list mode' ' |
1496 | git tag --contains $hash1 v* >actual && | |
1497 | test_cmp expected actual | |
1498 | ' | |
1499 | ||
e0e03a73 ST |
1500 | # mixing modes and options: |
1501 | ||
1502 | test_expect_success 'mixing incompatibles modes and options is forbidden' ' | |
2dec68cf | 1503 | test_must_fail git tag -a && |
bf748049 ÆAB |
1504 | test_must_fail git tag -a -l && |
1505 | test_must_fail git tag -s && | |
1506 | test_must_fail git tag -s -l && | |
1507 | test_must_fail git tag -m && | |
1508 | test_must_fail git tag -m -l && | |
1509 | test_must_fail git tag -m "hlagh" && | |
1510 | test_must_fail git tag -m "hlagh" -l && | |
1511 | test_must_fail git tag -F && | |
1512 | test_must_fail git tag -F -l && | |
1513 | test_must_fail git tag -f && | |
1514 | test_must_fail git tag -f -l && | |
1515 | test_must_fail git tag -a -s -m -F && | |
1516 | test_must_fail git tag -a -s -m -F -l && | |
2dec68cf | 1517 | test_must_fail git tag -l -v && |
bf748049 ÆAB |
1518 | test_must_fail git tag -l -d && |
1519 | test_must_fail git tag -l -v -d && | |
bf748049 | 1520 | test_must_fail git tag -n 100 -v && |
2dec68cf JN |
1521 | test_must_fail git tag -l -m msg && |
1522 | test_must_fail git tag -l -F some file && | |
b643827b ÆAB |
1523 | test_must_fail git tag -v -s && |
1524 | test_must_fail git tag --contains tag-tree && | |
1525 | test_must_fail git tag --contains tag-blob | |
e0e03a73 ST |
1526 | ' |
1527 | ||
6a338149 ÆAB |
1528 | for option in --contains --merged --no-merged --points-at |
1529 | do | |
1530 | test_expect_success "mixing incompatible modes with $option is forbidden" " | |
1531 | test_must_fail git tag -d $option HEAD && | |
1532 | test_must_fail git tag -d $option HEAD some-tag && | |
1533 | test_must_fail git tag -v $option HEAD | |
1534 | " | |
1535 | test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" " | |
1536 | git tag -n $option HEAD HEAD && | |
1537 | git tag $option HEAD HEAD | |
1538 | " | |
1539 | done | |
1540 | ||
ae7706b9 TG |
1541 | # check points-at |
1542 | ||
6a338149 ÆAB |
1543 | test_expect_success '--points-at can be used in non-list mode' ' |
1544 | echo v4.0 >expect && | |
1545 | git tag --points-at=v4.0 "v*" >actual && | |
1546 | test_cmp expect actual | |
ae7706b9 TG |
1547 | ' |
1548 | ||
1549 | test_expect_success '--points-at finds lightweight tags' ' | |
1550 | echo v4.0 >expect && | |
1551 | git tag --points-at v4.0 >actual && | |
1552 | test_cmp expect actual | |
1553 | ' | |
1554 | ||
1555 | test_expect_success '--points-at finds annotated tags of commits' ' | |
1556 | git tag -m "v4.0, annotated" annotated-v4.0 v4.0 && | |
1557 | echo annotated-v4.0 >expect && | |
1558 | git tag -l --points-at v4.0 "annotated*" >actual && | |
1559 | test_cmp expect actual | |
1560 | ' | |
1561 | ||
1562 | test_expect_success '--points-at finds annotated tags of tags' ' | |
1563 | git tag -m "describing the v4.0 tag object" \ | |
1564 | annotated-again-v4.0 annotated-v4.0 && | |
1565 | cat >expect <<-\EOF && | |
1566 | annotated-again-v4.0 | |
1567 | annotated-v4.0 | |
1568 | EOF | |
1569 | git tag --points-at=annotated-v4.0 >actual && | |
1570 | test_cmp expect actual | |
1571 | ' | |
1572 | ||
1573 | test_expect_success 'multiple --points-at are OR-ed together' ' | |
1574 | cat >expect <<-\EOF && | |
1575 | v2.0 | |
1576 | v3.0 | |
1577 | EOF | |
1578 | git tag --points-at=v2.0 --points-at=v3.0 >actual && | |
1579 | test_cmp expect actual | |
1580 | ' | |
1581 | ||
9ef176b5 NTND |
1582 | test_expect_success 'lexical sort' ' |
1583 | git tag foo1.3 && | |
1584 | git tag foo1.6 && | |
1585 | git tag foo1.10 && | |
1586 | git tag -l --sort=refname "foo*" >actual && | |
dc662d44 JK |
1587 | cat >expect <<-\EOF && |
1588 | foo1.10 | |
1589 | foo1.3 | |
1590 | foo1.6 | |
1591 | EOF | |
9ef176b5 NTND |
1592 | test_cmp expect actual |
1593 | ' | |
1594 | ||
1595 | test_expect_success 'version sort' ' | |
1596 | git tag -l --sort=version:refname "foo*" >actual && | |
dc662d44 JK |
1597 | cat >expect <<-\EOF && |
1598 | foo1.3 | |
1599 | foo1.6 | |
1600 | foo1.10 | |
1601 | EOF | |
9ef176b5 NTND |
1602 | test_cmp expect actual |
1603 | ' | |
1604 | ||
1605 | test_expect_success 'reverse version sort' ' | |
1606 | git tag -l --sort=-version:refname "foo*" >actual && | |
dc662d44 JK |
1607 | cat >expect <<-\EOF && |
1608 | foo1.10 | |
1609 | foo1.6 | |
1610 | foo1.3 | |
1611 | EOF | |
9ef176b5 NTND |
1612 | test_cmp expect actual |
1613 | ' | |
1614 | ||
1615 | test_expect_success 'reverse lexical sort' ' | |
1616 | git tag -l --sort=-refname "foo*" >actual && | |
dc662d44 JK |
1617 | cat >expect <<-\EOF && |
1618 | foo1.6 | |
1619 | foo1.3 | |
1620 | foo1.10 | |
1621 | EOF | |
9ef176b5 NTND |
1622 | test_cmp expect actual |
1623 | ' | |
1624 | ||
b150794d | 1625 | test_expect_success 'configured lexical sort' ' |
9ffda48f | 1626 | test_config tag.sort "v:refname" && |
b150794d JK |
1627 | git tag -l "foo*" >actual && |
1628 | cat >expect <<-\EOF && | |
1629 | foo1.3 | |
1630 | foo1.6 | |
1631 | foo1.10 | |
1632 | EOF | |
1633 | test_cmp expect actual | |
1634 | ' | |
1635 | ||
1636 | test_expect_success 'option override configured sort' ' | |
9ffda48f | 1637 | test_config tag.sort "v:refname" && |
b150794d JK |
1638 | git tag -l --sort=-refname "foo*" >actual && |
1639 | cat >expect <<-\EOF && | |
1640 | foo1.6 | |
1641 | foo1.3 | |
1642 | foo1.10 | |
1643 | EOF | |
1644 | test_cmp expect actual | |
1645 | ' | |
1646 | ||
1647 | test_expect_success 'invalid sort parameter on command line' ' | |
1648 | test_must_fail git tag -l --sort=notvalid "foo*" >actual | |
1649 | ' | |
1650 | ||
1651 | test_expect_success 'invalid sort parameter in configuratoin' ' | |
9ffda48f | 1652 | test_config tag.sort "v:notvalid" && |
b7cc53e9 | 1653 | test_must_fail git tag -l "foo*" |
b150794d JK |
1654 | ' |
1655 | ||
d811c8e1 | 1656 | test_expect_success 'version sort with prerelease reordering' ' |
9ffda48f | 1657 | test_config versionsort.prereleaseSuffix -rc && |
d811c8e1 NTND |
1658 | git tag foo1.6-rc1 && |
1659 | git tag foo1.6-rc2 && | |
1660 | git tag -l --sort=version:refname "foo*" >actual && | |
1661 | cat >expect <<-\EOF && | |
1662 | foo1.3 | |
1663 | foo1.6-rc1 | |
1664 | foo1.6-rc2 | |
1665 | foo1.6 | |
1666 | foo1.10 | |
1667 | EOF | |
1668 | test_cmp expect actual | |
1669 | ' | |
1670 | ||
1671 | test_expect_success 'reverse version sort with prerelease reordering' ' | |
9ffda48f | 1672 | test_config versionsort.prereleaseSuffix -rc && |
d811c8e1 NTND |
1673 | git tag -l --sort=-version:refname "foo*" >actual && |
1674 | cat >expect <<-\EOF && | |
1675 | foo1.10 | |
1676 | foo1.6 | |
1677 | foo1.6-rc2 | |
1678 | foo1.6-rc1 | |
1679 | foo1.3 | |
1680 | EOF | |
1681 | test_cmp expect actual | |
1682 | ' | |
1683 | ||
b8231660 | 1684 | test_expect_success 'version sort with prerelease reordering and common leading character' ' |
0c1b4878 SG |
1685 | test_config versionsort.prereleaseSuffix -before && |
1686 | git tag foo1.7-before1 && | |
1687 | git tag foo1.7 && | |
1688 | git tag foo1.7-after1 && | |
1689 | git tag -l --sort=version:refname "foo1.7*" >actual && | |
1690 | cat >expect <<-\EOF && | |
1691 | foo1.7-before1 | |
1692 | foo1.7 | |
1693 | foo1.7-after1 | |
1694 | EOF | |
1695 | test_cmp expect actual | |
1696 | ' | |
1697 | ||
b8231660 | 1698 | test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' ' |
0c1b4878 SG |
1699 | test_config versionsort.prereleaseSuffix -before && |
1700 | git config --add versionsort.prereleaseSuffix -after && | |
1701 | git tag -l --sort=version:refname "foo1.7*" >actual && | |
1702 | cat >expect <<-\EOF && | |
1703 | foo1.7-before1 | |
1704 | foo1.7-after1 | |
1705 | foo1.7 | |
1706 | EOF | |
1707 | test_cmp expect actual | |
1708 | ' | |
1709 | ||
51acfa9d SG |
1710 | test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' ' |
1711 | test_config versionsort.prereleaseSuffix -bar && | |
1712 | git config --add versionsort.prereleaseSuffix -foo-baz && | |
1713 | git config --add versionsort.prereleaseSuffix -foo-bar && | |
1714 | git tag foo1.8-foo-bar && | |
1715 | git tag foo1.8-foo-baz && | |
1716 | git tag foo1.8 && | |
1717 | git tag -l --sort=version:refname "foo1.8*" >actual && | |
1718 | cat >expect <<-\EOF && | |
1719 | foo1.8-foo-baz | |
1720 | foo1.8-foo-bar | |
1721 | foo1.8 | |
1722 | EOF | |
1723 | test_cmp expect actual | |
1724 | ' | |
1725 | ||
1726 | test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' ' | |
1727 | test_config versionsort.prereleaseSuffix -pre && | |
1728 | git config --add versionsort.prereleaseSuffix -prerelease && | |
1729 | git tag foo1.9-pre1 && | |
1730 | git tag foo1.9-pre2 && | |
1731 | git tag foo1.9-prerelease1 && | |
1732 | git tag -l --sort=version:refname "foo1.9*" >actual && | |
1733 | cat >expect <<-\EOF && | |
1734 | foo1.9-pre1 | |
1735 | foo1.9-pre2 | |
1736 | foo1.9-prerelease1 | |
1737 | EOF | |
1738 | test_cmp expect actual | |
1739 | ' | |
1740 | ||
c026557a SG |
1741 | test_expect_success 'version sort with general suffix reordering' ' |
1742 | test_config versionsort.suffix -alpha && | |
1743 | git config --add versionsort.suffix -beta && | |
1744 | git config --add versionsort.suffix "" && | |
1745 | git config --add versionsort.suffix -gamma && | |
1746 | git config --add versionsort.suffix -delta && | |
1747 | git tag foo1.10-alpha && | |
1748 | git tag foo1.10-beta && | |
1749 | git tag foo1.10-gamma && | |
1750 | git tag foo1.10-delta && | |
1751 | git tag foo1.10-unlisted-suffix && | |
1752 | git tag -l --sort=version:refname "foo1.10*" >actual && | |
1753 | cat >expect <<-\EOF && | |
1754 | foo1.10-alpha | |
1755 | foo1.10-beta | |
1756 | foo1.10 | |
1757 | foo1.10-unlisted-suffix | |
1758 | foo1.10-gamma | |
1759 | foo1.10-delta | |
1760 | EOF | |
1761 | test_cmp expect actual | |
1762 | ' | |
1763 | ||
1764 | test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' ' | |
1765 | test_config versionsort.suffix -before && | |
1766 | test_config versionsort.prereleaseSuffix -after && | |
1767 | git tag -l --sort=version:refname "foo1.7*" >actual && | |
1768 | cat >expect <<-\EOF && | |
1769 | foo1.7-before1 | |
1770 | foo1.7 | |
1771 | foo1.7-after1 | |
1772 | EOF | |
1773 | test_cmp expect actual | |
1774 | ' | |
1775 | ||
b8231660 SG |
1776 | test_expect_success 'version sort with very long prerelease suffix' ' |
1777 | test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix && | |
1778 | git tag -l --sort=version:refname | |
1779 | ' | |
1780 | ||
cbc60b67 | 1781 | run_with_limited_stack () { |
b9a19078 | 1782 | (ulimit -s 128 && "$@") |
cbc60b67 JJL |
1783 | } |
1784 | ||
fc38a9bb | 1785 | test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true' |
cbc60b67 JJL |
1786 | |
1787 | # we require ulimit, this excludes Windows | |
fc38a9bb | 1788 | test_expect_success ULIMIT_STACK_SIZE '--contains works in a deep repo' ' |
cbc60b67 JJL |
1789 | >expect && |
1790 | i=1 && | |
b9a19078 | 1791 | while test $i -lt 8000 |
cbc60b67 JJL |
1792 | do |
1793 | echo "commit refs/heads/master | |
1794 | committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200 | |
1795 | data <<EOF | |
1796 | commit #$i | |
1797 | EOF" | |
1798 | test $i = 1 && echo "from refs/heads/master^0" | |
1799 | i=$(($i + 1)) | |
1800 | done | git fast-import && | |
1801 | git checkout master && | |
1802 | git tag far-far-away HEAD^ && | |
1803 | run_with_limited_stack git tag --contains HEAD >actual && | |
1804 | test_cmp expect actual | |
1805 | ' | |
1806 | ||
df094741 KN |
1807 | test_expect_success '--format should list tags as per format given' ' |
1808 | cat >expect <<-\EOF && | |
0c1b4878 SG |
1809 | refname : refs/tags/v1.0 |
1810 | refname : refs/tags/v1.0.1 | |
1811 | refname : refs/tags/v1.1.3 | |
df094741 | 1812 | EOF |
0c1b4878 | 1813 | git tag -l --format="refname : %(refname)" "v1*" >actual && |
df094741 KN |
1814 | test_cmp expect actual |
1815 | ' | |
1816 | ||
5242860f KN |
1817 | test_expect_success 'setup --merged test tags' ' |
1818 | git tag mergetest-1 HEAD~2 && | |
1819 | git tag mergetest-2 HEAD~1 && | |
1820 | git tag mergetest-3 HEAD | |
1821 | ' | |
1822 | ||
6a338149 ÆAB |
1823 | test_expect_success '--merged can be used in non-list mode' ' |
1824 | cat >expect <<-\EOF && | |
1825 | mergetest-1 | |
1826 | mergetest-2 | |
1827 | EOF | |
1828 | git tag --merged=mergetest-2 "mergetest*" >actual && | |
1829 | test_cmp expect actual | |
5242860f KN |
1830 | ' |
1831 | ||
17d6c744 ÆAB |
1832 | test_expect_success '--merged is incompatible with --no-merged' ' |
1833 | test_must_fail git tag --merged HEAD --no-merged HEAD | |
1834 | ' | |
1835 | ||
5242860f KN |
1836 | test_expect_success '--merged shows merged tags' ' |
1837 | cat >expect <<-\EOF && | |
1838 | mergetest-1 | |
1839 | mergetest-2 | |
1840 | EOF | |
1841 | git tag -l --merged=mergetest-2 mergetest-* >actual && | |
1842 | test_cmp expect actual | |
1843 | ' | |
1844 | ||
1845 | test_expect_success '--no-merged show unmerged tags' ' | |
1846 | cat >expect <<-\EOF && | |
1847 | mergetest-3 | |
1848 | EOF | |
1849 | git tag -l --no-merged=mergetest-2 mergetest-* >actual && | |
1850 | test_cmp expect actual | |
1851 | ' | |
1852 | ||
6a338149 ÆAB |
1853 | test_expect_success '--no-merged can be used in non-list mode' ' |
1854 | git tag --no-merged=mergetest-2 mergetest-* >actual && | |
1855 | test_cmp expect actual | |
1856 | ' | |
1857 | ||
0571979b JK |
1858 | test_expect_success 'ambiguous branch/tags not marked' ' |
1859 | git tag ambiguous && | |
1860 | git branch ambiguous && | |
1861 | echo ambiguous >expect && | |
1862 | git tag -l ambiguous >actual && | |
1863 | test_cmp expect actual | |
1864 | ' | |
1865 | ||
ef5a6fb5 | 1866 | test_done |