leak tests: mark some config tests as passing with SANITIZE=leak
[git/debian.git] / t / t6300-for-each-ref.sh
blob80679d5e12d49328fea6bd4d8e0b7929b68d9bea
1 #!/bin/sh
3 # Copyright (c) 2007 Andy Parkins
6 test_description='for-each-ref test'
8 GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master
9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
11 . ./test-lib.sh
12 . "$TEST_DIRECTORY"/lib-gpg.sh
13 . "$TEST_DIRECTORY"/lib-terminal.sh
15 # Mon Jul 3 23:18:43 2006 +0000
16 datestamp=1151968723
17 setdate_and_increment () {
18 GIT_COMMITTER_DATE="$datestamp +0200"
19 datestamp=$(expr "$datestamp" + 1)
20 GIT_AUTHOR_DATE="$datestamp +0200"
21 datestamp=$(expr "$datestamp" + 1)
22 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
25 test_expect_success setup '
26 test_oid_cache <<-EOF &&
27 disklen sha1:138
28 disklen sha256:154
29 EOF
30 setdate_and_increment &&
31 echo "Using $datestamp" > one &&
32 git add one &&
33 git commit -m "Initial" &&
34 git branch -M main &&
35 setdate_and_increment &&
36 git tag -a -m "Tagging at $datestamp" testtag &&
37 git update-ref refs/remotes/origin/main main &&
38 git remote add origin nowhere &&
39 git config branch.main.remote origin &&
40 git config branch.main.merge refs/heads/main &&
41 git remote add myfork elsewhere &&
42 git config remote.pushdefault myfork &&
43 git config push.default current
46 test_atom() {
47 case "$1" in
48 head) ref=refs/heads/main ;;
49 tag) ref=refs/tags/testtag ;;
50 sym) ref=refs/heads/sym ;;
51 *) ref=$1 ;;
52 esac
53 printf '%s\n' "$3" >expected
54 test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
55 git for-each-ref --format='%($2)' $ref >actual &&
56 sanitize_pgp <actual >actual.clean &&
57 test_cmp expected actual.clean
59 # Automatically test "contents:size" atom after testing "contents"
60 if test "$2" = "contents"
61 then
62 # for commit leg, $3 is changed there
63 expect=$(printf '%s' "$3" | wc -c)
64 test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" '
65 type=$(git cat-file -t "$ref") &&
66 case $type in
67 tag)
68 # We cannot use $3 as it expects sanitize_pgp to run
69 git cat-file tag $ref >out &&
70 expect=$(tail -n +6 out | wc -c) &&
71 rm -f out ;;
72 tree | blob)
73 expect="" ;;
74 commit)
75 : "use the calculated expect" ;;
77 BUG "unknown object type" ;;
78 esac &&
79 # Leave $expect unquoted to lose possible leading whitespaces
80 echo $expect >expected &&
81 git for-each-ref --format="%(contents:size)" "$ref" >actual &&
82 test_cmp expected actual
87 hexlen=$(test_oid hexsz)
88 disklen=$(test_oid disklen)
90 test_atom head refname refs/heads/main
91 test_atom head refname: refs/heads/main
92 test_atom head refname:short main
93 test_atom head refname:lstrip=1 heads/main
94 test_atom head refname:lstrip=2 main
95 test_atom head refname:lstrip=-1 main
96 test_atom head refname:lstrip=-2 heads/main
97 test_atom head refname:rstrip=1 refs/heads
98 test_atom head refname:rstrip=2 refs
99 test_atom head refname:rstrip=-1 refs
100 test_atom head refname:rstrip=-2 refs/heads
101 test_atom head refname:strip=1 heads/main
102 test_atom head refname:strip=2 main
103 test_atom head refname:strip=-1 main
104 test_atom head refname:strip=-2 heads/main
105 test_atom head upstream refs/remotes/origin/main
106 test_atom head upstream:short origin/main
107 test_atom head upstream:lstrip=2 origin/main
108 test_atom head upstream:lstrip=-2 origin/main
109 test_atom head upstream:rstrip=2 refs/remotes
110 test_atom head upstream:rstrip=-2 refs/remotes
111 test_atom head upstream:strip=2 origin/main
112 test_atom head upstream:strip=-2 origin/main
113 test_atom head push refs/remotes/myfork/main
114 test_atom head push:short myfork/main
115 test_atom head push:lstrip=1 remotes/myfork/main
116 test_atom head push:lstrip=-1 main
117 test_atom head push:rstrip=1 refs/remotes/myfork
118 test_atom head push:rstrip=-1 refs
119 test_atom head push:strip=1 remotes/myfork/main
120 test_atom head push:strip=-1 main
121 test_atom head objecttype commit
122 test_atom head objectsize $((131 + hexlen))
123 test_atom head objectsize:disk $disklen
124 test_atom head deltabase $ZERO_OID
125 test_atom head objectname $(git rev-parse refs/heads/main)
126 test_atom head objectname:short $(git rev-parse --short refs/heads/main)
127 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
128 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
129 test_atom head tree $(git rev-parse refs/heads/main^{tree})
130 test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree})
131 test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree})
132 test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree})
133 test_atom head parent ''
134 test_atom head parent:short ''
135 test_atom head parent:short=1 ''
136 test_atom head parent:short=10 ''
137 test_atom head numparent 0
138 test_atom head object ''
139 test_atom head type ''
140 test_atom head raw "$(git cat-file commit refs/heads/main)
142 test_atom head '*objectname' ''
143 test_atom head '*objecttype' ''
144 test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
145 test_atom head authorname 'A U Thor'
146 test_atom head authoremail '<author@example.com>'
147 test_atom head authoremail:trim 'author@example.com'
148 test_atom head authoremail:localpart 'author'
149 test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
150 test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
151 test_atom head committername 'C O Mitter'
152 test_atom head committeremail '<committer@example.com>'
153 test_atom head committeremail:trim 'committer@example.com'
154 test_atom head committeremail:localpart 'committer'
155 test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
156 test_atom head tag ''
157 test_atom head tagger ''
158 test_atom head taggername ''
159 test_atom head taggeremail ''
160 test_atom head taggeremail:trim ''
161 test_atom head taggeremail:localpart ''
162 test_atom head taggerdate ''
163 test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
164 test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
165 test_atom head subject 'Initial'
166 test_atom head subject:sanitize 'Initial'
167 test_atom head contents:subject 'Initial'
168 test_atom head body ''
169 test_atom head contents:body ''
170 test_atom head contents:signature ''
171 test_atom head contents 'Initial
173 test_atom head HEAD '*'
175 test_atom tag refname refs/tags/testtag
176 test_atom tag refname:short testtag
177 test_atom tag upstream ''
178 test_atom tag push ''
179 test_atom tag objecttype tag
180 test_atom tag objectsize $((114 + hexlen))
181 test_atom tag objectsize:disk $disklen
182 test_atom tag '*objectsize:disk' $disklen
183 test_atom tag deltabase $ZERO_OID
184 test_atom tag '*deltabase' $ZERO_OID
185 test_atom tag objectname $(git rev-parse refs/tags/testtag)
186 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
187 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
188 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
189 test_atom tag tree ''
190 test_atom tag tree:short ''
191 test_atom tag tree:short=1 ''
192 test_atom tag tree:short=10 ''
193 test_atom tag parent ''
194 test_atom tag parent:short ''
195 test_atom tag parent:short=1 ''
196 test_atom tag parent:short=10 ''
197 test_atom tag numparent ''
198 test_atom tag object $(git rev-parse refs/tags/testtag^0)
199 test_atom tag type 'commit'
200 test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
201 test_atom tag '*objecttype' 'commit'
202 test_atom tag author ''
203 test_atom tag authorname ''
204 test_atom tag authoremail ''
205 test_atom tag authoremail:trim ''
206 test_atom tag authoremail:localpart ''
207 test_atom tag authordate ''
208 test_atom tag committer ''
209 test_atom tag committername ''
210 test_atom tag committeremail ''
211 test_atom tag committeremail:trim ''
212 test_atom tag committeremail:localpart ''
213 test_atom tag committerdate ''
214 test_atom tag tag 'testtag'
215 test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
216 test_atom tag taggername 'C O Mitter'
217 test_atom tag taggeremail '<committer@example.com>'
218 test_atom tag taggeremail:trim 'committer@example.com'
219 test_atom tag taggeremail:localpart 'committer'
220 test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
221 test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
222 test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
223 test_atom tag subject 'Tagging at 1151968727'
224 test_atom tag subject:sanitize 'Tagging-at-1151968727'
225 test_atom tag contents:subject 'Tagging at 1151968727'
226 test_atom tag body ''
227 test_atom tag contents:body ''
228 test_atom tag contents:signature ''
229 test_atom tag contents 'Tagging at 1151968727
231 test_atom tag HEAD ' '
233 test_expect_success 'basic atom: refs/tags/testtag *raw' '
234 git cat-file commit refs/tags/testtag^{} >expected &&
235 git for-each-ref --format="%(*raw)" refs/tags/testtag >actual &&
236 sanitize_pgp <expected >expected.clean &&
237 echo >>expected.clean &&
238 sanitize_pgp <actual >actual.clean &&
239 test_cmp expected.clean actual.clean
242 test_expect_success 'Check invalid atoms names are errors' '
243 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
246 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
247 git for-each-ref --format="%(authordate)" refs/heads &&
248 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
249 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
250 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
253 test_expect_success 'Check valid format specifiers for date fields' '
254 git for-each-ref --format="%(authordate:default)" refs/heads &&
255 git for-each-ref --format="%(authordate:relative)" refs/heads &&
256 git for-each-ref --format="%(authordate:short)" refs/heads &&
257 git for-each-ref --format="%(authordate:local)" refs/heads &&
258 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
259 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
262 test_expect_success 'Check invalid format specifiers are errors' '
263 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
266 test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
267 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
268 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
269 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
272 test_date () {
273 f=$1 &&
274 committer_date=$2 &&
275 author_date=$3 &&
276 tagger_date=$4 &&
277 cat >expected <<-EOF &&
278 'refs/heads/main' '$committer_date' '$author_date'
279 'refs/tags/testtag' '$tagger_date'
282 git for-each-ref --shell \
283 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
284 refs/heads &&
285 git for-each-ref --shell \
286 --format="%(refname) %(taggerdate${f:+:$f})" \
287 refs/tags
288 ) >actual &&
289 test_cmp expected actual
292 test_expect_success 'Check unformatted date fields output' '
293 test_date "" \
294 "Tue Jul 4 01:18:43 2006 +0200" \
295 "Tue Jul 4 01:18:44 2006 +0200" \
296 "Tue Jul 4 01:18:45 2006 +0200"
299 test_expect_success 'Check format "default" formatted date fields output' '
300 test_date default \
301 "Tue Jul 4 01:18:43 2006 +0200" \
302 "Tue Jul 4 01:18:44 2006 +0200" \
303 "Tue Jul 4 01:18:45 2006 +0200"
306 test_expect_success 'Check format "default-local" date fields output' '
307 test_date default-local "Mon Jul 3 23:18:43 2006" "Mon Jul 3 23:18:44 2006" "Mon Jul 3 23:18:45 2006"
310 # Don't know how to do relative check because I can't know when this script
311 # is going to be run and can't fake the current time to git, and hence can't
312 # provide expected output. Instead, I'll just make sure that "relative"
313 # doesn't exit in error
314 test_expect_success 'Check format "relative" date fields output' '
315 f=relative &&
316 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
317 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
320 # We just check that this is the same as "relative" for now.
321 test_expect_success 'Check format "relative-local" date fields output' '
322 test_date relative-local \
323 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
324 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
325 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
328 test_expect_success 'Check format "short" date fields output' '
329 test_date short 2006-07-04 2006-07-04 2006-07-04
332 test_expect_success 'Check format "short-local" date fields output' '
333 test_date short-local 2006-07-03 2006-07-03 2006-07-03
336 test_expect_success 'Check format "local" date fields output' '
337 test_date local \
338 "Mon Jul 3 23:18:43 2006" \
339 "Mon Jul 3 23:18:44 2006" \
340 "Mon Jul 3 23:18:45 2006"
343 test_expect_success 'Check format "iso8601" date fields output' '
344 test_date iso8601 \
345 "2006-07-04 01:18:43 +0200" \
346 "2006-07-04 01:18:44 +0200" \
347 "2006-07-04 01:18:45 +0200"
350 test_expect_success 'Check format "iso8601-local" date fields output' '
351 test_date iso8601-local "2006-07-03 23:18:43 +0000" "2006-07-03 23:18:44 +0000" "2006-07-03 23:18:45 +0000"
354 test_expect_success 'Check format "rfc2822" date fields output' '
355 test_date rfc2822 \
356 "Tue, 4 Jul 2006 01:18:43 +0200" \
357 "Tue, 4 Jul 2006 01:18:44 +0200" \
358 "Tue, 4 Jul 2006 01:18:45 +0200"
361 test_expect_success 'Check format "rfc2822-local" date fields output' '
362 test_date rfc2822-local "Mon, 3 Jul 2006 23:18:43 +0000" "Mon, 3 Jul 2006 23:18:44 +0000" "Mon, 3 Jul 2006 23:18:45 +0000"
365 test_expect_success 'Check format "raw" date fields output' '
366 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
369 test_expect_success 'Check format "raw-local" date fields output' '
370 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
373 test_expect_success 'Check format of strftime date fields' '
374 echo "my date is 2006-07-04" >expected &&
375 git for-each-ref \
376 --format="%(authordate:format:my date is %Y-%m-%d)" \
377 refs/heads >actual &&
378 test_cmp expected actual
381 test_expect_success 'Check format of strftime-local date fields' '
382 echo "my date is 2006-07-03" >expected &&
383 git for-each-ref \
384 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
385 refs/heads >actual &&
386 test_cmp expected actual
389 test_expect_success 'exercise strftime with odd fields' '
390 echo >expected &&
391 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
392 test_cmp expected actual &&
393 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
394 echo $long >expected &&
395 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
396 test_cmp expected actual
399 cat >expected <<\EOF
400 refs/heads/main
401 refs/remotes/origin/main
402 refs/tags/testtag
405 test_expect_success 'Verify ascending sort' '
406 git for-each-ref --format="%(refname)" --sort=refname >actual &&
407 test_cmp expected actual
411 cat >expected <<\EOF
412 refs/tags/testtag
413 refs/remotes/origin/main
414 refs/heads/main
417 test_expect_success 'Verify descending sort' '
418 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
419 test_cmp expected actual
422 cat >expected <<\EOF
423 refs/tags/testtag
424 refs/tags/testtag-2
427 test_expect_success 'exercise patterns with prefixes' '
428 git tag testtag-2 &&
429 test_when_finished "git tag -d testtag-2" &&
430 git for-each-ref --format="%(refname)" \
431 refs/tags/testtag refs/tags/testtag-2 >actual &&
432 test_cmp expected actual
435 cat >expected <<\EOF
436 refs/tags/testtag
437 refs/tags/testtag-2
440 test_expect_success 'exercise glob patterns with prefixes' '
441 git tag testtag-2 &&
442 test_when_finished "git tag -d testtag-2" &&
443 git for-each-ref --format="%(refname)" \
444 refs/tags/testtag "refs/tags/testtag-*" >actual &&
445 test_cmp expected actual
448 cat >expected <<\EOF
449 'refs/heads/main'
450 'refs/remotes/origin/main'
451 'refs/tags/testtag'
454 test_expect_success 'Quoting style: shell' '
455 git for-each-ref --shell --format="%(refname)" >actual &&
456 test_cmp expected actual
459 test_expect_success 'Quoting style: perl' '
460 git for-each-ref --perl --format="%(refname)" >actual &&
461 test_cmp expected actual
464 test_expect_success 'Quoting style: python' '
465 git for-each-ref --python --format="%(refname)" >actual &&
466 test_cmp expected actual
469 cat >expected <<\EOF
470 "refs/heads/main"
471 "refs/remotes/origin/main"
472 "refs/tags/testtag"
475 test_expect_success 'Quoting style: tcl' '
476 git for-each-ref --tcl --format="%(refname)" >actual &&
477 test_cmp expected actual
480 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
481 test_expect_success "more than one quoting style: $i" "
482 test_must_fail git for-each-ref $i 2>err &&
483 grep '^error: more than one quoting style' err
485 done
487 test_expect_success 'setup for upstream:track[short]' '
488 test_commit two
491 test_atom head upstream:track '[ahead 1]'
492 test_atom head upstream:trackshort '>'
493 test_atom head upstream:track,nobracket 'ahead 1'
494 test_atom head upstream:nobracket,track 'ahead 1'
496 test_expect_success 'setup for push:track[short]' '
497 test_commit third &&
498 git update-ref refs/remotes/myfork/main main &&
499 git reset main~1
502 test_atom head push:track '[behind 1]'
503 test_atom head push:trackshort '<'
505 test_expect_success 'Check that :track[short] cannot be used with other atoms' '
506 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
507 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
510 test_expect_success 'Check that :track[short] works when upstream is invalid' '
511 cat >expected <<-\EOF &&
512 [gone]
515 test_when_finished "git config branch.main.merge refs/heads/main" &&
516 git config branch.main.merge refs/heads/does-not-exist &&
517 git for-each-ref \
518 --format="%(upstream:track)$LF%(upstream:trackshort)" \
519 refs/heads >actual &&
520 test_cmp expected actual
523 test_expect_success 'Check for invalid refname format' '
524 test_must_fail git for-each-ref --format="%(refname:INVALID)"
527 test_expect_success 'set up color tests' '
528 cat >expected.color <<-EOF &&
529 $(git rev-parse --short refs/heads/main) <GREEN>main<RESET>
530 $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET>
531 $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET>
532 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
533 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
534 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
536 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
537 color_format="%(objectname:short) %(color:green)%(refname:short)"
540 test_expect_success TTY '%(color) shows color with a tty' '
541 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
542 test_decode_color <actual.raw >actual &&
543 test_cmp expected.color actual
546 test_expect_success '%(color) does not show color without tty' '
547 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
548 test_cmp expected.bare actual
551 test_expect_success '--color can override tty check' '
552 git for-each-ref --color --format="$color_format" >actual.raw &&
553 test_decode_color <actual.raw >actual &&
554 test_cmp expected.color actual
557 test_expect_success 'color.ui=always does not override tty check' '
558 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
559 test_cmp expected.bare actual
562 cat >expected <<\EOF
563 heads/main
564 tags/main
567 test_expect_success 'Check ambiguous head and tag refs (strict)' '
568 git config --bool core.warnambiguousrefs true &&
569 git checkout -b newtag &&
570 echo "Using $datestamp" > one &&
571 git add one &&
572 git commit -m "Branch" &&
573 setdate_and_increment &&
574 git tag -m "Tagging at $datestamp" main &&
575 git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
576 test_cmp expected actual
579 cat >expected <<\EOF
580 heads/main
581 main
584 test_expect_success 'Check ambiguous head and tag refs (loose)' '
585 git config --bool core.warnambiguousrefs false &&
586 git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
587 test_cmp expected actual
590 cat >expected <<\EOF
591 heads/ambiguous
592 ambiguous
595 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
596 git checkout main &&
597 git tag ambiguous testtag^0 &&
598 git branch ambiguous testtag^0 &&
599 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
600 test_cmp expected actual
603 test_expect_success 'create tag without tagger' '
604 git tag -a -m "Broken tag" taggerless &&
605 git tag -f taggerless $(git cat-file tag taggerless |
606 sed -e "/^tagger /d" |
607 git hash-object --stdin -w -t tag)
610 test_atom refs/tags/taggerless type 'commit'
611 test_atom refs/tags/taggerless tag 'taggerless'
612 test_atom refs/tags/taggerless tagger ''
613 test_atom refs/tags/taggerless taggername ''
614 test_atom refs/tags/taggerless taggeremail ''
615 test_atom refs/tags/taggerless taggeremail:trim ''
616 test_atom refs/tags/taggerless taggeremail:localpart ''
617 test_atom refs/tags/taggerless taggerdate ''
618 test_atom refs/tags/taggerless committer ''
619 test_atom refs/tags/taggerless committername ''
620 test_atom refs/tags/taggerless committeremail ''
621 test_atom refs/tags/taggerless committeremail:trim ''
622 test_atom refs/tags/taggerless committeremail:localpart ''
623 test_atom refs/tags/taggerless committerdate ''
624 test_atom refs/tags/taggerless subject 'Broken tag'
626 test_expect_success 'an unusual tag with an incomplete line' '
628 git tag -m "bogo" bogo &&
629 bogo=$(git cat-file tag bogo) &&
630 bogo=$(printf "%s" "$bogo" | git mktag) &&
631 git tag -f bogo "$bogo" &&
632 git for-each-ref --format "%(body)" refs/tags/bogo
636 test_expect_success 'create tag with subject and body content' '
637 cat >>msg <<-\EOF &&
638 the subject line
640 first body line
641 second body line
643 git tag -F msg subject-body
645 test_atom refs/tags/subject-body subject 'the subject line'
646 test_atom refs/tags/subject-body subject:sanitize 'the-subject-line'
647 test_atom refs/tags/subject-body body 'first body line
648 second body line
650 test_atom refs/tags/subject-body contents 'the subject line
652 first body line
653 second body line
656 test_expect_success 'create tag with multiline subject' '
657 cat >msg <<-\EOF &&
658 first subject line
659 second subject line
661 first body line
662 second body line
664 git tag -F msg multiline
666 test_atom refs/tags/multiline subject 'first subject line second subject line'
667 test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line'
668 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
669 test_atom refs/tags/multiline body 'first body line
670 second body line
672 test_atom refs/tags/multiline contents:body 'first body line
673 second body line
675 test_atom refs/tags/multiline contents:signature ''
676 test_atom refs/tags/multiline contents 'first subject line
677 second subject line
679 first body line
680 second body line
683 test_expect_success GPG 'create signed tags' '
684 git tag -s -m "" signed-empty &&
685 git tag -s -m "subject line" signed-short &&
686 cat >msg <<-\EOF &&
687 subject line
689 body contents
691 git tag -s -F msg signed-long
694 sig='-----BEGIN PGP SIGNATURE-----
695 -----END PGP SIGNATURE-----
698 PREREQ=GPG
699 test_atom refs/tags/signed-empty subject ''
700 test_atom refs/tags/signed-empty subject:sanitize ''
701 test_atom refs/tags/signed-empty contents:subject ''
702 test_atom refs/tags/signed-empty body "$sig"
703 test_atom refs/tags/signed-empty contents:body ''
704 test_atom refs/tags/signed-empty contents:signature "$sig"
705 test_atom refs/tags/signed-empty contents "$sig"
707 test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' '
708 git cat-file tag refs/tags/signed-empty >expected &&
709 git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual &&
710 sanitize_pgp <expected >expected.clean &&
711 echo >>expected.clean &&
712 sanitize_pgp <actual >actual.clean &&
713 test_cmp expected.clean actual.clean
716 test_atom refs/tags/signed-short subject 'subject line'
717 test_atom refs/tags/signed-short subject:sanitize 'subject-line'
718 test_atom refs/tags/signed-short contents:subject 'subject line'
719 test_atom refs/tags/signed-short body "$sig"
720 test_atom refs/tags/signed-short contents:body ''
721 test_atom refs/tags/signed-short contents:signature "$sig"
722 test_atom refs/tags/signed-short contents "subject line
723 $sig"
725 test_expect_success GPG 'basic atom: refs/tags/signed-short raw' '
726 git cat-file tag refs/tags/signed-short >expected &&
727 git for-each-ref --format="%(raw)" refs/tags/signed-short >actual &&
728 sanitize_pgp <expected >expected.clean &&
729 echo >>expected.clean &&
730 sanitize_pgp <actual >actual.clean &&
731 test_cmp expected.clean actual.clean
734 test_atom refs/tags/signed-long subject 'subject line'
735 test_atom refs/tags/signed-long subject:sanitize 'subject-line'
736 test_atom refs/tags/signed-long contents:subject 'subject line'
737 test_atom refs/tags/signed-long body "body contents
738 $sig"
739 test_atom refs/tags/signed-long contents:body 'body contents
741 test_atom refs/tags/signed-long contents:signature "$sig"
742 test_atom refs/tags/signed-long contents "subject line
744 body contents
745 $sig"
747 test_expect_success GPG 'basic atom: refs/tags/signed-long raw' '
748 git cat-file tag refs/tags/signed-long >expected &&
749 git for-each-ref --format="%(raw)" refs/tags/signed-long >actual &&
750 sanitize_pgp <expected >expected.clean &&
751 echo >>expected.clean &&
752 sanitize_pgp <actual >actual.clean &&
753 test_cmp expected.clean actual.clean
756 test_expect_success 'set up refs pointing to tree and blob' '
757 git update-ref refs/mytrees/first refs/heads/main^{tree} &&
758 git update-ref refs/myblobs/first refs/heads/main:one
761 test_atom refs/mytrees/first subject ""
762 test_atom refs/mytrees/first contents:subject ""
763 test_atom refs/mytrees/first body ""
764 test_atom refs/mytrees/first contents:body ""
765 test_atom refs/mytrees/first contents:signature ""
766 test_atom refs/mytrees/first contents ""
768 test_expect_success 'basic atom: refs/mytrees/first raw' '
769 git cat-file tree refs/mytrees/first >expected &&
770 echo >>expected &&
771 git for-each-ref --format="%(raw)" refs/mytrees/first >actual &&
772 test_cmp expected actual &&
773 git cat-file -s refs/mytrees/first >expected &&
774 git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual &&
775 test_cmp expected actual
778 test_atom refs/myblobs/first subject ""
779 test_atom refs/myblobs/first contents:subject ""
780 test_atom refs/myblobs/first body ""
781 test_atom refs/myblobs/first contents:body ""
782 test_atom refs/myblobs/first contents:signature ""
783 test_atom refs/myblobs/first contents ""
785 test_expect_success 'basic atom: refs/myblobs/first raw' '
786 git cat-file blob refs/myblobs/first >expected &&
787 echo >>expected &&
788 git for-each-ref --format="%(raw)" refs/myblobs/first >actual &&
789 test_cmp expected actual &&
790 git cat-file -s refs/myblobs/first >expected &&
791 git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual &&
792 test_cmp expected actual
795 test_expect_success 'set up refs pointing to binary blob' '
796 printf "a\0b\0c" >blob1 &&
797 printf "a\0c\0b" >blob2 &&
798 printf "\0a\0b\0c" >blob3 &&
799 printf "abc" >blob4 &&
800 printf "\0 \0 \0 " >blob5 &&
801 printf "\0 \0a\0 " >blob6 &&
802 printf " " >blob7 &&
803 >blob8 &&
804 obj=$(git hash-object -w blob1) &&
805 git update-ref refs/myblobs/blob1 "$obj" &&
806 obj=$(git hash-object -w blob2) &&
807 git update-ref refs/myblobs/blob2 "$obj" &&
808 obj=$(git hash-object -w blob3) &&
809 git update-ref refs/myblobs/blob3 "$obj" &&
810 obj=$(git hash-object -w blob4) &&
811 git update-ref refs/myblobs/blob4 "$obj" &&
812 obj=$(git hash-object -w blob5) &&
813 git update-ref refs/myblobs/blob5 "$obj" &&
814 obj=$(git hash-object -w blob6) &&
815 git update-ref refs/myblobs/blob6 "$obj" &&
816 obj=$(git hash-object -w blob7) &&
817 git update-ref refs/myblobs/blob7 "$obj" &&
818 obj=$(git hash-object -w blob8) &&
819 git update-ref refs/myblobs/blob8 "$obj"
822 test_expect_success 'Verify sorts with raw' '
823 cat >expected <<-EOF &&
824 refs/myblobs/blob8
825 refs/myblobs/blob5
826 refs/myblobs/blob6
827 refs/myblobs/blob3
828 refs/myblobs/blob7
829 refs/mytrees/first
830 refs/myblobs/first
831 refs/myblobs/blob1
832 refs/myblobs/blob2
833 refs/myblobs/blob4
834 refs/heads/main
836 git for-each-ref --format="%(refname)" --sort=raw \
837 refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
838 test_cmp expected actual
841 test_expect_success 'Verify sorts with raw:size' '
842 cat >expected <<-EOF &&
843 refs/myblobs/blob8
844 refs/myblobs/first
845 refs/myblobs/blob7
846 refs/heads/main
847 refs/myblobs/blob4
848 refs/myblobs/blob1
849 refs/myblobs/blob2
850 refs/myblobs/blob3
851 refs/myblobs/blob5
852 refs/myblobs/blob6
853 refs/mytrees/first
855 git for-each-ref --format="%(refname)" --sort=raw:size \
856 refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
857 test_cmp expected actual
860 test_expect_success 'validate raw atom with %(if:equals)' '
861 cat >expected <<-EOF &&
862 not equals
863 not equals
864 not equals
865 not equals
866 not equals
867 not equals
868 refs/myblobs/blob4
869 not equals
870 not equals
871 not equals
872 not equals
873 not equals
875 git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \
876 refs/myblobs/ refs/heads/ >actual &&
877 test_cmp expected actual
880 test_expect_success 'validate raw atom with %(if:notequals)' '
881 cat >expected <<-EOF &&
882 refs/heads/ambiguous
883 refs/heads/main
884 refs/heads/newtag
885 refs/myblobs/blob1
886 refs/myblobs/blob2
887 refs/myblobs/blob3
888 equals
889 refs/myblobs/blob5
890 refs/myblobs/blob6
891 refs/myblobs/blob7
892 refs/myblobs/blob8
893 refs/myblobs/first
895 git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \
896 refs/myblobs/ refs/heads/ >actual &&
897 test_cmp expected actual
900 test_expect_success 'empty raw refs with %(if)' '
901 cat >expected <<-EOF &&
902 refs/myblobs/blob1 not empty
903 refs/myblobs/blob2 not empty
904 refs/myblobs/blob3 not empty
905 refs/myblobs/blob4 not empty
906 refs/myblobs/blob5 not empty
907 refs/myblobs/blob6 not empty
908 refs/myblobs/blob7 empty
909 refs/myblobs/blob8 empty
910 refs/myblobs/first not empty
912 git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \
913 refs/myblobs/ >actual &&
914 test_cmp expected actual
917 test_expect_success '%(raw) with --python must fail' '
918 test_must_fail git for-each-ref --format="%(raw)" --python
921 test_expect_success '%(raw) with --tcl must fail' '
922 test_must_fail git for-each-ref --format="%(raw)" --tcl
925 test_expect_success '%(raw) with --perl' '
926 git for-each-ref --format="\$name= %(raw);
927 print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual &&
928 cmp blob1 actual &&
929 git for-each-ref --format="\$name= %(raw);
930 print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual &&
931 cmp blob3 actual &&
932 git for-each-ref --format="\$name= %(raw);
933 print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual &&
934 cmp blob8 actual &&
935 git for-each-ref --format="\$name= %(raw);
936 print \"\$name\"" refs/myblobs/first --perl | perl >actual &&
937 cmp one actual &&
938 git cat-file tree refs/mytrees/first > expected &&
939 git for-each-ref --format="\$name= %(raw);
940 print \"\$name\"" refs/mytrees/first --perl | perl >actual &&
941 cmp expected actual
944 test_expect_success '%(raw) with --shell must fail' '
945 test_must_fail git for-each-ref --format="%(raw)" --shell
948 test_expect_success '%(raw) with --shell and --sort=raw must fail' '
949 test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell
952 test_expect_success '%(raw:size) with --shell' '
953 git for-each-ref --format="%(raw:size)" | while read line
955 echo "'\''$line'\''" >>expect
956 done &&
957 git for-each-ref --format="%(raw:size)" --shell >actual &&
958 test_cmp expect actual
961 test_expect_success 'for-each-ref --format compare with cat-file --batch' '
962 git rev-parse refs/mytrees/first | git cat-file --batch >expected &&
963 git for-each-ref --format="%(objectname) %(objecttype) %(objectsize)
964 %(raw)" refs/mytrees/first >actual &&
965 test_cmp expected actual
968 test_expect_success 'set up multiple-sort tags' '
969 for when in 100000 200000
971 for email in user1 user2
973 for ref in ref1 ref2
975 GIT_COMMITTER_DATE="@$when +0000" \
976 GIT_COMMITTER_EMAIL="$email@example.com" \
977 git tag -m "tag $ref-$when-$email" \
978 multi-$ref-$when-$email || return 1
979 done
980 done
981 done
984 test_expect_success 'Verify sort with multiple keys' '
985 cat >expected <<-\EOF &&
986 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
987 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
988 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
989 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
990 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
991 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
992 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
993 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
995 git for-each-ref \
996 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
997 --sort=-refname \
998 --sort=taggeremail \
999 --sort=taggerdate \
1000 "refs/tags/multi-*" >actual &&
1001 test_cmp expected actual
1004 test_expect_success 'equivalent sorts fall back on refname' '
1005 cat >expected <<-\EOF &&
1006 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1007 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1008 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1009 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1010 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1011 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1012 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1013 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1015 git for-each-ref \
1016 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1017 --sort=taggerdate \
1018 "refs/tags/multi-*" >actual &&
1019 test_cmp expected actual
1022 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
1023 test_when_finished "git checkout main" &&
1024 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
1025 sed -e "s/^\* / /" actual >expect &&
1026 git checkout --orphan orphaned-branch &&
1027 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
1028 test_cmp expect actual
1031 cat >trailers <<EOF
1032 Reviewed-by: A U Thor <author@example.com>
1033 Signed-off-by: A U Thor <author@example.com>
1034 [ v2 updated patch description ]
1035 Acked-by: A U Thor
1036 <author@example.com>
1039 unfold () {
1040 perl -0pe 's/\n\s+/ /g'
1043 test_expect_success 'set up trailers for next test' '
1044 echo "Some contents" > two &&
1045 git add two &&
1046 git commit -F - <<-EOF
1047 trailers: this commit message has trailers
1049 Some message contents
1051 $(cat trailers)
1055 test_trailer_option () {
1056 title=$1 option=$2
1057 cat >expect
1058 test_expect_success "$title" '
1059 git for-each-ref --format="%($option)" refs/heads/main >actual &&
1060 test_cmp expect actual &&
1061 git for-each-ref --format="%(contents:$option)" refs/heads/main >actual &&
1062 test_cmp expect actual
1066 test_trailer_option '%(trailers:unfold) unfolds trailers' \
1067 'trailers:unfold' <<-EOF
1068 $(unfold <trailers)
1072 test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
1073 'trailers:only' <<-EOF
1074 $(grep -v patch.description <trailers)
1078 test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \
1079 'trailers:only=no,only=true' <<-EOF
1080 $(grep -v patch.description <trailers)
1084 test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \
1085 'trailers:only=yes' <<-EOF
1086 $(grep -v patch.description <trailers)
1090 test_trailer_option '%(trailers:only=no) shows all trailers' \
1091 'trailers:only=no' <<-EOF
1092 $(cat trailers)
1096 test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
1097 'trailers:only,unfold' <<-EOF
1098 $(grep -v patch.description <trailers | unfold)
1102 test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \
1103 'trailers:unfold,only' <<-EOF
1104 $(grep -v patch.description <trailers | unfold)
1108 test_trailer_option '%(trailers:key=foo) shows that trailer' \
1109 'trailers:key=Signed-off-by' <<-EOF
1110 Signed-off-by: A U Thor <author@example.com>
1114 test_trailer_option '%(trailers:key=foo) is case insensitive' \
1115 'trailers:key=SiGned-oFf-bY' <<-EOF
1116 Signed-off-by: A U Thor <author@example.com>
1120 test_trailer_option '%(trailers:key=foo:) trailing colon also works' \
1121 'trailers:key=Signed-off-by:' <<-EOF
1122 Signed-off-by: A U Thor <author@example.com>
1126 test_trailer_option '%(trailers:key=foo) multiple keys' \
1127 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF
1128 Reviewed-by: A U Thor <author@example.com>
1129 Signed-off-by: A U Thor <author@example.com>
1133 test_trailer_option '%(trailers:key=nonexistent) becomes empty' \
1134 'trailers:key=Shined-off-by:' <<-EOF
1138 test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \
1139 'trailers:key=Acked-by' <<-EOF
1140 $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by)
1144 test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \
1145 'trailers:key=Signed-Off-by,unfold' <<-EOF
1146 $(unfold <trailers | grep Signed-off-by)
1150 test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \
1151 'trailers:key=Signed-off-by,only=no' <<-EOF
1152 Signed-off-by: A U Thor <author@example.com>
1153 $(grep patch.description <trailers)
1157 test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \
1158 'trailers:key=Signed-off-by,valueonly' <<-EOF
1159 A U Thor <author@example.com>
1163 test_trailer_option '%(trailers:separator) changes separator' \
1164 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1165 Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com>
1168 test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \
1169 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1170 Reviewed-by,A U Thor <author@example.com>
1171 Signed-off-by,A U Thor <author@example.com>
1175 test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \
1176 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1177 Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com>
1180 test_failing_trailer_option () {
1181 title=$1 option=$2
1182 cat >expect
1183 test_expect_success "$title" '
1184 # error message cannot be checked under i18n
1185 test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual &&
1186 test_cmp expect actual &&
1187 test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual &&
1188 test_cmp expect actual
1192 test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
1193 'trailers:unsupported' <<-\EOF
1194 fatal: unknown %(trailers) argument: unsupported
1197 test_failing_trailer_option '%(trailers:key) without value is error' \
1198 'trailers:key' <<-\EOF
1199 fatal: expected %(trailers:key=<value>)
1202 test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
1203 cat >expect <<-EOF &&
1204 fatal: unrecognized %(contents) argument: trailersonly
1206 test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
1207 test_cmp expect actual
1210 test_expect_success 'basic atom: head contents:trailers' '
1211 git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual &&
1212 sanitize_pgp <actual >actual.clean &&
1213 # git for-each-ref ends with a blank line
1214 cat >expect <<-EOF &&
1215 $(cat trailers)
1218 test_cmp expect actual.clean
1221 test_expect_success 'basic atom: rest must fail' '
1222 test_must_fail git for-each-ref --format="%(rest)" refs/heads/main
1225 test_expect_success 'trailer parsing not fooled by --- line' '
1226 git commit --allow-empty -F - <<-\EOF &&
1227 this is the subject
1229 This is the body. The message has a "---" line which would confuse a
1230 message+patch parser. But here we know we have only a commit message,
1231 so we get it right.
1233 trailer: wrong
1235 This is more body.
1237 trailer: right
1241 echo "trailer: right" &&
1242 echo
1243 } >expect &&
1244 git for-each-ref --format="%(trailers)" refs/heads/main >actual &&
1245 test_cmp expect actual
1248 test_expect_success 'Add symbolic ref for the following tests' '
1249 git symbolic-ref refs/heads/sym refs/heads/main
1252 cat >expected <<EOF
1253 refs/heads/main
1256 test_expect_success 'Verify usage of %(symref) atom' '
1257 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
1258 test_cmp expected actual
1261 cat >expected <<EOF
1262 heads/main
1265 test_expect_success 'Verify usage of %(symref:short) atom' '
1266 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
1267 test_cmp expected actual
1270 cat >expected <<EOF
1271 main
1272 heads/main
1275 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
1276 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
1277 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
1278 test_cmp expected actual &&
1280 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
1281 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
1282 test_cmp expected actual
1285 cat >expected <<EOF
1286 refs
1287 refs/heads
1290 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
1291 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
1292 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
1293 test_cmp expected actual
1296 test_expect_success ':remotename and :remoteref' '
1297 git init remote-tests &&
1299 cd remote-tests &&
1300 test_commit initial &&
1301 git branch -M main &&
1302 git remote add from fifth.coffee:blub &&
1303 git config branch.main.remote from &&
1304 git config branch.main.merge refs/heads/stable &&
1305 git remote add to southridge.audio:repo &&
1306 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
1307 git config branch.main.pushRemote to &&
1308 for pair in "%(upstream)=refs/remotes/from/stable" \
1309 "%(upstream:remotename)=from" \
1310 "%(upstream:remoteref)=refs/heads/stable" \
1311 "%(push)=refs/remotes/to/pushed/main" \
1312 "%(push:remotename)=to" \
1313 "%(push:remoteref)=refs/heads/pushed/main"
1315 echo "${pair#*=}" >expect &&
1316 git for-each-ref --format="${pair%=*}" \
1317 refs/heads/main >actual &&
1318 test_cmp expect actual
1319 done &&
1320 git branch push-simple &&
1321 git config branch.push-simple.pushRemote from &&
1322 actual="$(git for-each-ref \
1323 --format="%(push:remotename),%(push:remoteref)" \
1324 refs/heads/push-simple)" &&
1325 test from, = "$actual"
1329 test_expect_success 'for-each-ref --ignore-case ignores case' '
1330 git for-each-ref --format="%(refname)" refs/heads/MAIN >actual &&
1331 test_must_be_empty actual &&
1333 echo refs/heads/main >expect &&
1334 git for-each-ref --format="%(refname)" --ignore-case \
1335 refs/heads/MAIN >actual &&
1336 test_cmp expect actual
1339 test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
1340 # name refs numerically to avoid case-insensitive filesystem conflicts
1341 nr=0 &&
1342 for email in a A b B
1344 for subject in a A b B
1346 GIT_COMMITTER_EMAIL="$email@example.com" \
1347 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
1348 nr=$((nr+1))||
1349 return 1
1350 done
1351 done &&
1352 git for-each-ref --ignore-case \
1353 --format="%(taggeremail) %(subject) %(refname)" \
1354 --sort=refname \
1355 --sort=subject \
1356 --sort=taggeremail \
1357 refs/tags/icase-* >actual &&
1358 cat >expect <<-\EOF &&
1359 <a@example.com> tag a refs/tags/icase-00
1360 <a@example.com> tag A refs/tags/icase-01
1361 <A@example.com> tag a refs/tags/icase-04
1362 <A@example.com> tag A refs/tags/icase-05
1363 <a@example.com> tag b refs/tags/icase-02
1364 <a@example.com> tag B refs/tags/icase-03
1365 <A@example.com> tag b refs/tags/icase-06
1366 <A@example.com> tag B refs/tags/icase-07
1367 <b@example.com> tag a refs/tags/icase-08
1368 <b@example.com> tag A refs/tags/icase-09
1369 <B@example.com> tag a refs/tags/icase-12
1370 <B@example.com> tag A refs/tags/icase-13
1371 <b@example.com> tag b refs/tags/icase-10
1372 <b@example.com> tag B refs/tags/icase-11
1373 <B@example.com> tag b refs/tags/icase-14
1374 <B@example.com> tag B refs/tags/icase-15
1376 test_cmp expect actual
1379 test_expect_success 'for-each-ref reports broken tags' '
1380 git tag -m "good tag" broken-tag-good HEAD &&
1381 git cat-file tag broken-tag-good >good &&
1382 sed s/commit/blob/ <good >bad &&
1383 bad=$(git hash-object -w -t tag bad) &&
1384 git update-ref refs/tags/broken-tag-bad $bad &&
1385 test_must_fail git for-each-ref --format="%(*objectname)" \
1386 refs/tags/broken-tag-*
1389 test_done