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