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