t7004-tag.sh 52.6 KB
Newer Older
C
Carlos Rica 已提交
1 2 3 4 5
#!/bin/sh
#
# Copyright (c) 2007 Carlos Rica
#

6
test_description='git tag
C
Carlos Rica 已提交
7

C
Carlos Rica 已提交
8
Tests for operations with tags.'
C
Carlos Rica 已提交
9 10

. ./test-lib.sh
J
Jeff King 已提交
11
. "$TEST_DIRECTORY"/lib-gpg.sh
C
Carlos Rica 已提交
12 13 14 15 16 17 18

# creating and listing lightweight tags:

tag_exists () {
	git show-ref --quiet --verify refs/tags/"$1"
}

C
Carlos Rica 已提交
19 20 21 22
test_expect_success 'listing all tags in an empty tree should succeed' '
	git tag -l &&
	git tag
'
C
Carlos Rica 已提交
23

C
Carlos Rica 已提交
24
test_expect_success 'listing all tags in an empty tree should output nothing' '
25 26
	test $(git tag -l | wc -l) -eq 0 &&
	test $(git tag | wc -l) -eq 0
C
Carlos Rica 已提交
27
'
C
Carlos Rica 已提交
28

29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
test_expect_success 'sort tags, ignore case' '
	(
		git init sort &&
		cd sort &&
		test_commit initial &&
		git tag tag-one &&
		git tag TAG-two &&
		git tag -l >actual &&
		cat >expected <<-\EOF &&
		TAG-two
		initial
		tag-one
		EOF
		test_cmp expected actual &&
		git tag -l -i >actual &&
		cat >expected <<-\EOF &&
		initial
		tag-one
		TAG-two
		EOF
		test_cmp expected actual
	)
'

J
Junio C Hamano 已提交
53 54
test_expect_success 'looking for a tag in an empty tree should fail' \
	'! (tag_exists mytag)'
C
Carlos Rica 已提交
55 56

test_expect_success 'creating a tag in an empty tree should fail' '
57
	test_must_fail git tag mynotag &&
C
Carlos Rica 已提交
58 59 60 61
	! tag_exists mynotag
'

test_expect_success 'creating a tag for HEAD in an empty tree should fail' '
62
	test_must_fail git tag mytaghead HEAD &&
C
Carlos Rica 已提交
63 64 65 66
	! tag_exists mytaghead
'

test_expect_success 'creating a tag for an unknown revision should fail' '
67
	test_must_fail git tag mytagnorev aaaaaaaaaaa &&
C
Carlos Rica 已提交
68 69 70 71 72
	! tag_exists mytagnorev
'

# commit used in the tests, test_tick is also called here to freeze the date:
test_expect_success 'creating a tag using default HEAD should succeed' '
73
	test_config core.logAllRefUpdates true &&
C
Carlos Rica 已提交
74 75 76 77
	test_tick &&
	echo foo >foo &&
	git add foo &&
	git commit -m Foo &&
78 79 80 81 82
	git tag mytag &&
	test_must_fail git reflog exists refs/tags/mytag
'

test_expect_success 'creating a tag with --create-reflog should create reflog' '
83 84 85
	git log -1 \
		--format="format:tag: tagging %h (%s, %cd)%n" \
		--date=format:%Y-%m-%d >expected &&
86 87
	test_when_finished "git tag -d tag_with_reflog" &&
	git tag --create-reflog tag_with_reflog &&
88 89 90 91 92 93 94 95 96 97 98 99 100 101
	git reflog exists refs/tags/tag_with_reflog &&
	sed -e "s/^.*	//" .git/logs/refs/tags/tag_with_reflog >actual &&
	test_cmp expected actual
'

test_expect_success 'annotated tag with --create-reflog has correct message' '
	git log -1 \
		--format="format:tag: tagging %h (%s, %cd)%n" \
		--date=format:%Y-%m-%d >expected &&
	test_when_finished "git tag -d tag_with_reflog" &&
	git tag -m "annotated tag" --create-reflog tag_with_reflog &&
	git reflog exists refs/tags/tag_with_reflog &&
	sed -e "s/^.*	//" .git/logs/refs/tags/tag_with_reflog >actual &&
	test_cmp expected actual
102 103 104 105 106
'

test_expect_success '--create-reflog does not create reflog on failure' '
	test_must_fail git tag --create-reflog mytag &&
	test_must_fail git reflog exists refs/tags/mytag
C
Carlos Rica 已提交
107 108
'

109 110 111 112 113 114 115
test_expect_success 'option core.logAllRefUpdates=always creates reflog' '
	test_when_finished "git tag -d tag_with_reflog" &&
	test_config core.logAllRefUpdates always &&
	git tag tag_with_reflog &&
	git reflog exists refs/tags/tag_with_reflog
'

C
Carlos Rica 已提交
116
test_expect_success 'listing all tags if one exists should succeed' '
117 118
	git tag -l &&
	git tag
C
Carlos Rica 已提交
119
'
C
Carlos Rica 已提交
120

121 122 123 124 125 126 127 128 129 130 131 132
cat >expect <<EOF
mytag
EOF
test_expect_success 'Multiple -l or --list options are equivalent to one -l option' '
	git tag -l -l >actual &&
	test_cmp expect actual &&
	git tag --list --list >actual &&
	test_cmp expect actual &&
	git tag --list -l --list >actual &&
	test_cmp expect actual
'

C
Carlos Rica 已提交
133
test_expect_success 'listing all tags if one exists should output that tag' '
134 135
	test $(git tag -l) = mytag &&
	test $(git tag) = mytag
C
Carlos Rica 已提交
136
'
C
Carlos Rica 已提交
137 138 139 140

# pattern matching:

test_expect_success 'listing a tag using a matching pattern should succeed' \
141
	'git tag -l mytag'
C
Carlos Rica 已提交
142

143 144 145
test_expect_success 'listing a tag with --ignore-case' \
	'test $(git tag -l --ignore-case MYTAG) = mytag'

C
Carlos Rica 已提交
146 147
test_expect_success \
	'listing a tag using a matching pattern should output that tag' \
148
	'test $(git tag -l mytag) = mytag'
C
Carlos Rica 已提交
149 150

test_expect_success \
151
	'listing tags using a non-matching pattern should succeed' \
152
	'git tag -l xxx'
C
Carlos Rica 已提交
153 154 155

test_expect_success \
	'listing tags using a non-matching pattern should output nothing' \
156
	'test $(git tag -l xxx | wc -l) -eq 0'
C
Carlos Rica 已提交
157 158 159

# special cases for creating tags:

J
Junio C Hamano 已提交
160
test_expect_success \
C
Carlos Rica 已提交
161
	'trying to create a tag with the name of one existing should fail' \
162
	'test_must_fail git tag mytag'
C
Carlos Rica 已提交
163 164 165

test_expect_success \
	'trying to create a tag with a non-valid name should fail' '
166
	test $(git tag -l | wc -l) -eq 1 &&
167 168 169 170 171
	test_must_fail git tag "" &&
	test_must_fail git tag .othertag &&
	test_must_fail git tag "other tag" &&
	test_must_fail git tag "othertag^" &&
	test_must_fail git tag "other~tag" &&
172
	test $(git tag -l | wc -l) -eq 1
C
Carlos Rica 已提交
173 174 175 176 177 178 179
'

test_expect_success 'creating a tag using HEAD directly should succeed' '
	git tag myhead HEAD &&
	tag_exists myhead
'

180 181 182 183 184 185
test_expect_success '--force can create a tag with the name of one existing' '
	tag_exists mytag &&
	git tag --force mytag &&
	tag_exists mytag'

test_expect_success '--force is moot with a non-existing tag name' '
186
	test_when_finished git tag -d newtag forcetag &&
187 188 189 190 191
	git tag newtag >expect &&
	git tag --force forcetag >actual &&
	test_cmp expect actual
'

C
Carlos Rica 已提交
192 193 194 195
# deleting tags:

test_expect_success 'trying to delete an unknown tag should fail' '
	! tag_exists unknown-tag &&
196
	test_must_fail git tag -d unknown-tag
C
Carlos Rica 已提交
197 198 199 200 201 202 203 204
'

cat >expect <<EOF
myhead
mytag
EOF
test_expect_success \
	'trying to delete tags without params should succeed and do nothing' '
205
	git tag -l > actual && test_cmp expect actual &&
206
	git tag -d &&
207
	git tag -l > actual && test_cmp expect actual
C
Carlos Rica 已提交
208 209 210 211 212 213
'

test_expect_success \
	'deleting two existing tags in one command should succeed' '
	tag_exists mytag &&
	tag_exists myhead &&
214
	git tag -d mytag myhead &&
C
Carlos Rica 已提交
215 216 217 218 219 220 221
	! tag_exists mytag &&
	! tag_exists myhead
'

test_expect_success \
	'creating a tag with the name of another deleted one should succeed' '
	! tag_exists mytag &&
222
	git tag mytag &&
C
Carlos Rica 已提交
223 224 225 226 227 228 229
	tag_exists mytag
'

test_expect_success \
	'trying to delete two tags, existing and not, should fail in the 2nd' '
	tag_exists mytag &&
	! tag_exists myhead &&
230
	test_must_fail git tag -d mytag anothertag &&
C
Carlos Rica 已提交
231 232 233 234
	! tag_exists mytag &&
	! tag_exists myhead
'

J
Junio C Hamano 已提交
235
test_expect_success 'trying to delete an already deleted tag should fail' \
236
	'test_must_fail git tag -d mytag'
C
Carlos Rica 已提交
237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260

# listing various tags with pattern matching:

cat >expect <<EOF
a1
aa1
cba
t210
t211
v0.2.1
v1.0
v1.0.1
v1.1.3
EOF
test_expect_success 'listing all tags should print them ordered' '
	git tag v1.0.1 &&
	git tag t211 &&
	git tag aa1 &&
	git tag v0.2.1 &&
	git tag v1.1.3 &&
	git tag cba &&
	git tag a1 &&
	git tag v1.0 &&
	git tag t210 &&
261
	git tag -l > actual &&
262
	test_cmp expect actual &&
C
Carlos Rica 已提交
263
	git tag > actual &&
264
	test_cmp expect actual
C
Carlos Rica 已提交
265 266 267 268 269 270 271 272 273
'

cat >expect <<EOF
a1
aa1
cba
EOF
test_expect_success \
	'listing tags with substring as pattern must print those matching' '
274 275 276
	rm *a* &&
	git tag -l "*a*" > current &&
	test_cmp expect current
C
Carlos Rica 已提交
277 278 279 280 281 282 283
'

cat >expect <<EOF
v0.2.1
v1.0.1
EOF
test_expect_success \
284
	'listing tags with a suffix as pattern must print those matching' '
285
	git tag -l "*.1" > actual &&
286
	test_cmp expect actual
C
Carlos Rica 已提交
287 288 289 290 291 292 293
'

cat >expect <<EOF
t210
t211
EOF
test_expect_success \
294
	'listing tags with a prefix as pattern must print those matching' '
295
	git tag -l "t21*" > actual &&
296
	test_cmp expect actual
C
Carlos Rica 已提交
297 298 299 300 301 302
'

cat >expect <<EOF
a1
EOF
test_expect_success \
303
	'listing tags using a name as pattern must print that one matching' '
304
	git tag -l a1 > actual &&
305
	test_cmp expect actual
C
Carlos Rica 已提交
306 307 308 309 310 311
'

cat >expect <<EOF
v1.0
EOF
test_expect_success \
312
	'listing tags using a name as pattern must print that one matching' '
313
	git tag -l v1.0 > actual &&
314
	test_cmp expect actual
C
Carlos Rica 已提交
315 316 317
'

cat >expect <<EOF
318
v1.0.1
C
Carlos Rica 已提交
319 320 321 322
v1.1.3
EOF
test_expect_success \
	'listing tags with ? in the pattern should print those matching' '
323
	git tag -l "v1.?.?" > actual &&
324
	test_cmp expect actual
C
Carlos Rica 已提交
325 326 327 328 329
'

>expect
test_expect_success \
	'listing tags using v.* should print nothing because none have v.' '
330
	git tag -l "v.*" > actual &&
331
	test_cmp expect actual
C
Carlos Rica 已提交
332 333 334 335 336 337 338 339 340 341
'

cat >expect <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
EOF
test_expect_success \
	'listing tags using v* should print only those having v' '
342
	git tag -l "v*" > actual &&
343
	test_cmp expect actual
C
Carlos Rica 已提交
344 345
'

346 347 348 349 350
test_expect_success 'tag -l can accept multiple patterns' '
	git tag -l "v1*" "v0*" >actual &&
	test_cmp expect actual
'

351 352 353 354 355 356 357 358 359 360 361 362 363
# Between v1.7.7 & v2.13.0 a fair reading of the git-tag documentation
# could leave you with the impression that "-l <pattern> -l <pattern>"
# was how we wanted to accept multiple patterns.
#
# This test should not imply that this is a sane thing to support. but
# since the documentation was worded like it was let's at least find
# out if we're going to break this long-documented form of taking
# multiple patterns.
test_expect_success 'tag -l <pattern> -l <pattern> works, as our buggy documentation previously suggested' '
	git tag -l "v1*" -l "v0*" >actual &&
	test_cmp expect actual
'

N
Nguyễn Thái Ngọc Duy 已提交
364 365 366 367 368 369 370 371 372 373
test_expect_success 'listing tags in column' '
	COLUMNS=40 git tag -l --column=row >actual &&
	cat >expected <<\EOF &&
a1      aa1     cba     t210    t211
v0.2.1  v1.0    v1.0.1  v1.1.3
EOF
	test_cmp expected actual
'

test_expect_success 'listing tags in column with column.*' '
S
SZEDER Gábor 已提交
374 375
	test_config column.tag row &&
	test_config column.ui dense &&
N
Nguyễn Thái Ngọc Duy 已提交
376 377 378 379 380 381 382 383 384 385 386 387 388
	COLUMNS=40 git tag -l >actual &&
	cat >expected <<\EOF &&
a1      aa1   cba     t210    t211
v0.2.1  v1.0  v1.0.1  v1.1.3
EOF
	test_cmp expected actual
'

test_expect_success 'listing tag with -n --column should fail' '
	test_must_fail git tag --column -n
'

test_expect_success 'listing tags -n in column with column.ui ignored' '
S
SZEDER Gábor 已提交
389
	test_config column.ui "row dense" &&
N
Nguyễn Thái Ngọc Duy 已提交
390 391 392 393 394 395 396 397 398 399 400 401 402 403 404
	COLUMNS=40 git tag -l -n >actual &&
	cat >expected <<\EOF &&
a1              Foo
aa1             Foo
cba             Foo
t210            Foo
t211            Foo
v0.2.1          Foo
v1.0            Foo
v1.0.1          Foo
v1.1.3          Foo
EOF
	test_cmp expected actual
'

C
Carlos Rica 已提交
405 406 407 408
# creating and verifying lightweight tags:

test_expect_success \
	'a non-annotated tag created without parameters should point to HEAD' '
409
	git tag non-annotated-tag &&
410 411
	test $(git cat-file -t non-annotated-tag) = commit &&
	test $(git rev-parse non-annotated-tag) = $(git rev-parse HEAD)
C
Carlos Rica 已提交
412 413
'

J
Junio C Hamano 已提交
414
test_expect_success 'trying to verify an unknown tag should fail' \
415
	'test_must_fail git tag -v unknown-tag'
C
Carlos Rica 已提交
416

J
Junio C Hamano 已提交
417
test_expect_success \
C
Carlos Rica 已提交
418
	'trying to verify a non-annotated and non-signed tag should fail' \
419
	'test_must_fail git tag -v non-annotated-tag'
C
Carlos Rica 已提交
420

J
Junio C Hamano 已提交
421
test_expect_success \
C
Carlos Rica 已提交
422
	'trying to verify many non-annotated or unknown tags, should fail' \
423
	'test_must_fail git tag -v unknown-tag1 non-annotated-tag unknown-tag2'
C
Carlos Rica 已提交
424

C
Carlos Rica 已提交
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448
# creating annotated tags:

get_tag_msg () {
	git cat-file tag "$1" | sed -e "/BEGIN PGP/q"
}

# run test_tick before committing always gives the time in that timezone
get_tag_header () {
cat <<EOF
object $2
type $3
tag $1
tagger C O Mitter <committer@example.com> $4 -0700

EOF
}

commit=$(git rev-parse HEAD)
time=$test_tick

get_tag_header annotated-tag $commit commit $time >expect
echo "A message" >>expect
test_expect_success \
	'creating an annotated tag with -m message should succeed' '
449
	git tag -m "A message" annotated-tag &&
C
Carlos Rica 已提交
450
	get_tag_msg annotated-tag >actual &&
451
	test_cmp expect actual
C
Carlos Rica 已提交
452 453 454 455 456 457 458 459 460 461
'

cat >msgfile <<EOF
Another message
in a file.
EOF
get_tag_header file-annotated-tag $commit commit $time >expect
cat msgfile >>expect
test_expect_success \
	'creating an annotated tag with -F messagefile should succeed' '
462
	git tag -F msgfile file-annotated-tag &&
C
Carlos Rica 已提交
463
	get_tag_msg file-annotated-tag >actual &&
464
	test_cmp expect actual
C
Carlos Rica 已提交
465 466
'

C
Carlos Rica 已提交
467 468 469 470 471 472 473
cat >inputmsg <<EOF
A message from the
standard input
EOF
get_tag_header stdin-annotated-tag $commit commit $time >expect
cat inputmsg >>expect
test_expect_success 'creating an annotated tag with -F - should succeed' '
474
	git tag -F - stdin-annotated-tag <inputmsg &&
C
Carlos Rica 已提交
475
	get_tag_msg stdin-annotated-tag >actual &&
476
	test_cmp expect actual
C
Carlos Rica 已提交
477 478
'

479 480 481 482
test_expect_success \
	'trying to create a tag with a non-existing -F file should fail' '
	! test -f nonexistingfile &&
	! tag_exists notag &&
483
	test_must_fail git tag -F nonexistingfile notag &&
484 485 486 487
	! tag_exists notag
'

test_expect_success \
488
	'trying to create tags giving both -m or -F options should fail' '
489 490 491
	echo "message file 1" >msgfile1 &&
	echo "message file 2" >msgfile2 &&
	! tag_exists msgtag &&
492
	test_must_fail git tag -m "message 1" -F msgfile1 msgtag &&
493
	! tag_exists msgtag &&
494
	test_must_fail git tag -F msgfile1 -m "message 1" msgtag &&
495
	! tag_exists msgtag &&
496
	test_must_fail git tag -m "message 1" -F msgfile1 \
497
		-m "message 2" msgtag &&
498 499 500
	! tag_exists msgtag
'

C
Carlos Rica 已提交
501 502 503 504 505
# blank and empty messages:

get_tag_header empty-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with an empty -m message should succeed' '
506
	git tag -m "" empty-annotated-tag &&
C
Carlos Rica 已提交
507
	get_tag_msg empty-annotated-tag >actual &&
508
	test_cmp expect actual
C
Carlos Rica 已提交
509 510 511 512 513 514
'

>emptyfile
get_tag_header emptyfile-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with an empty -F messagefile should succeed' '
515
	git tag -F emptyfile emptyfile-annotated-tag &&
C
Carlos Rica 已提交
516
	get_tag_msg emptyfile-annotated-tag >actual &&
517
	test_cmp expect actual
C
Carlos Rica 已提交
518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535
'

printf '\n\n  \n\t\nLeading blank lines\n' >blanksfile
printf '\n\t \t  \nRepeated blank lines\n' >>blanksfile
printf '\n\n\nTrailing spaces      \t  \n' >>blanksfile
printf '\nTrailing blank lines\n\n\t \n\n' >>blanksfile
get_tag_header blanks-annotated-tag $commit commit $time >expect
cat >>expect <<EOF
Leading blank lines

Repeated blank lines

Trailing spaces

Trailing blank lines
EOF
test_expect_success \
	'extra blanks in the message for an annotated tag should be removed' '
536
	git tag -F blanksfile blanks-annotated-tag &&
C
Carlos Rica 已提交
537
	get_tag_msg blanks-annotated-tag >actual &&
538
	test_cmp expect actual
C
Carlos Rica 已提交
539 540 541 542 543
'

get_tag_header blank-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with blank -m message with spaces should succeed' '
544
	git tag -m "     " blank-annotated-tag &&
C
Carlos Rica 已提交
545
	get_tag_msg blank-annotated-tag >actual &&
546
	test_cmp expect actual
C
Carlos Rica 已提交
547 548 549 550 551 552 553 554
'

echo '     ' >blankfile
echo ''      >>blankfile
echo '  '    >>blankfile
get_tag_header blankfile-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with blank -F messagefile with spaces should succeed' '
555
	git tag -F blankfile blankfile-annotated-tag &&
C
Carlos Rica 已提交
556
	get_tag_msg blankfile-annotated-tag >actual &&
557
	test_cmp expect actual
C
Carlos Rica 已提交
558 559 560 561 562 563
'

printf '      ' >blanknonlfile
get_tag_header blanknonlfile-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with -F file of spaces and no newline should succeed' '
564
	git tag -F blanknonlfile blanknonlfile-annotated-tag &&
C
Carlos Rica 已提交
565
	get_tag_msg blanknonlfile-annotated-tag >actual &&
566
	test_cmp expect actual
C
Carlos Rica 已提交
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598
'

# messages with commented lines:

cat >commentsfile <<EOF
# A comment

############
The message.
############
One line.


# commented lines
# commented lines

Another line.
# comments

Last line.
EOF
get_tag_header comments-annotated-tag $commit commit $time >expect
cat >>expect <<EOF
The message.
One line.

Another line.

Last line.
EOF
test_expect_success \
	'creating a tag using a -F messagefile with #comments should succeed' '
599
	git tag -F commentsfile comments-annotated-tag &&
C
Carlos Rica 已提交
600
	get_tag_msg comments-annotated-tag >actual &&
601
	test_cmp expect actual
C
Carlos Rica 已提交
602 603 604 605 606
'

get_tag_header comment-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with a #comment in the -m message should succeed' '
607
	git tag -m "#comment" comment-annotated-tag &&
C
Carlos Rica 已提交
608
	get_tag_msg comment-annotated-tag >actual &&
609
	test_cmp expect actual
C
Carlos Rica 已提交
610 611 612 613 614 615 616 617
'

echo '#comment' >commentfile
echo ''         >>commentfile
echo '####'     >>commentfile
get_tag_header commentfile-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with #comments in the -F messagefile should succeed' '
618
	git tag -F commentfile commentfile-annotated-tag &&
C
Carlos Rica 已提交
619
	get_tag_msg commentfile-annotated-tag >actual &&
620
	test_cmp expect actual
C
Carlos Rica 已提交
621 622 623 624 625 626
'

printf '#comment' >commentnonlfile
get_tag_header commentnonlfile-annotated-tag $commit commit $time >expect
test_expect_success \
	'creating a tag with a file of #comment and no newline should succeed' '
627
	git tag -F commentnonlfile commentnonlfile-annotated-tag &&
C
Carlos Rica 已提交
628
	get_tag_msg commentnonlfile-annotated-tag >actual &&
629
	test_cmp expect actual
C
Carlos Rica 已提交
630 631
'

632 633 634 635
# listing messages for annotated non-signed tags:

test_expect_success \
	'listing the one-line message of a non-signed tag should succeed' '
636
	git tag -m "A msg" tag-one-line &&
637 638

	echo "tag-one-line" >expect &&
639
	git tag -l | grep "^tag-one-line" >actual &&
640
	test_cmp expect actual &&
641
	git tag -n0 -l | grep "^tag-one-line" >actual &&
642
	test_cmp expect actual &&
643
	git tag -n0 -l tag-one-line >actual &&
644
	test_cmp expect actual &&
645

646 647 648 649 650
	git tag -n0 | grep "^tag-one-line" >actual &&
	test_cmp expect actual &&
	git tag -n0 tag-one-line >actual &&
	test_cmp expect actual &&

651
	echo "tag-one-line    A msg" >expect &&
652
	git tag -n1 -l | grep "^tag-one-line" >actual &&
653
	test_cmp expect actual &&
654
	git tag -n -l | grep "^tag-one-line" >actual &&
655
	test_cmp expect actual &&
656
	git tag -n1 -l tag-one-line >actual &&
657
	test_cmp expect actual &&
658
	git tag -n2 -l tag-one-line >actual &&
659
	test_cmp expect actual &&
660
	git tag -n999 -l tag-one-line >actual &&
661
	test_cmp expect actual
662 663
'

664 665 666 667 668 669 670 671 672 673 674
test_expect_success 'The -n 100 invocation means -n --list 100, not -n100' '
	>expect &&
	git tag -n 100 >actual &&
	test_cmp expect actual &&

	git tag -m "A msg" 100 &&
	echo "100             A msg" >expect &&
	git tag -n 100 >actual &&
	test_cmp expect actual
'

675 676
test_expect_success \
	'listing the zero-lines message of a non-signed tag should succeed' '
677
	git tag -m "" tag-zero-lines &&
678 679

	echo "tag-zero-lines" >expect &&
680
	git tag -l | grep "^tag-zero-lines" >actual &&
681
	test_cmp expect actual &&
682
	git tag -n0 -l | grep "^tag-zero-lines" >actual &&
683
	test_cmp expect actual &&
684
	git tag -n0 -l tag-zero-lines >actual &&
685
	test_cmp expect actual &&
686 687

	echo "tag-zero-lines  " >expect &&
688
	git tag -n1 -l | grep "^tag-zero-lines" >actual &&
689
	test_cmp expect actual &&
690
	git tag -n -l | grep "^tag-zero-lines" >actual &&
691
	test_cmp expect actual &&
692
	git tag -n1 -l tag-zero-lines >actual &&
693
	test_cmp expect actual &&
694
	git tag -n2 -l tag-zero-lines >actual &&
695
	test_cmp expect actual &&
696
	git tag -n999 -l tag-zero-lines >actual &&
697
	test_cmp expect actual
698 699 700 701 702 703 704
'

echo 'tag line one' >annotagmsg
echo 'tag line two' >>annotagmsg
echo 'tag line three' >>annotagmsg
test_expect_success \
	'listing many message lines of a non-signed tag should succeed' '
705
	git tag -F annotagmsg tag-lines &&
706 707

	echo "tag-lines" >expect &&
708
	git tag -l | grep "^tag-lines" >actual &&
709
	test_cmp expect actual &&
710
	git tag -n0 -l | grep "^tag-lines" >actual &&
711
	test_cmp expect actual &&
712
	git tag -n0 -l tag-lines >actual &&
713
	test_cmp expect actual &&
714 715

	echo "tag-lines       tag line one" >expect &&
716
	git tag -n1 -l | grep "^tag-lines" >actual &&
717
	test_cmp expect actual &&
718
	git tag -n -l | grep "^tag-lines" >actual &&
719
	test_cmp expect actual &&
720
	git tag -n1 -l tag-lines >actual &&
721
	test_cmp expect actual &&
722 723

	echo "    tag line two" >>expect &&
724
	git tag -n2 -l | grep "^ *tag.line" >actual &&
725
	test_cmp expect actual &&
726
	git tag -n2 -l tag-lines >actual &&
727
	test_cmp expect actual &&
728 729

	echo "    tag line three" >>expect &&
730
	git tag -n3 -l | grep "^ *tag.line" >actual &&
731
	test_cmp expect actual &&
732
	git tag -n3 -l tag-lines >actual &&
733
	test_cmp expect actual &&
734
	git tag -n4 -l | grep "^ *tag.line" >actual &&
735
	test_cmp expect actual &&
736
	git tag -n4 -l tag-lines >actual &&
737
	test_cmp expect actual &&
738
	git tag -n99 -l | grep "^ *tag.line" >actual &&
739
	test_cmp expect actual &&
740
	git tag -n99 -l tag-lines >actual &&
741
	test_cmp expect actual
742 743
'

744 745 746 747 748 749 750 751 752 753 754 755 756
test_expect_success 'annotations for blobs are empty' '
	blob=$(git hash-object -w --stdin <<-\EOF
	Blob paragraph 1.

	Blob paragraph 2.
	EOF
	) &&
	git tag tag-blob $blob &&
	echo "tag-blob        " >expect &&
	git tag -n1 -l tag-blob >actual &&
	test_cmp expect actual
'

C
Carlos Rica 已提交
757 758
# trying to verify annotated non-signed tags:

759
test_expect_success GPG \
C
Carlos Rica 已提交
760 761
	'trying to verify an annotated non-signed tag should fail' '
	tag_exists annotated-tag &&
762
	test_must_fail git tag -v annotated-tag
C
Carlos Rica 已提交
763 764
'

765
test_expect_success GPG \
C
Carlos Rica 已提交
766 767
	'trying to verify a file-annotated non-signed tag should fail' '
	tag_exists file-annotated-tag &&
768
	test_must_fail git tag -v file-annotated-tag
C
Carlos Rica 已提交
769 770
'

771
test_expect_success GPG \
C
Carlos Rica 已提交
772 773
	'trying to verify two annotated non-signed tags should fail' '
	tag_exists annotated-tag file-annotated-tag &&
774
	test_must_fail git tag -v annotated-tag file-annotated-tag
C
Carlos Rica 已提交
775 776
'

C
Carlos Rica 已提交
777 778 779 780 781
# creating and verifying signed tags:

get_tag_header signed-tag $commit commit $time >expect
echo 'A signed tag message' >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
782
test_expect_success GPG 'creating a signed tag with -m message should succeed' '
783
	git tag -s -m "A signed tag message" signed-tag &&
C
Carlos Rica 已提交
784
	get_tag_msg signed-tag >actual &&
785
	test_cmp expect actual
C
Carlos Rica 已提交
786 787
'

L
Linus Torvalds 已提交
788 789 790
get_tag_header u-signed-tag $commit commit $time >expect
echo 'Another message' >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
791
test_expect_success GPG 'sign with a given key id' '
L
Linus Torvalds 已提交
792 793 794

	git tag -u committer@example.com -m "Another message" u-signed-tag &&
	get_tag_msg u-signed-tag >actual &&
795
	test_cmp expect actual
L
Linus Torvalds 已提交
796 797 798

'

799
test_expect_success GPG 'sign with an unknown id (1)' '
L
Linus Torvalds 已提交
800

801 802
	test_must_fail git tag -u author@example.com \
		-m "Another message" o-signed-tag
L
Linus Torvalds 已提交
803 804 805

'

806
test_expect_success GPG 'sign with an unknown id (2)' '
L
Linus Torvalds 已提交
807

808
	test_must_fail git tag -u DEADBEEF -m "Another message" o-signed-tag
L
Linus Torvalds 已提交
809 810 811 812 813 814 815 816 817 818 819 820 821 822

'

cat >fakeeditor <<'EOF'
#!/bin/sh
test -n "$1" && exec >"$1"
echo A signed tag message
echo from a fake editor.
EOF
chmod +x fakeeditor

get_tag_header implied-sign $commit commit $time >expect
./fakeeditor >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
823
test_expect_success GPG '-u implies signed tag' '
824
	GIT_EDITOR=./fakeeditor git tag -u CDDE430D implied-sign &&
L
Linus Torvalds 已提交
825
	get_tag_msg implied-sign >actual &&
826
	test_cmp expect actual
L
Linus Torvalds 已提交
827 828
'

C
Carlos Rica 已提交
829 830 831 832 833 834 835
cat >sigmsgfile <<EOF
Another signed tag
message in a file.
EOF
get_tag_header file-signed-tag $commit commit $time >expect
cat sigmsgfile >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
836
test_expect_success GPG \
C
Carlos Rica 已提交
837
	'creating a signed tag with -F messagefile should succeed' '
838
	git tag -s -F sigmsgfile file-signed-tag &&
C
Carlos Rica 已提交
839
	get_tag_msg file-signed-tag >actual &&
840
	test_cmp expect actual
C
Carlos Rica 已提交
841 842 843 844 845 846 847 848 849
'

cat >siginputmsg <<EOF
A signed tag message from
the standard input
EOF
get_tag_header stdin-signed-tag $commit commit $time >expect
cat siginputmsg >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
850
test_expect_success GPG 'creating a signed tag with -F - should succeed' '
851
	git tag -s -F - stdin-signed-tag <siginputmsg &&
C
Carlos Rica 已提交
852
	get_tag_msg stdin-signed-tag >actual &&
853
	test_cmp expect actual
C
Carlos Rica 已提交
854 855
'

856 857 858
get_tag_header implied-annotate $commit commit $time >expect
./fakeeditor >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
859
test_expect_success GPG '-s implies annotated tag' '
860
	GIT_EDITOR=./fakeeditor git tag -s implied-annotate &&
861
	get_tag_msg implied-annotate >actual &&
862
	test_cmp expect actual
863 864
'

865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905
get_tag_header forcesignannotated-implied-sign $commit commit $time >expect
echo "A message" >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
test_expect_success GPG \
	'git tag -s implied if configured with tag.forcesignannotated' \
	'test_config tag.forcesignannotated true &&
	git tag -m "A message" forcesignannotated-implied-sign &&
	get_tag_msg forcesignannotated-implied-sign >actual &&
	test_cmp expect actual
'

test_expect_success GPG \
	'lightweight with no message when configured with tag.forcesignannotated' \
	'test_config tag.forcesignannotated true &&
	git tag forcesignannotated-lightweight &&
	tag_exists forcesignannotated-lightweight &&
	test_must_fail git tag -v forcesignannotated-no-message
'

get_tag_header forcesignannotated-annotate $commit commit $time >expect
echo "A message" >>expect
test_expect_success GPG \
	'git tag -a disable configured tag.forcesignannotated' \
	'test_config tag.forcesignannotated true &&
	git tag -a -m "A message" forcesignannotated-annotate &&
	get_tag_msg forcesignannotated-annotate >actual &&
	test_cmp expect actual &&
	test_must_fail git tag -v forcesignannotated-annotate
'

get_tag_header forcesignannotated-disabled $commit commit $time >expect
echo "A message" >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
test_expect_success GPG \
	'git tag --sign enable GPG sign' \
	'test_config tag.forcesignannotated false &&
	git tag --sign -m "A message" forcesignannotated-disabled &&
	get_tag_msg forcesignannotated-disabled >actual &&
	test_cmp expect actual
'

906
test_expect_success GPG \
907 908 909
	'trying to create a signed tag with non-existing -F file should fail' '
	! test -f nonexistingfile &&
	! tag_exists nosigtag &&
910
	test_must_fail git tag -s -F nonexistingfile nosigtag &&
911 912 913
	! tag_exists nosigtag
'

914
test_expect_success GPG 'verifying a signed tag should succeed' \
915
	'git tag -v signed-tag'
C
Carlos Rica 已提交
916

917
test_expect_success GPG 'verifying two signed tags in one command should succeed' \
918
	'git tag -v signed-tag file-signed-tag'
C
Carlos Rica 已提交
919

920
test_expect_success GPG \
C
Carlos Rica 已提交
921
	'verifying many signed and non-signed tags should fail' '
922 923 924
	test_must_fail git tag -v signed-tag annotated-tag &&
	test_must_fail git tag -v file-annotated-tag file-signed-tag &&
	test_must_fail git tag -v annotated-tag \
925
		file-signed-tag file-annotated-tag &&
926
	test_must_fail git tag -v signed-tag annotated-tag file-signed-tag
C
Carlos Rica 已提交
927 928
'

929
test_expect_success GPG 'verifying a forged tag should fail' '
C
Carlos Rica 已提交
930 931 932 933
	forged=$(git cat-file tag signed-tag |
		sed -e "s/signed-tag/forged-tag/" |
		git mktag) &&
	git tag forged-tag $forged &&
934
	test_must_fail git tag -v forged-tag
C
Carlos Rica 已提交
935 936
'

937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952
test_expect_success 'verifying a proper tag with --format pass and format accordingly' '
	cat >expect <<-\EOF
	tagname : signed-tag
	EOF &&
	git tag -v --format="tagname : %(tag)" "signed-tag" >actual &&
	test_cmp expect actual
'

test_expect_success 'verifying a forged tag with --format fail and format accordingly' '
	cat >expect <<-\EOF
	tagname : forged-tag
	EOF &&
	test_must_fail git tag -v --format="tagname : %(tag)" "forged-tag" >actual &&
	test_cmp expect actual
'

C
Carlos Rica 已提交
953 954 955 956
# blank and empty messages for signed tags:

get_tag_header empty-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
957
test_expect_success GPG \
C
Carlos Rica 已提交
958
	'creating a signed tag with an empty -m message should succeed' '
959
	git tag -s -m "" empty-signed-tag &&
C
Carlos Rica 已提交
960
	get_tag_msg empty-signed-tag >actual &&
961
	test_cmp expect actual &&
962
	git tag -v empty-signed-tag
C
Carlos Rica 已提交
963 964 965 966 967
'

>sigemptyfile
get_tag_header emptyfile-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
968
test_expect_success GPG \
C
Carlos Rica 已提交
969
	'creating a signed tag with an empty -F messagefile should succeed' '
970
	git tag -s -F sigemptyfile emptyfile-signed-tag &&
C
Carlos Rica 已提交
971
	get_tag_msg emptyfile-signed-tag >actual &&
972
	test_cmp expect actual &&
973
	git tag -v emptyfile-signed-tag
C
Carlos Rica 已提交
974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990
'

printf '\n\n  \n\t\nLeading blank lines\n' > sigblanksfile
printf '\n\t \t  \nRepeated blank lines\n' >>sigblanksfile
printf '\n\n\nTrailing spaces      \t  \n' >>sigblanksfile
printf '\nTrailing blank lines\n\n\t \n\n' >>sigblanksfile
get_tag_header blanks-signed-tag $commit commit $time >expect
cat >>expect <<EOF
Leading blank lines

Repeated blank lines

Trailing spaces

Trailing blank lines
EOF
echo '-----BEGIN PGP SIGNATURE-----' >>expect
991
test_expect_success GPG \
C
Carlos Rica 已提交
992
	'extra blanks in the message for a signed tag should be removed' '
993
	git tag -s -F sigblanksfile blanks-signed-tag &&
C
Carlos Rica 已提交
994
	get_tag_msg blanks-signed-tag >actual &&
995
	test_cmp expect actual &&
996
	git tag -v blanks-signed-tag
C
Carlos Rica 已提交
997 998 999 1000
'

get_tag_header blank-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1001
test_expect_success GPG \
C
Carlos Rica 已提交
1002
	'creating a signed tag with a blank -m message should succeed' '
1003
	git tag -s -m "     " blank-signed-tag &&
C
Carlos Rica 已提交
1004
	get_tag_msg blank-signed-tag >actual &&
1005
	test_cmp expect actual &&
1006
	git tag -v blank-signed-tag
C
Carlos Rica 已提交
1007 1008 1009 1010 1011 1012 1013
'

echo '     ' >sigblankfile
echo ''      >>sigblankfile
echo '  '    >>sigblankfile
get_tag_header blankfile-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1014
test_expect_success GPG \
C
Carlos Rica 已提交
1015
	'creating a signed tag with blank -F file with spaces should succeed' '
1016
	git tag -s -F sigblankfile blankfile-signed-tag &&
C
Carlos Rica 已提交
1017
	get_tag_msg blankfile-signed-tag >actual &&
1018
	test_cmp expect actual &&
1019
	git tag -v blankfile-signed-tag
C
Carlos Rica 已提交
1020 1021 1022 1023 1024
'

printf '      ' >sigblanknonlfile
get_tag_header blanknonlfile-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1025
test_expect_success GPG \
C
Carlos Rica 已提交
1026
	'creating a signed tag with spaces and no newline should succeed' '
1027
	git tag -s -F sigblanknonlfile blanknonlfile-signed-tag &&
C
Carlos Rica 已提交
1028
	get_tag_msg blanknonlfile-signed-tag >actual &&
1029
	test_cmp expect actual &&
1030
	git tag -v signed-tag
C
Carlos Rica 已提交
1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061
'

# messages with commented lines for signed tags:

cat >sigcommentsfile <<EOF
# A comment

############
The message.
############
One line.


# commented lines
# commented lines

Another line.
# comments

Last line.
EOF
get_tag_header comments-signed-tag $commit commit $time >expect
cat >>expect <<EOF
The message.
One line.

Another line.

Last line.
EOF
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1062
test_expect_success GPG \
C
Carlos Rica 已提交
1063
	'creating a signed tag with a -F file with #comments should succeed' '
1064
	git tag -s -F sigcommentsfile comments-signed-tag &&
C
Carlos Rica 已提交
1065
	get_tag_msg comments-signed-tag >actual &&
1066
	test_cmp expect actual &&
1067
	git tag -v comments-signed-tag
C
Carlos Rica 已提交
1068 1069 1070 1071
'

get_tag_header comment-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1072
test_expect_success GPG \
C
Carlos Rica 已提交
1073
	'creating a signed tag with #commented -m message should succeed' '
1074
	git tag -s -m "#comment" comment-signed-tag &&
C
Carlos Rica 已提交
1075
	get_tag_msg comment-signed-tag >actual &&
1076
	test_cmp expect actual &&
1077
	git tag -v comment-signed-tag
C
Carlos Rica 已提交
1078 1079 1080 1081 1082 1083 1084
'

echo '#comment' >sigcommentfile
echo ''         >>sigcommentfile
echo '####'     >>sigcommentfile
get_tag_header commentfile-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1085
test_expect_success GPG \
C
Carlos Rica 已提交
1086
	'creating a signed tag with #commented -F messagefile should succeed' '
1087
	git tag -s -F sigcommentfile commentfile-signed-tag &&
C
Carlos Rica 已提交
1088
	get_tag_msg commentfile-signed-tag >actual &&
1089
	test_cmp expect actual &&
1090
	git tag -v commentfile-signed-tag
C
Carlos Rica 已提交
1091 1092 1093 1094 1095
'

printf '#comment' >sigcommentnonlfile
get_tag_header commentnonlfile-signed-tag $commit commit $time >expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1096
test_expect_success GPG \
C
Carlos Rica 已提交
1097
	'creating a signed tag with a #comment and no newline should succeed' '
1098
	git tag -s -F sigcommentnonlfile commentnonlfile-signed-tag &&
C
Carlos Rica 已提交
1099
	get_tag_msg commentnonlfile-signed-tag >actual &&
1100
	test_cmp expect actual &&
1101
	git tag -v commentnonlfile-signed-tag
C
Carlos Rica 已提交
1102 1103
'

1104 1105
# listing messages for signed tags:

1106
test_expect_success GPG \
1107
	'listing the one-line message of a signed tag should succeed' '
1108
	git tag -s -m "A message line signed" stag-one-line &&
1109 1110

	echo "stag-one-line" >expect &&
1111
	git tag -l | grep "^stag-one-line" >actual &&
1112
	test_cmp expect actual &&
1113
	git tag -n0 -l | grep "^stag-one-line" >actual &&
1114
	test_cmp expect actual &&
1115
	git tag -n0 -l stag-one-line >actual &&
1116
	test_cmp expect actual &&
1117 1118

	echo "stag-one-line   A message line signed" >expect &&
1119
	git tag -n1 -l | grep "^stag-one-line" >actual &&
1120
	test_cmp expect actual &&
1121
	git tag -n -l | grep "^stag-one-line" >actual &&
1122
	test_cmp expect actual &&
1123
	git tag -n1 -l stag-one-line >actual &&
1124
	test_cmp expect actual &&
1125
	git tag -n2 -l stag-one-line >actual &&
1126
	test_cmp expect actual &&
1127
	git tag -n999 -l stag-one-line >actual &&
1128
	test_cmp expect actual
1129 1130
'

1131
test_expect_success GPG \
1132
	'listing the zero-lines message of a signed tag should succeed' '
1133
	git tag -s -m "" stag-zero-lines &&
1134 1135

	echo "stag-zero-lines" >expect &&
1136
	git tag -l | grep "^stag-zero-lines" >actual &&
1137
	test_cmp expect actual &&
1138
	git tag -n0 -l | grep "^stag-zero-lines" >actual &&
1139
	test_cmp expect actual &&
1140
	git tag -n0 -l stag-zero-lines >actual &&
1141
	test_cmp expect actual &&
1142 1143

	echo "stag-zero-lines " >expect &&
1144
	git tag -n1 -l | grep "^stag-zero-lines" >actual &&
1145
	test_cmp expect actual &&
1146
	git tag -n -l | grep "^stag-zero-lines" >actual &&
1147
	test_cmp expect actual &&
1148
	git tag -n1 -l stag-zero-lines >actual &&
1149
	test_cmp expect actual &&
1150
	git tag -n2 -l stag-zero-lines >actual &&
1151
	test_cmp expect actual &&
1152
	git tag -n999 -l stag-zero-lines >actual &&
1153
	test_cmp expect actual
1154 1155 1156 1157 1158
'

echo 'stag line one' >sigtagmsg
echo 'stag line two' >>sigtagmsg
echo 'stag line three' >>sigtagmsg
1159
test_expect_success GPG \
1160
	'listing many message lines of a signed tag should succeed' '
1161
	git tag -s -F sigtagmsg stag-lines &&
1162 1163

	echo "stag-lines" >expect &&
1164
	git tag -l | grep "^stag-lines" >actual &&
1165
	test_cmp expect actual &&
1166
	git tag -n0 -l | grep "^stag-lines" >actual &&
1167
	test_cmp expect actual &&
1168
	git tag -n0 -l stag-lines >actual &&
1169
	test_cmp expect actual &&
1170 1171

	echo "stag-lines      stag line one" >expect &&
1172
	git tag -n1 -l | grep "^stag-lines" >actual &&
1173
	test_cmp expect actual &&
1174
	git tag -n -l | grep "^stag-lines" >actual &&
1175
	test_cmp expect actual &&
1176
	git tag -n1 -l stag-lines >actual &&
1177
	test_cmp expect actual &&
1178 1179

	echo "    stag line two" >>expect &&
1180
	git tag -n2 -l | grep "^ *stag.line" >actual &&
1181
	test_cmp expect actual &&
1182
	git tag -n2 -l stag-lines >actual &&
1183
	test_cmp expect actual &&
1184 1185

	echo "    stag line three" >>expect &&
1186
	git tag -n3 -l | grep "^ *stag.line" >actual &&
1187
	test_cmp expect actual &&
1188
	git tag -n3 -l stag-lines >actual &&
1189
	test_cmp expect actual &&
1190
	git tag -n4 -l | grep "^ *stag.line" >actual &&
1191
	test_cmp expect actual &&
1192
	git tag -n4 -l stag-lines >actual &&
1193
	test_cmp expect actual &&
1194
	git tag -n99 -l | grep "^ *stag.line" >actual &&
1195
	test_cmp expect actual &&
1196
	git tag -n99 -l stag-lines >actual &&
1197
	test_cmp expect actual
1198 1199
'

C
Carlos Rica 已提交
1200 1201 1202 1203
# tags pointing to objects different from commits:

tree=$(git rev-parse HEAD^{tree})
blob=$(git rev-parse HEAD:foo)
1204
tag=$(git rev-parse signed-tag 2>/dev/null)
C
Carlos Rica 已提交
1205 1206 1207 1208

get_tag_header tree-signed-tag $tree tree $time >expect
echo "A message for a tree" >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1209
test_expect_success GPG \
C
Carlos Rica 已提交
1210
	'creating a signed tag pointing to a tree should succeed' '
1211
	git tag -s -m "A message for a tree" tree-signed-tag HEAD^{tree} &&
C
Carlos Rica 已提交
1212
	get_tag_msg tree-signed-tag >actual &&
1213
	test_cmp expect actual
C
Carlos Rica 已提交
1214 1215 1216 1217 1218
'

get_tag_header blob-signed-tag $blob blob $time >expect
echo "A message for a blob" >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1219
test_expect_success GPG \
C
Carlos Rica 已提交
1220
	'creating a signed tag pointing to a blob should succeed' '
1221
	git tag -s -m "A message for a blob" blob-signed-tag HEAD:foo &&
C
Carlos Rica 已提交
1222
	get_tag_msg blob-signed-tag >actual &&
1223
	test_cmp expect actual
C
Carlos Rica 已提交
1224 1225 1226 1227 1228
'

get_tag_header tag-signed-tag $tag tag $time >expect
echo "A message for another tag" >>expect
echo '-----BEGIN PGP SIGNATURE-----' >>expect
1229
test_expect_success GPG \
C
Carlos Rica 已提交
1230
	'creating a signed tag pointing to another tag should succeed' '
1231
	git tag -s -m "A message for another tag" tag-signed-tag signed-tag &&
C
Carlos Rica 已提交
1232
	get_tag_msg tag-signed-tag >actual &&
1233
	test_cmp expect actual
C
Carlos Rica 已提交
1234 1235
'

1236 1237 1238 1239
# usage with rfc1991 signatures
get_tag_header rfc1991-signed-tag $commit commit $time >expect
echo "RFC1991 signed tag" >>expect
echo '-----BEGIN PGP MESSAGE-----' >>expect
1240
test_expect_success GPG,RFC1991 \
1241
	'creating a signed tag with rfc1991' '
1242
	echo "rfc1991" >gpghome/gpg.conf &&
1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253
	git tag -s -m "RFC1991 signed tag" rfc1991-signed-tag $commit &&
	get_tag_msg rfc1991-signed-tag >actual &&
	test_cmp expect actual
'

cat >fakeeditor <<'EOF'
#!/bin/sh
cp "$1" actual
EOF
chmod +x fakeeditor

1254
test_expect_success GPG,RFC1991 \
1255
	'reediting a signed tag body omits signature' '
1256
	echo "rfc1991" >gpghome/gpg.conf &&
1257 1258 1259 1260 1261
	echo "RFC1991 signed tag" >expect &&
	GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
	test_cmp expect actual
'

1262
test_expect_success GPG,RFC1991 \
1263
	'verifying rfc1991 signature' '
1264
	echo "rfc1991" >gpghome/gpg.conf &&
1265 1266 1267
	git tag -v rfc1991-signed-tag
'

1268
test_expect_success GPG,RFC1991 \
1269
	'list tag with rfc1991 signature' '
1270
	echo "rfc1991" >gpghome/gpg.conf &&
1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281
	echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
	git tag -l -n1 rfc1991-signed-tag >actual &&
	test_cmp expect actual &&
	git tag -l -n2 rfc1991-signed-tag >actual &&
	test_cmp expect actual &&
	git tag -l -n999 rfc1991-signed-tag >actual &&
	test_cmp expect actual
'

rm -f gpghome/gpg.conf

1282
test_expect_success GPG,RFC1991 \
1283 1284 1285 1286
	'verifying rfc1991 signature without --rfc1991' '
	git tag -v rfc1991-signed-tag
'

1287
test_expect_success GPG,RFC1991 \
1288 1289 1290 1291 1292 1293 1294 1295 1296 1297
	'list tag with rfc1991 signature without --rfc1991' '
	echo "rfc1991-signed-tag RFC1991 signed tag" >expect &&
	git tag -l -n1 rfc1991-signed-tag >actual &&
	test_cmp expect actual &&
	git tag -l -n2 rfc1991-signed-tag >actual &&
	test_cmp expect actual &&
	git tag -l -n999 rfc1991-signed-tag >actual &&
	test_cmp expect actual
'

1298
test_expect_success GPG,RFC1991 \
1299 1300 1301 1302 1303 1304
	'reediting a signed tag body omits signature' '
	echo "RFC1991 signed tag" >expect &&
	GIT_EDITOR=./fakeeditor git tag -f -s rfc1991-signed-tag $commit &&
	test_cmp expect actual
'

1305
# try to sign with bad user.signingkey
1306
test_expect_success GPG \
1307
	'git tag -s fails if gpg is misconfigured (bad key)' \
S
SZEDER Gábor 已提交
1308 1309
	'test_config user.signingkey BobTheMouse &&
	test_must_fail git tag -s -m tail tag-gpg-failure'
1310

1311 1312 1313 1314 1315 1316 1317
# try to produce invalid signature
test_expect_success GPG \
	'git tag -s fails if gpg is misconfigured (bad signature format)' \
	'test_config gpg.program echo &&
	 test_must_fail git tag -s -m tail tag-gpg-failure'


C
Carlos Rica 已提交
1318 1319 1320
# try to verify without gpg:

rm -rf gpghome
1321
test_expect_success GPG \
C
Carlos Rica 已提交
1322
	'verify signed tag fails when public key is not present' \
1323
	'test_must_fail git tag -v signed-tag'
C
Carlos Rica 已提交
1324

J
Junio C Hamano 已提交
1325
test_expect_success \
1326
	'git tag -a fails if tag annotation is empty' '
J
Junio C Hamano 已提交
1327
	! (GIT_EDITOR=cat git tag -a initial-comment)
1328 1329
'

M
Mike Hommey 已提交
1330 1331
test_expect_success \
	'message in editor has initial comment' '
1332 1333 1334
	! (GIT_EDITOR=cat git tag -a initial-comment > actual)
'

1335
test_expect_success 'message in editor has initial comment: first line' '
1336
	# check the first line --- should be empty
1337 1338
	echo >first.expect &&
	sed -e 1q <actual >first.actual &&
1339
	test_i18ncmp first.expect first.actual
1340 1341 1342 1343
'

test_expect_success \
	'message in editor has initial comment: remainder' '
1344
	# remove commented lines from the remainder -- should be empty
J
Jeff King 已提交
1345
	>rest.expect &&
J
Jeff King 已提交
1346
	sed -e 1d -e "/^#/d" <actual >rest.actual &&
1347
	test_cmp rest.expect rest.actual
M
Mike Hommey 已提交
1348 1349 1350 1351 1352 1353 1354 1355 1356
'

get_tag_header reuse $commit commit $time >expect
echo "An annotation to be reused" >> expect
test_expect_success \
	'overwriting an annoted tag should use its previous body' '
	git tag -a -m "An annotation to be reused" reuse &&
	GIT_EDITOR=true git tag -f -a reuse &&
	get_tag_msg reuse >actual &&
1357
	test_cmp expect actual
M
Mike Hommey 已提交
1358 1359
'

1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379
test_expect_success 'filename for the message is relative to cwd' '
	mkdir subdir &&
	echo "Tag message in top directory" >msgfile-5 &&
	echo "Tag message in sub directory" >subdir/msgfile-5 &&
	(
		cd subdir &&
		git tag -a -F msgfile-5 tag-from-subdir
	) &&
	git cat-file tag tag-from-subdir | grep "in sub directory"
'

test_expect_success 'filename for the message is relative to cwd' '
	echo "Tag message in sub directory" >subdir/msgfile-6 &&
	(
		cd subdir &&
		git tag -a -F msgfile-6 tag-from-subdir-2
	) &&
	git cat-file tag tag-from-subdir-2 | grep "in sub directory"
'

J
Jake Goulding 已提交
1380 1381 1382 1383 1384 1385 1386
# create a few more commits to test --contains

hash1=$(git rev-parse HEAD)

test_expect_success 'creating second commit and tag' '
	echo foo-2.0 >foo &&
	git add foo &&
J
Jonathan Nieder 已提交
1387
	git commit -m second &&
J
Jake Goulding 已提交
1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411
	git tag v2.0
'

hash2=$(git rev-parse HEAD)

test_expect_success 'creating third commit without tag' '
	echo foo-dev >foo &&
	git add foo &&
	git commit -m third
'

hash3=$(git rev-parse HEAD)

# simple linear checks of --continue

cat > expected <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
v2.0
EOF

test_expect_success 'checking that first commit is in all tags (hash)' "
J
Jonathan Nieder 已提交
1412
	git tag -l --contains $hash1 v* >actual &&
J
Jake Goulding 已提交
1413 1414 1415 1416 1417
	test_cmp expected actual
"

# other ways of specifying the commit
test_expect_success 'checking that first commit is in all tags (tag)' "
J
Jonathan Nieder 已提交
1418
	git tag -l --contains v1.0 v* >actual &&
J
Jake Goulding 已提交
1419 1420 1421 1422
	test_cmp expected actual
"

test_expect_success 'checking that first commit is in all tags (relative)' "
J
Jonathan Nieder 已提交
1423
	git tag -l --contains HEAD~2 v* >actual &&
J
Jake Goulding 已提交
1424 1425 1426
	test_cmp expected actual
"

1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443
# All the --contains tests above, but with --no-contains
test_expect_success 'checking that first commit is not listed in any tag with --no-contains  (hash)' "
	>expected &&
	git tag -l --no-contains $hash1 v* >actual &&
	test_cmp expected actual
"

test_expect_success 'checking that first commit is in all tags (tag)' "
	git tag -l --no-contains v1.0 v* >actual &&
	test_cmp expected actual
"

test_expect_success 'checking that first commit is in all tags (relative)' "
	git tag -l --no-contains HEAD~2 v* >actual &&
	test_cmp expected actual
"

J
Jake Goulding 已提交
1444 1445 1446 1447 1448
cat > expected <<EOF
v2.0
EOF

test_expect_success 'checking that second commit only has one tag' "
J
Jonathan Nieder 已提交
1449
	git tag -l --contains $hash2 v* >actual &&
J
Jake Goulding 已提交
1450 1451 1452
	test_cmp expected actual
"

1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463
cat > expected <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
EOF

test_expect_success 'inverse of the last test, with --no-contains' "
	git tag -l --no-contains $hash2 v* >actual &&
	test_cmp expected actual
"
J
Jake Goulding 已提交
1464 1465 1466 1467 1468

cat > expected <<EOF
EOF

test_expect_success 'checking that third commit has no tags' "
J
Jonathan Nieder 已提交
1469
	git tag -l --contains $hash3 v* >actual &&
J
Jake Goulding 已提交
1470 1471 1472
	test_cmp expected actual
"

1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485
cat > expected <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
v2.0
EOF

test_expect_success 'conversely --no-contains on the third commit lists all tags' "
	git tag -l --no-contains $hash3 v* >actual &&
	test_cmp expected actual
"

J
Jake Goulding 已提交
1486 1487 1488 1489 1490 1491
# how about a simple merge?

test_expect_success 'creating simple branch' '
	git branch stable v2.0 &&
        git checkout stable &&
	echo foo-3.0 > foo &&
J
Jonathan Nieder 已提交
1492
	git commit foo -m fourth &&
J
Jake Goulding 已提交
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502
	git tag v3.0
'

hash4=$(git rev-parse HEAD)

cat > expected <<EOF
v3.0
EOF

test_expect_success 'checking that branch head only has one tag' "
J
Jonathan Nieder 已提交
1503
	git tag -l --contains $hash4 v* >actual &&
J
Jake Goulding 已提交
1504 1505 1506
	test_cmp expected actual
"

1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
cat > expected <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
v2.0
EOF

test_expect_success 'checking that branch head with --no-contains lists all but one tag' "
	git tag -l --no-contains $hash4 v* >actual &&
	test_cmp expected actual
"

J
Jake Goulding 已提交
1520 1521 1522 1523 1524 1525 1526 1527 1528 1529
test_expect_success 'merging original branch into this branch' '
	git merge --strategy=ours master &&
        git tag v4.0
'

cat > expected <<EOF
v4.0
EOF

test_expect_success 'checking that original branch head has one tag now' "
J
Jonathan Nieder 已提交
1530
	git tag -l --contains $hash3 v* >actual &&
J
Jake Goulding 已提交
1531 1532 1533
	test_cmp expected actual
"

1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547
cat > expected <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
v2.0
v3.0
EOF

test_expect_success 'checking that original branch head with --no-contains lists all but one tag now' "
	git tag -l --no-contains $hash3 v* >actual &&
	test_cmp expected actual
"

J
Jake Goulding 已提交
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558
cat > expected <<EOF
v0.2.1
v1.0
v1.0.1
v1.1.3
v2.0
v3.0
v4.0
EOF

test_expect_success 'checking that initial commit is in all tags' "
J
Jonathan Nieder 已提交
1559
	git tag -l --contains $hash1 v* >actual &&
J
Jake Goulding 已提交
1560 1561 1562
	test_cmp expected actual
"

1563 1564 1565 1566 1567
test_expect_success 'checking that --contains can be used in non-list mode' '
	git tag --contains $hash1 v* >actual &&
	test_cmp expected actual
'

1568 1569 1570 1571 1572 1573
test_expect_success 'checking that initial commit is in all tags with --no-contains' "
	>expected &&
	git tag -l --no-contains $hash1 v* >actual &&
	test_cmp expected actual
"

1574 1575 1576
# mixing modes and options:

test_expect_success 'mixing incompatibles modes and options is forbidden' '
J
Jonathan Nieder 已提交
1577
	test_must_fail git tag -a &&
1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590
	test_must_fail git tag -a -l &&
	test_must_fail git tag -s &&
	test_must_fail git tag -s -l &&
	test_must_fail git tag -m &&
	test_must_fail git tag -m -l &&
	test_must_fail git tag -m "hlagh" &&
	test_must_fail git tag -m "hlagh" -l &&
	test_must_fail git tag -F &&
	test_must_fail git tag -F -l &&
	test_must_fail git tag -f &&
	test_must_fail git tag -f -l &&
	test_must_fail git tag -a -s -m -F &&
	test_must_fail git tag -a -s -m -F -l &&
J
Jonathan Nieder 已提交
1591
	test_must_fail git tag -l -v &&
1592 1593 1594
	test_must_fail git tag -l -d &&
	test_must_fail git tag -l -v -d &&
	test_must_fail git tag -n 100 -v &&
J
Jonathan Nieder 已提交
1595 1596
	test_must_fail git tag -l -m msg &&
	test_must_fail git tag -l -F some file &&
1597 1598
	test_must_fail git tag -v -s &&
	test_must_fail git tag --contains tag-tree &&
1599 1600 1601 1602
	test_must_fail git tag --contains tag-blob &&
	test_must_fail git tag --no-contains tag-tree &&
	test_must_fail git tag --no-contains tag-blob &&
	test_must_fail git tag --contains --no-contains
1603 1604
'

1605
for option in --contains --no-contains --merged --no-merged --points-at
1606 1607 1608 1609 1610 1611 1612 1613
do
	test_expect_success "mixing incompatible modes with $option is forbidden" "
		test_must_fail git tag -d $option HEAD &&
		test_must_fail git tag -d $option HEAD some-tag &&
		test_must_fail git tag -v $option HEAD
	"
	test_expect_success "Doing 'git tag --list-like $option <commit> <pattern> is permitted" "
		git tag -n $option HEAD HEAD &&
1614 1615
		git tag $option HEAD HEAD &&
		git tag $option
1616 1617 1618
	"
done

T
Tom Grennan 已提交
1619 1620
# check points-at

1621 1622 1623 1624
test_expect_success '--points-at can be used in non-list mode' '
	echo v4.0 >expect &&
	git tag --points-at=v4.0 "v*" >actual &&
	test_cmp expect actual
T
Tom Grennan 已提交
1625 1626
'

1627 1628 1629 1630 1631 1632
test_expect_success '--points-at is a synonym for --points-at HEAD' '
	echo v4.0 >expect &&
	git tag --points-at >actual &&
	test_cmp expect actual
'

T
Tom Grennan 已提交
1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665
test_expect_success '--points-at finds lightweight tags' '
	echo v4.0 >expect &&
	git tag --points-at v4.0 >actual &&
	test_cmp expect actual
'

test_expect_success '--points-at finds annotated tags of commits' '
	git tag -m "v4.0, annotated" annotated-v4.0 v4.0 &&
	echo annotated-v4.0 >expect &&
	git tag -l --points-at v4.0 "annotated*" >actual &&
	test_cmp expect actual
'

test_expect_success '--points-at finds annotated tags of tags' '
	git tag -m "describing the v4.0 tag object" \
		annotated-again-v4.0 annotated-v4.0 &&
	cat >expect <<-\EOF &&
	annotated-again-v4.0
	annotated-v4.0
	EOF
	git tag --points-at=annotated-v4.0 >actual &&
	test_cmp expect actual
'

test_expect_success 'multiple --points-at are OR-ed together' '
	cat >expect <<-\EOF &&
	v2.0
	v3.0
	EOF
	git tag --points-at=v2.0 --points-at=v3.0 >actual &&
	test_cmp expect actual
'

1666 1667 1668 1669 1670
test_expect_success 'lexical sort' '
	git tag foo1.3 &&
	git tag foo1.6 &&
	git tag foo1.10 &&
	git tag -l --sort=refname "foo*" >actual &&
1671 1672 1673 1674 1675
	cat >expect <<-\EOF &&
	foo1.10
	foo1.3
	foo1.6
	EOF
1676 1677 1678 1679 1680
	test_cmp expect actual
'

test_expect_success 'version sort' '
	git tag -l --sort=version:refname "foo*" >actual &&
1681 1682 1683 1684 1685
	cat >expect <<-\EOF &&
	foo1.3
	foo1.6
	foo1.10
	EOF
1686 1687 1688 1689 1690
	test_cmp expect actual
'

test_expect_success 'reverse version sort' '
	git tag -l --sort=-version:refname "foo*" >actual &&
1691 1692 1693 1694 1695
	cat >expect <<-\EOF &&
	foo1.10
	foo1.6
	foo1.3
	EOF
1696 1697 1698 1699 1700
	test_cmp expect actual
'

test_expect_success 'reverse lexical sort' '
	git tag -l --sort=-refname "foo*" >actual &&
1701 1702 1703 1704 1705
	cat >expect <<-\EOF &&
	foo1.6
	foo1.3
	foo1.10
	EOF
1706 1707 1708
	test_cmp expect actual
'

1709
test_expect_success 'configured lexical sort' '
S
SZEDER Gábor 已提交
1710
	test_config tag.sort "v:refname" &&
1711 1712 1713 1714 1715 1716 1717 1718 1719 1720
	git tag -l "foo*" >actual &&
	cat >expect <<-\EOF &&
	foo1.3
	foo1.6
	foo1.10
	EOF
	test_cmp expect actual
'

test_expect_success 'option override configured sort' '
S
SZEDER Gábor 已提交
1721
	test_config tag.sort "v:refname" &&
1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735
	git tag -l --sort=-refname "foo*" >actual &&
	cat >expect <<-\EOF &&
	foo1.6
	foo1.3
	foo1.10
	EOF
	test_cmp expect actual
'

test_expect_success 'invalid sort parameter on command line' '
	test_must_fail git tag -l --sort=notvalid "foo*" >actual
'

test_expect_success 'invalid sort parameter in configuratoin' '
S
SZEDER Gábor 已提交
1736
	test_config tag.sort "v:notvalid" &&
K
Karthik Nayak 已提交
1737
	test_must_fail git tag -l "foo*"
1738 1739
'

1740
test_expect_success 'version sort with prerelease reordering' '
S
SZEDER Gábor 已提交
1741
	test_config versionsort.prereleaseSuffix -rc &&
1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755
	git tag foo1.6-rc1 &&
	git tag foo1.6-rc2 &&
	git tag -l --sort=version:refname "foo*" >actual &&
	cat >expect <<-\EOF &&
	foo1.3
	foo1.6-rc1
	foo1.6-rc2
	foo1.6
	foo1.10
	EOF
	test_cmp expect actual
'

test_expect_success 'reverse version sort with prerelease reordering' '
S
SZEDER Gábor 已提交
1756
	test_config versionsort.prereleaseSuffix -rc &&
1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767
	git tag -l --sort=-version:refname "foo*" >actual &&
	cat >expect <<-\EOF &&
	foo1.10
	foo1.6
	foo1.6-rc2
	foo1.6-rc1
	foo1.3
	EOF
	test_cmp expect actual
'

1768
test_expect_success 'version sort with prerelease reordering and common leading character' '
1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781
	test_config versionsort.prereleaseSuffix -before &&
	git tag foo1.7-before1 &&
	git tag foo1.7 &&
	git tag foo1.7-after1 &&
	git tag -l --sort=version:refname "foo1.7*" >actual &&
	cat >expect <<-\EOF &&
	foo1.7-before1
	foo1.7
	foo1.7-after1
	EOF
	test_cmp expect actual
'

1782
test_expect_success 'version sort with prerelease reordering, multiple suffixes and common leading character' '
1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793
	test_config versionsort.prereleaseSuffix -before &&
	git config --add versionsort.prereleaseSuffix -after &&
	git tag -l --sort=version:refname "foo1.7*" >actual &&
	cat >expect <<-\EOF &&
	foo1.7-before1
	foo1.7-after1
	foo1.7
	EOF
	test_cmp expect actual
'

1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824
test_expect_success 'version sort with prerelease reordering, multiple suffixes match the same tag' '
	test_config versionsort.prereleaseSuffix -bar &&
	git config --add versionsort.prereleaseSuffix -foo-baz &&
	git config --add versionsort.prereleaseSuffix -foo-bar &&
	git tag foo1.8-foo-bar &&
	git tag foo1.8-foo-baz &&
	git tag foo1.8 &&
	git tag -l --sort=version:refname "foo1.8*" >actual &&
	cat >expect <<-\EOF &&
	foo1.8-foo-baz
	foo1.8-foo-bar
	foo1.8
	EOF
	test_cmp expect actual
'

test_expect_success 'version sort with prerelease reordering, multiple suffixes match starting at the same position' '
	test_config versionsort.prereleaseSuffix -pre &&
	git config --add versionsort.prereleaseSuffix -prerelease &&
	git tag foo1.9-pre1 &&
	git tag foo1.9-pre2 &&
	git tag foo1.9-prerelease1 &&
	git tag -l --sort=version:refname "foo1.9*" >actual &&
	cat >expect <<-\EOF &&
	foo1.9-pre1
	foo1.9-pre2
	foo1.9-prerelease1
	EOF
	test_cmp expect actual
'

1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859
test_expect_success 'version sort with general suffix reordering' '
	test_config versionsort.suffix -alpha &&
	git config --add versionsort.suffix -beta &&
	git config --add versionsort.suffix ""  &&
	git config --add versionsort.suffix -gamma &&
	git config --add versionsort.suffix -delta &&
	git tag foo1.10-alpha &&
	git tag foo1.10-beta &&
	git tag foo1.10-gamma &&
	git tag foo1.10-delta &&
	git tag foo1.10-unlisted-suffix &&
	git tag -l --sort=version:refname "foo1.10*" >actual &&
	cat >expect <<-\EOF &&
	foo1.10-alpha
	foo1.10-beta
	foo1.10
	foo1.10-unlisted-suffix
	foo1.10-gamma
	foo1.10-delta
	EOF
	test_cmp expect actual
'

test_expect_success 'versionsort.suffix overrides versionsort.prereleaseSuffix' '
	test_config versionsort.suffix -before &&
	test_config versionsort.prereleaseSuffix -after &&
	git tag -l --sort=version:refname "foo1.7*" >actual &&
	cat >expect <<-\EOF &&
	foo1.7-before1
	foo1.7
	foo1.7-after1
	EOF
	test_cmp expect actual
'

1860 1861 1862 1863 1864
test_expect_success 'version sort with very long prerelease suffix' '
	test_config versionsort.prereleaseSuffix -very-looooooooooooooooooooooooong-prerelease-suffix &&
	git tag -l --sort=version:refname
'

1865
run_with_limited_stack () {
1866
	(ulimit -s 128 && "$@")
1867 1868
}

1869
test_lazy_prereq ULIMIT_STACK_SIZE 'run_with_limited_stack true'
1870 1871

# we require ulimit, this excludes Windows
1872
test_expect_success ULIMIT_STACK_SIZE '--contains and --no-contains work in a deep repo' '
1873 1874
	>expect &&
	i=1 &&
1875
	while test $i -lt 8000
1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887
	do
		echo "commit refs/heads/master
committer A U Thor <author@example.com> $((1000000000 + $i * 100)) +0200
data <<EOF
commit #$i
EOF"
		test $i = 1 && echo "from refs/heads/master^0"
		i=$(($i + 1))
	done | git fast-import &&
	git checkout master &&
	git tag far-far-away HEAD^ &&
	run_with_limited_stack git tag --contains HEAD >actual &&
1888 1889 1890
	test_cmp expect actual &&
	run_with_limited_stack git tag --no-contains HEAD >actual &&
	test_line_count ">" 10 actual
1891 1892
'

1893 1894
test_expect_success '--format should list tags as per format given' '
	cat >expect <<-\EOF &&
1895 1896 1897
	refname : refs/tags/v1.0
	refname : refs/tags/v1.0.1
	refname : refs/tags/v1.1.3
1898
	EOF
1899
	git tag -l --format="refname : %(refname)" "v1*" >actual &&
1900 1901 1902
	test_cmp expect actual
'

1903 1904 1905 1906 1907 1908
test_expect_success 'setup --merged test tags' '
	git tag mergetest-1 HEAD~2 &&
	git tag mergetest-2 HEAD~1 &&
	git tag mergetest-3 HEAD
'

1909 1910 1911 1912 1913 1914 1915
test_expect_success '--merged can be used in non-list mode' '
	cat >expect <<-\EOF &&
	mergetest-1
	mergetest-2
	EOF
	git tag --merged=mergetest-2 "mergetest*" >actual &&
	test_cmp expect actual
1916 1917
'

1918 1919 1920 1921
test_expect_success '--merged is incompatible with --no-merged' '
	test_must_fail git tag --merged HEAD --no-merged HEAD
'

1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938
test_expect_success '--merged shows merged tags' '
	cat >expect <<-\EOF &&
	mergetest-1
	mergetest-2
	EOF
	git tag -l --merged=mergetest-2 mergetest-* >actual &&
	test_cmp expect actual
'

test_expect_success '--no-merged show unmerged tags' '
	cat >expect <<-\EOF &&
	mergetest-3
	EOF
	git tag -l --no-merged=mergetest-2 mergetest-* >actual &&
	test_cmp expect actual
'

1939 1940 1941 1942 1943
test_expect_success '--no-merged can be used in non-list mode' '
	git tag --no-merged=mergetest-2 mergetest-* >actual &&
	test_cmp expect actual
'

1944 1945 1946 1947 1948 1949 1950 1951
test_expect_success 'ambiguous branch/tags not marked' '
	git tag ambiguous &&
	git branch ambiguous &&
	echo ambiguous >expect &&
	git tag -l ambiguous >actual &&
	test_cmp expect actual
'

1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994
test_expect_success '--contains combined with --no-contains' '
	(
		git init no-contains &&
		cd no-contains &&
		test_commit v0.1 &&
		test_commit v0.2 &&
		test_commit v0.3 &&
		test_commit v0.4 &&
		test_commit v0.5 &&
		cat >expected <<-\EOF &&
		v0.2
		v0.3
		v0.4
		EOF
		git tag --contains v0.2 --no-contains v0.5 >actual &&
		test_cmp expected actual
	)
'

# As the docs say, list tags which contain a specified *commit*. We
# don't recurse down to tags for trees or blobs pointed to by *those*
# commits.
test_expect_success 'Does --[no-]contains stop at commits? Yes!' '
	cd no-contains &&
	blob=$(git rev-parse v0.3:v0.3.t) &&
	tree=$(git rev-parse v0.3^{tree}) &&
	git tag tag-blob $blob &&
	git tag tag-tree $tree &&
	git tag --contains v0.3 >actual &&
	cat >expected <<-\EOF &&
	v0.3
	v0.4
	v0.5
	EOF
	test_cmp expected actual &&
	git tag --no-contains v0.3 >actual &&
	cat >expected <<-\EOF &&
	v0.1
	v0.2
	EOF
	test_cmp expected actual
'

C
Carlos Rica 已提交
1995
test_done