Raw
1 #!/bin/sh
2
3 test_description='test for-each-refs usage of ref-filter APIs'
4
5 . ./test-lib.sh
6 . "$TEST_DIRECTORY"/lib-gpg.sh
7
8 test_expect_success 'setup some history and refs' '
9 test_commit one &&
10 git branch -M main &&
11 test_commit two &&
12 test_commit three &&
13 git checkout -b side &&
14 test_commit four &&
15 git tag -m "An annotated tag" annotated-tag &&
16 git tag -m "Annotated doubly" doubly-annotated-tag annotated-tag &&
17
18 # Note that these "signed" tags might not actually be signed.
19 # Tests which care about the distinction should be marked
20 # with the GPG prereq.
21 if test_have_prereq GPG
22 then
23 sign=-s
24 else
25 sign=
26 fi &&
27 git tag $sign -m "A signed tag" signed-tag &&
28 git tag $sign -m "Signed doubly" doubly-signed-tag signed-tag &&
29
30 git checkout main &&
31 git update-ref refs/odd/spot main
32 '
33
34 test_expect_success '--include-root-refs pattern prints pseudorefs' '
35 cat >expect <<-\EOF &&
36 HEAD
37 ORIG_HEAD
38 refs/heads/main
39 refs/heads/side
40 refs/odd/spot
41 refs/tags/annotated-tag
42 refs/tags/doubly-annotated-tag
43 refs/tags/doubly-signed-tag
44 refs/tags/four
45 refs/tags/one
46 refs/tags/signed-tag
47 refs/tags/three
48 refs/tags/two
49 EOF
50 git update-ref ORIG_HEAD main &&
51 git for-each-ref --format="%(refname)" --include-root-refs >actual &&
52 test_cmp expect actual
53 '
54
55 test_expect_success '--include-root-refs pattern does not print special refs' '
56 test_when_finished "rm -rf repo" &&
57 git init repo &&
58 (
59 cd repo &&
60 test_commit initial &&
61 git rev-parse HEAD >.git/MERGE_HEAD &&
62 git for-each-ref --format="%(refname)" --include-root-refs >actual &&
63 cat >expect <<-EOF &&
64 HEAD
65 $(git symbolic-ref HEAD)
66 refs/tags/initial
67 EOF
68 test_cmp expect actual
69 )
70 '
71
72 test_expect_success '--include-root-refs with other patterns' '
73 cat >expect <<-\EOF &&
74 HEAD
75 ORIG_HEAD
76 EOF
77 git update-ref ORIG_HEAD main &&
78 git for-each-ref --format="%(refname)" --include-root-refs "*HEAD" >actual &&
79 test_cmp expect actual
80 '
81
82 test_expect_success '--include-root-refs omits dangling symrefs' '
83 test_when_finished "rm -rf repo" &&
84 git init repo &&
85 (
86 cd repo &&
87 test_commit initial &&
88 git symbolic-ref DANGLING_HEAD refs/heads/missing &&
89 cat >expect <<-EOF &&
90 HEAD
91 $(git symbolic-ref HEAD)
92 refs/tags/initial
93 EOF
94 git for-each-ref --format="%(refname)" --include-root-refs >actual &&
95 test_cmp expect actual
96 )
97 '
98
99 test_expect_success 'filtering with --points-at' '
100 cat >expect <<-\EOF &&
101 refs/heads/main
102 refs/odd/spot
103 refs/tags/three
104 EOF
105 git for-each-ref --format="%(refname)" --points-at=main >actual &&
106 test_cmp expect actual
107 '
108
109 test_expect_success 'check signed tags with --points-at' '
110 sed -e "s/Z$//" >expect <<-\EOF &&
111 refs/heads/side Z
112 refs/tags/annotated-tag four
113 refs/tags/doubly-annotated-tag four
114 refs/tags/doubly-signed-tag four
115 refs/tags/four Z
116 refs/tags/signed-tag four
117 EOF
118 git for-each-ref --format="%(refname) %(*subject)" --points-at=side >actual &&
119 test_cmp expect actual
120 '
121
122 test_expect_success 'filtering with --merged' '
123 cat >expect <<-\EOF &&
124 refs/heads/main
125 refs/odd/spot
126 refs/tags/one
127 refs/tags/three
128 refs/tags/two
129 EOF
130 git for-each-ref --format="%(refname)" --merged=main >actual &&
131 test_cmp expect actual
132 '
133
134 test_expect_success 'filtering with --no-merged' '
135 cat >expect <<-\EOF &&
136 refs/heads/side
137 refs/tags/annotated-tag
138 refs/tags/doubly-annotated-tag
139 refs/tags/doubly-signed-tag
140 refs/tags/four
141 refs/tags/signed-tag
142 EOF
143 git for-each-ref --format="%(refname)" --no-merged=main >actual &&
144 test_cmp expect actual
145 '
146
147 test_expect_success 'filtering with --contains' '
148 cat >expect <<-\EOF &&
149 refs/heads/main
150 refs/heads/side
151 refs/odd/spot
152 refs/tags/annotated-tag
153 refs/tags/doubly-annotated-tag
154 refs/tags/doubly-signed-tag
155 refs/tags/four
156 refs/tags/signed-tag
157 refs/tags/three
158 refs/tags/two
159 EOF
160 git for-each-ref --format="%(refname)" --contains=two >actual &&
161 test_cmp expect actual
162 '
163
164 test_expect_success 'filtering with --no-contains' '
165 cat >expect <<-\EOF &&
166 refs/tags/one
167 EOF
168 git for-each-ref --format="%(refname)" --no-contains=two >actual &&
169 test_cmp expect actual
170 '
171
172 test_expect_success 'filtering with --contains and --no-contains' '
173 cat >expect <<-\EOF &&
174 refs/tags/two
175 EOF
176 git for-each-ref --format="%(refname)" --contains=two --no-contains=three >actual &&
177 test_cmp expect actual
178 '
179
180 test_expect_success '%(color) must fail' '
181 test_must_fail git for-each-ref --format="%(color)%(refname)"
182 '
183
184 test_expect_success '%(color:#aa22ac) must succeed' '
185 test_when_finished rm -rf test &&
186 git init test &&
187 (
188 cd test &&
189 test_commit initial &&
190 git branch -M main &&
191 cat >expect <<-\EOF &&
192 refs/heads/main
193 refs/tags/initial
194 EOF
195 git remote add origin nowhere &&
196 git config branch.main.remote origin &&
197 git config branch.main.merge refs/heads/main &&
198 git for-each-ref --format="%(color:#aa22ac)%(refname)" >actual &&
199 test_cmp expect actual
200 )
201 '
202
203 test_expect_success 'left alignment is default' '
204 cat >expect <<-\EOF &&
205 refname is refs/heads/main |refs/heads/main
206 refname is refs/heads/side |refs/heads/side
207 refname is refs/odd/spot |refs/odd/spot
208 refname is refs/tags/annotated-tag|refs/tags/annotated-tag
209 refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
210 refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
211 refname is refs/tags/four |refs/tags/four
212 refname is refs/tags/one |refs/tags/one
213 refname is refs/tags/signed-tag|refs/tags/signed-tag
214 refname is refs/tags/three |refs/tags/three
215 refname is refs/tags/two |refs/tags/two
216 EOF
217 git for-each-ref --format="%(align:30)refname is %(refname)%(end)|%(refname)" >actual &&
218 test_cmp expect actual
219 '
220
221 test_expect_success 'middle alignment' '
222 cat >expect <<-\EOF &&
223 | refname is refs/heads/main |refs/heads/main
224 | refname is refs/heads/side |refs/heads/side
225 | refname is refs/odd/spot |refs/odd/spot
226 |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
227 |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
228 |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
229 | refname is refs/tags/four |refs/tags/four
230 | refname is refs/tags/one |refs/tags/one
231 |refname is refs/tags/signed-tag|refs/tags/signed-tag
232 | refname is refs/tags/three |refs/tags/three
233 | refname is refs/tags/two |refs/tags/two
234 EOF
235 git for-each-ref --format="|%(align:middle,30)refname is %(refname)%(end)|%(refname)" >actual &&
236 test_cmp expect actual
237 '
238
239 test_expect_success 'right alignment' '
240 cat >expect <<-\EOF &&
241 | refname is refs/heads/main|refs/heads/main
242 | refname is refs/heads/side|refs/heads/side
243 | refname is refs/odd/spot|refs/odd/spot
244 |refname is refs/tags/annotated-tag|refs/tags/annotated-tag
245 |refname is refs/tags/doubly-annotated-tag|refs/tags/doubly-annotated-tag
246 |refname is refs/tags/doubly-signed-tag|refs/tags/doubly-signed-tag
247 | refname is refs/tags/four|refs/tags/four
248 | refname is refs/tags/one|refs/tags/one
249 |refname is refs/tags/signed-tag|refs/tags/signed-tag
250 | refname is refs/tags/three|refs/tags/three
251 | refname is refs/tags/two|refs/tags/two
252 EOF
253 git for-each-ref --format="|%(align:30,right)refname is %(refname)%(end)|%(refname)" >actual &&
254 test_cmp expect actual
255 '
256
257 cat >expect <<-\EOF
258 | refname is refs/heads/main |refs/heads/main
259 | refname is refs/heads/side |refs/heads/side
260 | refname is refs/odd/spot |refs/odd/spot
261 | refname is refs/tags/annotated-tag |refs/tags/annotated-tag
262 |refname is refs/tags/doubly-annotated-tag |refs/tags/doubly-annotated-tag
263 | refname is refs/tags/doubly-signed-tag |refs/tags/doubly-signed-tag
264 | refname is refs/tags/four |refs/tags/four
265 | refname is refs/tags/one |refs/tags/one
266 | refname is refs/tags/signed-tag |refs/tags/signed-tag
267 | refname is refs/tags/three |refs/tags/three
268 | refname is refs/tags/two |refs/tags/two
269 EOF
270
271 test_align_permutations() {
272 while read -r option
273 do
274 test_expect_success "align:$option" '
275 git for-each-ref --format="|%(align:$option)refname is %(refname)%(end)|%(refname)" >actual &&
276 test_cmp expect actual
277 '
278 done
279 }
280
281 test_align_permutations <<-\EOF
282 middle,42
283 42,middle
284 position=middle,42
285 42,position=middle
286 middle,width=42
287 width=42,middle
288 position=middle,width=42
289 width=42,position=middle
290 EOF
291
292 # Last one wins (silently) when multiple arguments of the same type are given
293
294 test_align_permutations <<-\EOF
295 32,width=42,middle
296 width=30,42,middle
297 width=42,position=right,middle
298 42,right,position=middle
299 EOF
300
301 # Individual atoms inside %(align:...) and %(end) must not be quoted.
302
303 test_expect_success 'alignment with format quote' "
304 cat >expect <<-\EOF &&
305 |' '\''main| A U Thor'\'' '|
306 |' '\''side| A U Thor'\'' '|
307 |' '\''odd/spot| A U Thor'\'' '|
308 |' '\''annotated-tag| '\'' '|
309 |' '\''doubly-annotated-tag| '\'' '|
310 |' '\''doubly-signed-tag| '\'' '|
311 |' '\''four| A U Thor'\'' '|
312 |' '\''one| A U Thor'\'' '|
313 |' '\''signed-tag| '\'' '|
314 |' '\''three| A U Thor'\'' '|
315 |' '\''two| A U Thor'\'' '|
316 EOF
317 git for-each-ref --shell --format=\"|%(align:30,middle)'%(refname:short)| %(authorname)'%(end)|\" >actual &&
318 test_cmp expect actual
319 "
320
321 test_expect_success 'nested alignment with quote formatting' "
322 cat >expect <<-\EOF &&
323 |' main '|
324 |' side '|
325 |' odd/spot '|
326 |' annotated-tag '|
327 |'doubly-annotated-tag '|
328 |'doubly-signed-tag '|
329 |' four '|
330 |' one '|
331 |' signed-tag '|
332 |' three '|
333 |' two '|
334 EOF
335 git for-each-ref --shell --format='|%(align:30,left)%(align:15,right)%(refname:short)%(end)%(end)|' >actual &&
336 test_cmp expect actual
337 "
338
339 test_expect_success 'check `%(contents:lines=1)`' '
340 cat >expect <<-\EOF &&
341 main |three
342 side |four
343 odd/spot |three
344 annotated-tag |An annotated tag
345 doubly-annotated-tag |Annotated doubly
346 doubly-signed-tag |Signed doubly
347 four |four
348 one |one
349 signed-tag |A signed tag
350 three |three
351 two |two
352 EOF
353 git for-each-ref --format="%(refname:short) |%(contents:lines=1)" >actual &&
354 test_cmp expect actual
355 '
356
357 test_expect_success 'check `%(contents:lines=0)`' '
358 cat >expect <<-\EOF &&
359 main |
360 side |
361 odd/spot |
362 annotated-tag |
363 doubly-annotated-tag |
364 doubly-signed-tag |
365 four |
366 one |
367 signed-tag |
368 three |
369 two |
370 EOF
371 git for-each-ref --format="%(refname:short) |%(contents:lines=0)" >actual &&
372 test_cmp expect actual
373 '
374
375 test_expect_success 'check `%(contents:lines=99999)`' '
376 cat >expect <<-\EOF &&
377 main |three
378 side |four
379 odd/spot |three
380 annotated-tag |An annotated tag
381 doubly-annotated-tag |Annotated doubly
382 doubly-signed-tag |Signed doubly
383 four |four
384 one |one
385 signed-tag |A signed tag
386 three |three
387 two |two
388 EOF
389 git for-each-ref --format="%(refname:short) |%(contents:lines=99999)" >actual &&
390 test_cmp expect actual
391 '
392
393 test_expect_success '`%(contents:lines=-1)` should fail' '
394 test_must_fail git for-each-ref --format="%(refname:short) |%(contents:lines=-1)"
395 '
396
397 test_expect_success 'setup for version sort' '
398 test_commit foo1.3 &&
399 test_commit foo1.6 &&
400 test_commit foo1.10
401 '
402
403 test_expect_success 'version sort' '
404 git for-each-ref --sort=version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
405 cat >expect <<-\EOF &&
406 foo1.3
407 foo1.6
408 foo1.10
409 EOF
410 test_cmp expect actual
411 '
412
413 test_expect_success 'version sort (shortened)' '
414 git for-each-ref --sort=v:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
415 cat >expect <<-\EOF &&
416 foo1.3
417 foo1.6
418 foo1.10
419 EOF
420 test_cmp expect actual
421 '
422
423 test_expect_success 'reverse version sort' '
424 git for-each-ref --sort=-version:refname --format="%(refname:short)" refs/tags/ | grep "foo" >actual &&
425 cat >expect <<-\EOF &&
426 foo1.10
427 foo1.6
428 foo1.3
429 EOF
430 test_cmp expect actual
431 '
432
433 test_expect_success 'improper usage of %(if), %(then), %(else) and %(end) atoms' '
434 test_must_fail git for-each-ref --format="%(if)" &&
435 test_must_fail git for-each-ref --format="%(then) %(end)" &&
436 test_must_fail git for-each-ref --format="%(else) %(end)" &&
437 test_must_fail git for-each-ref --format="%(if) %(else) %(end)" &&
438 test_must_fail git for-each-ref --format="%(if) %(then) %(then) %(end)" &&
439 test_must_fail git for-each-ref --format="%(then) %(else) %(end)" &&
440 test_must_fail git for-each-ref --format="%(if) %(else) %(end)" &&
441 test_must_fail git for-each-ref --format="%(if) %(then) %(else)" &&
442 test_must_fail git for-each-ref --format="%(if) %(else) %(then) %(end)" &&
443 test_must_fail git for-each-ref --format="%(if) %(then) %(else) %(else) %(end)" &&
444 test_must_fail git for-each-ref --format="%(if) %(end)"
445 '
446
447 test_expect_success 'check %(if)...%(then)...%(end) atoms' '
448 git for-each-ref --format="%(refname)%(if)%(authorname)%(then) Author: %(authorname)%(end)" >actual &&
449 cat >expect <<-\EOF &&
450 refs/heads/main Author: A U Thor
451 refs/heads/side Author: A U Thor
452 refs/odd/spot Author: A U Thor
453 refs/tags/annotated-tag
454 refs/tags/doubly-annotated-tag
455 refs/tags/doubly-signed-tag
456 refs/tags/foo1.10 Author: A U Thor
457 refs/tags/foo1.3 Author: A U Thor
458 refs/tags/foo1.6 Author: A U Thor
459 refs/tags/four Author: A U Thor
460 refs/tags/one Author: A U Thor
461 refs/tags/signed-tag
462 refs/tags/three Author: A U Thor
463 refs/tags/two Author: A U Thor
464 EOF
465 test_cmp expect actual
466 '
467
468 test_expect_success 'check %(if)...%(then)...%(else)...%(end) atoms' '
469 git for-each-ref --format="%(if)%(authorname)%(then)%(authorname)%(else)No author%(end): %(refname)" >actual &&
470 cat >expect <<-\EOF &&
471 A U Thor: refs/heads/main
472 A U Thor: refs/heads/side
473 A U Thor: refs/odd/spot
474 No author: refs/tags/annotated-tag
475 No author: refs/tags/doubly-annotated-tag
476 No author: refs/tags/doubly-signed-tag
477 A U Thor: refs/tags/foo1.10
478 A U Thor: refs/tags/foo1.3
479 A U Thor: refs/tags/foo1.6
480 A U Thor: refs/tags/four
481 A U Thor: refs/tags/one
482 No author: refs/tags/signed-tag
483 A U Thor: refs/tags/three
484 A U Thor: refs/tags/two
485 EOF
486 test_cmp expect actual
487 '
488 test_expect_success 'ignore spaces in %(if) atom usage' '
489 git for-each-ref --format="%(refname:short): %(if)%(HEAD)%(then)Head ref%(else)Not Head ref%(end)" >actual &&
490 cat >expect <<-\EOF &&
491 main: Head ref
492 side: Not Head ref
493 odd/spot: Not Head ref
494 annotated-tag: Not Head ref
495 doubly-annotated-tag: Not Head ref
496 doubly-signed-tag: Not Head ref
497 foo1.10: Not Head ref
498 foo1.3: Not Head ref
499 foo1.6: Not Head ref
500 four: Not Head ref
501 one: Not Head ref
502 signed-tag: Not Head ref
503 three: Not Head ref
504 two: Not Head ref
505 EOF
506 test_cmp expect actual
507 '
508
509 test_expect_success 'check %(if:equals=<string>)' '
510 git for-each-ref --format="%(if:equals=main)%(refname:short)%(then)Found main%(else)Not main%(end)" refs/heads/ >actual &&
511 cat >expect <<-\EOF &&
512 Found main
513 Not main
514 EOF
515 test_cmp expect actual
516 '
517
518 test_expect_success 'check %(if:notequals=<string>)' '
519 git for-each-ref --format="%(if:notequals=main)%(refname:short)%(then)Not main%(else)Found main%(end)" refs/heads/ >actual &&
520 cat >expect <<-\EOF &&
521 Found main
522 Not main
523 EOF
524 test_cmp expect actual
525 '
526
527 test_expect_success '--merged is compatible with --no-merged' '
528 git for-each-ref --merged HEAD --no-merged HEAD
529 '
530
531 test_expect_success 'validate worktree atom' '
532 cat >expect <<-EOF &&
533 main: $(pwd)
534 main_worktree: $(pwd)/worktree_dir
535 side: not checked out
536 EOF
537 git worktree add -b main_worktree worktree_dir main &&
538 git for-each-ref --format="%(refname:short): %(if)%(worktreepath)%(then)%(worktreepath)%(else)not checked out%(end)" refs/heads/ >actual &&
539 rm -r worktree_dir &&
540 git worktree prune &&
541 test_cmp expect actual
542 '
543
544 test_expect_success 'start after with empty value' '
545 cat >expect <<-\EOF &&
546 refs/heads/main
547 refs/heads/main_worktree
548 refs/heads/side
549 refs/odd/spot
550 refs/tags/annotated-tag
551 refs/tags/doubly-annotated-tag
552 refs/tags/doubly-signed-tag
553 refs/tags/foo1.10
554 refs/tags/foo1.3
555 refs/tags/foo1.6
556 refs/tags/four
557 refs/tags/one
558 refs/tags/signed-tag
559 refs/tags/three
560 refs/tags/two
561 EOF
562 git for-each-ref --format="%(refname)" --start-after="" >actual &&
563 test_cmp expect actual
564 '
565
566 test_expect_success 'start after a specific reference' '
567 cat >expect <<-\EOF &&
568 refs/tags/annotated-tag
569 refs/tags/doubly-annotated-tag
570 refs/tags/doubly-signed-tag
571 refs/tags/foo1.10
572 refs/tags/foo1.3
573 refs/tags/foo1.6
574 refs/tags/four
575 refs/tags/one
576 refs/tags/signed-tag
577 refs/tags/three
578 refs/tags/two
579 EOF
580 git for-each-ref --format="%(refname)" --start-after=refs/odd/spot >actual &&
581 test_cmp expect actual
582 '
583
584 test_expect_success 'start after a specific reference with partial match' '
585 cat >expect <<-\EOF &&
586 refs/odd/spot
587 refs/tags/annotated-tag
588 refs/tags/doubly-annotated-tag
589 refs/tags/doubly-signed-tag
590 refs/tags/foo1.10
591 refs/tags/foo1.3
592 refs/tags/foo1.6
593 refs/tags/four
594 refs/tags/one
595 refs/tags/signed-tag
596 refs/tags/three
597 refs/tags/two
598 EOF
599 git for-each-ref --format="%(refname)" --start-after=refs/odd/sp >actual &&
600 test_cmp expect actual
601 '
602
603 test_expect_success 'start after, just behind a specific reference' '
604 cat >expect <<-\EOF &&
605 refs/odd/spot
606 refs/tags/annotated-tag
607 refs/tags/doubly-annotated-tag
608 refs/tags/doubly-signed-tag
609 refs/tags/foo1.10
610 refs/tags/foo1.3
611 refs/tags/foo1.6
612 refs/tags/four
613 refs/tags/one
614 refs/tags/signed-tag
615 refs/tags/three
616 refs/tags/two
617 EOF
618 git for-each-ref --format="%(refname)" --start-after=refs/odd/parrot >actual &&
619 test_cmp expect actual
620 '
621
622 test_expect_success 'start after with specific directory match' '
623 cat >expect <<-\EOF &&
624 refs/odd/spot
625 refs/tags/annotated-tag
626 refs/tags/doubly-annotated-tag
627 refs/tags/doubly-signed-tag
628 refs/tags/foo1.10
629 refs/tags/foo1.3
630 refs/tags/foo1.6
631 refs/tags/four
632 refs/tags/one
633 refs/tags/signed-tag
634 refs/tags/three
635 refs/tags/two
636 EOF
637 git for-each-ref --format="%(refname)" --start-after=refs/odd >actual &&
638 test_cmp expect actual
639 '
640
641 test_expect_success 'start after with specific directory and trailing slash' '
642 cat >expect <<-\EOF &&
643 refs/odd/spot
644 refs/tags/annotated-tag
645 refs/tags/doubly-annotated-tag
646 refs/tags/doubly-signed-tag
647 refs/tags/foo1.10
648 refs/tags/foo1.3
649 refs/tags/foo1.6
650 refs/tags/four
651 refs/tags/one
652 refs/tags/signed-tag
653 refs/tags/three
654 refs/tags/two
655 EOF
656 git for-each-ref --format="%(refname)" --start-after=refs/odd/ >actual &&
657 test_cmp expect actual
658 '
659
660 test_expect_success 'start after, just behind a specific directory' '
661 cat >expect <<-\EOF &&
662 refs/odd/spot
663 refs/tags/annotated-tag
664 refs/tags/doubly-annotated-tag
665 refs/tags/doubly-signed-tag
666 refs/tags/foo1.10
667 refs/tags/foo1.3
668 refs/tags/foo1.6
669 refs/tags/four
670 refs/tags/one
671 refs/tags/signed-tag
672 refs/tags/three
673 refs/tags/two
674 EOF
675 git for-each-ref --format="%(refname)" --start-after=refs/lost >actual &&
676 test_cmp expect actual
677 '
678
679 test_expect_success 'start after, overflow specific reference length' '
680 cat >expect <<-\EOF &&
681 refs/tags/annotated-tag
682 refs/tags/doubly-annotated-tag
683 refs/tags/doubly-signed-tag
684 refs/tags/foo1.10
685 refs/tags/foo1.3
686 refs/tags/foo1.6
687 refs/tags/four
688 refs/tags/one
689 refs/tags/signed-tag
690 refs/tags/three
691 refs/tags/two
692 EOF
693 git for-each-ref --format="%(refname)" --start-after=refs/odd/spotnew >actual &&
694 test_cmp expect actual
695 '
696
697 test_expect_success 'start after, overflow specific reference path' '
698 cat >expect <<-\EOF &&
699 refs/tags/annotated-tag
700 refs/tags/doubly-annotated-tag
701 refs/tags/doubly-signed-tag
702 refs/tags/foo1.10
703 refs/tags/foo1.3
704 refs/tags/foo1.6
705 refs/tags/four
706 refs/tags/one
707 refs/tags/signed-tag
708 refs/tags/three
709 refs/tags/two
710 EOF
711 git for-each-ref --format="%(refname)" --start-after=refs/odd/spot/new >actual &&
712 test_cmp expect actual
713 '
714
715 test_expect_success 'start after, with exclude pattern' '
716 cat >expect <<-\EOF &&
717 refs/tags/annotated-tag
718 refs/tags/doubly-annotated-tag
719 refs/tags/doubly-signed-tag
720 refs/tags/foo1.10
721 refs/tags/foo1.3
722 refs/tags/foo1.6
723 refs/tags/four
724 refs/tags/one
725 refs/tags/signed-tag
726 refs/tags/three
727 refs/tags/two
728 EOF
729 git for-each-ref --format="%(refname)" --start-after=refs/odd/spot \
730 --exclude=refs/tags/foo >actual &&
731 test_cmp expect actual
732 '
733
734 test_expect_success 'start after, last reference' '
735 cat >expect <<-\EOF &&
736 EOF
737 git for-each-ref --format="%(refname)" --start-after=refs/tags/two >actual &&
738 test_cmp expect actual
739 '
740
741 test_expect_success 'start after used with a pattern' '
742 cat >expect <<-\EOF &&
743 fatal: cannot use --start-after with patterns
744 EOF
745 test_must_fail git for-each-ref --format="%(refname)" --start-after=refs/odd/spot refs/tags 2>actual &&
746 test_cmp expect actual
747 '
748
749 test_expect_success 'start after used with custom sort order' '
750 cat >expect <<-\EOF &&
751 fatal: cannot use --start-after with custom sort options
752 EOF
753 test_must_fail git for-each-ref --format="%(refname)" --start-after=refs/odd/spot --sort=author 2>actual &&
754 test_cmp expect actual
755 '
756
757 test_expect_success 'start after with packed refs' '
758 test_when_finished "rm -rf repo" &&
759 git init repo &&
760 (
761 cd repo &&
762 test_commit default &&
763
764 git update-ref --stdin <<-\EOF &&
765 create refs/heads/branch @
766 create refs/heads/side @
767 create refs/odd/spot @
768 create refs/tags/one @
769 create refs/tags/two @
770 commit
771 EOF
772
773 cat >expect <<-\EOF &&
774 refs/tags/default
775 refs/tags/one
776 refs/tags/two
777 EOF
778
779 git pack-refs --all &&
780 git for-each-ref --format="%(refname)" --start-after=refs/odd/spot >actual &&
781 test_cmp expect actual
782 )
783 '
784
785 test_expect_success 'start after with packed refs and some loose refs' '
786 test_when_finished "rm -rf repo" &&
787 git init repo &&
788 (
789 cd repo &&
790 test_commit default &&
791
792 git update-ref --stdin <<-\EOF &&
793 create refs/heads/branch @
794 create refs/heads/side @
795 create refs/odd/spot @
796 create refs/tags/one @
797 create refs/tags/two @
798 commit
799 EOF
800
801 git pack-refs --all &&
802
803 git update-ref --stdin <<-\EOF &&
804 create refs/heads/foo @
805 create refs/odd/tee @
806 commit
807 EOF
808
809 cat >expect <<-\EOF &&
810 refs/odd/tee
811 refs/tags/default
812 refs/tags/one
813 refs/tags/two
814 EOF
815
816
817 git for-each-ref --format="%(refname)" --start-after=refs/odd/spot >actual &&
818 test_cmp expect actual
819 )
820 '
821
822 test_done