sha1-name.c: move around the collect_ambiguous() function
[git.git] / t / t6300-for-each-ref.sh
blob295d1475bde0151df65e0098e6e4a169193906ed
1 #!/bin/sh
3 # Copyright (c) 2007 Andy Parkins
6 test_description='for-each-ref test'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-gpg.sh
10 . "$TEST_DIRECTORY"/lib-terminal.sh
12 # Mon Jul 3 23:18:43 2006 +0000
13 datestamp=1151968723
14 setdate_and_increment () {
15 GIT_COMMITTER_DATE="$datestamp +0200"
16 datestamp=$(expr "$datestamp" + 1)
17 GIT_AUTHOR_DATE="$datestamp +0200"
18 datestamp=$(expr "$datestamp" + 1)
19 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
22 test_expect_success setup '
23 setdate_and_increment &&
24 echo "Using $datestamp" > one &&
25 git add one &&
26 git commit -m "Initial" &&
27 setdate_and_increment &&
28 git tag -a -m "Tagging at $datestamp" testtag &&
29 git update-ref refs/remotes/origin/master master &&
30 git remote add origin nowhere &&
31 git config branch.master.remote origin &&
32 git config branch.master.merge refs/heads/master &&
33 git remote add myfork elsewhere &&
34 git config remote.pushdefault myfork &&
35 git config push.default current
38 test_atom() {
39 case "$1" in
40 head) ref=refs/heads/master ;;
41 tag) ref=refs/tags/testtag ;;
42 sym) ref=refs/heads/sym ;;
43 *) ref=$1 ;;
44 esac
45 printf '%s\n' "$3" >expected
46 test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
47 git for-each-ref --format='%($2)' $ref >actual &&
48 sanitize_pgp <actual >actual.clean &&
49 test_cmp expected actual.clean
53 test_atom head refname refs/heads/master
54 test_atom head refname: refs/heads/master
55 test_atom head refname:short master
56 test_atom head refname:lstrip=1 heads/master
57 test_atom head refname:lstrip=2 master
58 test_atom head refname:lstrip=-1 master
59 test_atom head refname:lstrip=-2 heads/master
60 test_atom head refname:rstrip=1 refs/heads
61 test_atom head refname:rstrip=2 refs
62 test_atom head refname:rstrip=-1 refs
63 test_atom head refname:rstrip=-2 refs/heads
64 test_atom head refname:strip=1 heads/master
65 test_atom head refname:strip=2 master
66 test_atom head refname:strip=-1 master
67 test_atom head refname:strip=-2 heads/master
68 test_atom head upstream refs/remotes/origin/master
69 test_atom head upstream:short origin/master
70 test_atom head upstream:lstrip=2 origin/master
71 test_atom head upstream:lstrip=-2 origin/master
72 test_atom head upstream:rstrip=2 refs/remotes
73 test_atom head upstream:rstrip=-2 refs/remotes
74 test_atom head upstream:strip=2 origin/master
75 test_atom head upstream:strip=-2 origin/master
76 test_atom head push refs/remotes/myfork/master
77 test_atom head push:short myfork/master
78 test_atom head push:lstrip=1 remotes/myfork/master
79 test_atom head push:lstrip=-1 master
80 test_atom head push:rstrip=1 refs/remotes/myfork
81 test_atom head push:rstrip=-1 refs
82 test_atom head push:strip=1 remotes/myfork/master
83 test_atom head push:strip=-1 master
84 test_atom head objecttype commit
85 test_atom head objectsize 171
86 test_atom head objectname $(git rev-parse refs/heads/master)
87 test_atom head objectname:short $(git rev-parse --short refs/heads/master)
88 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
89 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
90 test_atom head tree $(git rev-parse refs/heads/master^{tree})
91 test_atom head parent ''
92 test_atom head numparent 0
93 test_atom head object ''
94 test_atom head type ''
95 test_atom head '*objectname' ''
96 test_atom head '*objecttype' ''
97 test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
98 test_atom head authorname 'A U Thor'
99 test_atom head authoremail '<author@example.com>'
100 test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
101 test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
102 test_atom head committername 'C O Mitter'
103 test_atom head committeremail '<committer@example.com>'
104 test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
105 test_atom head tag ''
106 test_atom head tagger ''
107 test_atom head taggername ''
108 test_atom head taggeremail ''
109 test_atom head taggerdate ''
110 test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
111 test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
112 test_atom head subject 'Initial'
113 test_atom head contents:subject 'Initial'
114 test_atom head body ''
115 test_atom head contents:body ''
116 test_atom head contents:signature ''
117 test_atom head contents 'Initial
119 test_atom head HEAD '*'
121 test_atom tag refname refs/tags/testtag
122 test_atom tag refname:short testtag
123 test_atom tag upstream ''
124 test_atom tag push ''
125 test_atom tag objecttype tag
126 test_atom tag objectsize 154
127 test_atom tag objectname $(git rev-parse refs/tags/testtag)
128 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
129 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
130 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
131 test_atom tag tree ''
132 test_atom tag parent ''
133 test_atom tag numparent ''
134 test_atom tag object $(git rev-parse refs/tags/testtag^0)
135 test_atom tag type 'commit'
136 test_atom tag '*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463'
137 test_atom tag '*objecttype' 'commit'
138 test_atom tag author ''
139 test_atom tag authorname ''
140 test_atom tag authoremail ''
141 test_atom tag authordate ''
142 test_atom tag committer ''
143 test_atom tag committername ''
144 test_atom tag committeremail ''
145 test_atom tag committerdate ''
146 test_atom tag tag 'testtag'
147 test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
148 test_atom tag taggername 'C O Mitter'
149 test_atom tag taggeremail '<committer@example.com>'
150 test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
151 test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
152 test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
153 test_atom tag subject 'Tagging at 1151968727'
154 test_atom tag contents:subject 'Tagging at 1151968727'
155 test_atom tag body ''
156 test_atom tag contents:body ''
157 test_atom tag contents:signature ''
158 test_atom tag contents 'Tagging at 1151968727
160 test_atom tag HEAD ' '
162 test_expect_success 'Check invalid atoms names are errors' '
163 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
166 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
167 git for-each-ref --format="%(authordate)" refs/heads &&
168 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
169 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
170 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
173 test_expect_success 'Check valid format specifiers for date fields' '
174 git for-each-ref --format="%(authordate:default)" refs/heads &&
175 git for-each-ref --format="%(authordate:relative)" refs/heads &&
176 git for-each-ref --format="%(authordate:short)" refs/heads &&
177 git for-each-ref --format="%(authordate:local)" refs/heads &&
178 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
179 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
182 test_expect_success 'Check invalid format specifiers are errors' '
183 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
186 test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
187 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
188 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
189 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
192 test_date () {
193 f=$1 &&
194 committer_date=$2 &&
195 author_date=$3 &&
196 tagger_date=$4 &&
197 cat >expected <<-EOF &&
198 'refs/heads/master' '$committer_date' '$author_date'
199 'refs/tags/testtag' '$tagger_date'
202 git for-each-ref --shell \
203 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
204 refs/heads &&
205 git for-each-ref --shell \
206 --format="%(refname) %(taggerdate${f:+:$f})" \
207 refs/tags
208 ) >actual &&
209 test_cmp expected actual
212 test_expect_success 'Check unformatted date fields output' '
213 test_date "" \
214 "Tue Jul 4 01:18:43 2006 +0200" \
215 "Tue Jul 4 01:18:44 2006 +0200" \
216 "Tue Jul 4 01:18:45 2006 +0200"
219 test_expect_success 'Check format "default" formatted date fields output' '
220 test_date default \
221 "Tue Jul 4 01:18:43 2006 +0200" \
222 "Tue Jul 4 01:18:44 2006 +0200" \
223 "Tue Jul 4 01:18:45 2006 +0200"
226 test_expect_success 'Check format "default-local" date fields output' '
227 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"
230 # Don't know how to do relative check because I can't know when this script
231 # is going to be run and can't fake the current time to git, and hence can't
232 # provide expected output. Instead, I'll just make sure that "relative"
233 # doesn't exit in error
234 test_expect_success 'Check format "relative" date fields output' '
235 f=relative &&
236 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
237 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
240 # We just check that this is the same as "relative" for now.
241 test_expect_success 'Check format "relative-local" date fields output' '
242 test_date relative-local \
243 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
244 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
245 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
248 test_expect_success 'Check format "short" date fields output' '
249 test_date short 2006-07-04 2006-07-04 2006-07-04
252 test_expect_success 'Check format "short-local" date fields output' '
253 test_date short-local 2006-07-03 2006-07-03 2006-07-03
256 test_expect_success 'Check format "local" date fields output' '
257 test_date local \
258 "Mon Jul 3 23:18:43 2006" \
259 "Mon Jul 3 23:18:44 2006" \
260 "Mon Jul 3 23:18:45 2006"
263 test_expect_success 'Check format "iso8601" date fields output' '
264 test_date iso8601 \
265 "2006-07-04 01:18:43 +0200" \
266 "2006-07-04 01:18:44 +0200" \
267 "2006-07-04 01:18:45 +0200"
270 test_expect_success 'Check format "iso8601-local" date fields output' '
271 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"
274 test_expect_success 'Check format "rfc2822" date fields output' '
275 test_date rfc2822 \
276 "Tue, 4 Jul 2006 01:18:43 +0200" \
277 "Tue, 4 Jul 2006 01:18:44 +0200" \
278 "Tue, 4 Jul 2006 01:18:45 +0200"
281 test_expect_success 'Check format "rfc2822-local" date fields output' '
282 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"
285 test_expect_success 'Check format "raw" date fields output' '
286 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
289 test_expect_success 'Check format "raw-local" date fields output' '
290 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
293 test_expect_success 'Check format of strftime date fields' '
294 echo "my date is 2006-07-04" >expected &&
295 git for-each-ref \
296 --format="%(authordate:format:my date is %Y-%m-%d)" \
297 refs/heads >actual &&
298 test_cmp expected actual
301 test_expect_success 'Check format of strftime-local date fields' '
302 echo "my date is 2006-07-03" >expected &&
303 git for-each-ref \
304 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
305 refs/heads >actual &&
306 test_cmp expected actual
309 test_expect_success 'exercise strftime with odd fields' '
310 echo >expected &&
311 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
312 test_cmp expected actual &&
313 long="long format -- $_z40$_z40$_z40$_z40$_z40$_z40$_z40" &&
314 echo $long >expected &&
315 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
316 test_cmp expected actual
319 cat >expected <<\EOF
320 refs/heads/master
321 refs/remotes/origin/master
322 refs/tags/testtag
325 test_expect_success 'Verify ascending sort' '
326 git for-each-ref --format="%(refname)" --sort=refname >actual &&
327 test_cmp expected actual
331 cat >expected <<\EOF
332 refs/tags/testtag
333 refs/remotes/origin/master
334 refs/heads/master
337 test_expect_success 'Verify descending sort' '
338 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
339 test_cmp expected actual
342 cat >expected <<\EOF
343 'refs/heads/master'
344 'refs/remotes/origin/master'
345 'refs/tags/testtag'
348 test_expect_success 'Quoting style: shell' '
349 git for-each-ref --shell --format="%(refname)" >actual &&
350 test_cmp expected actual
353 test_expect_success 'Quoting style: perl' '
354 git for-each-ref --perl --format="%(refname)" >actual &&
355 test_cmp expected actual
358 test_expect_success 'Quoting style: python' '
359 git for-each-ref --python --format="%(refname)" >actual &&
360 test_cmp expected actual
363 cat >expected <<\EOF
364 "refs/heads/master"
365 "refs/remotes/origin/master"
366 "refs/tags/testtag"
369 test_expect_success 'Quoting style: tcl' '
370 git for-each-ref --tcl --format="%(refname)" >actual &&
371 test_cmp expected actual
374 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
375 test_expect_success "more than one quoting style: $i" "
376 test_must_fail git for-each-ref $i 2>err &&
377 grep '^error: more than one quoting style' err
379 done
381 test_expect_success 'setup for upstream:track[short]' '
382 test_commit two
385 test_atom head upstream:track '[ahead 1]'
386 test_atom head upstream:trackshort '>'
387 test_atom head upstream:track,nobracket 'ahead 1'
388 test_atom head upstream:nobracket,track 'ahead 1'
389 test_atom head push:track '[ahead 1]'
390 test_atom head push:trackshort '>'
392 test_expect_success 'Check that :track[short] cannot be used with other atoms' '
393 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
394 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
397 test_expect_success 'Check that :track[short] works when upstream is invalid' '
398 cat >expected <<-\EOF &&
399 [gone]
402 test_when_finished "git config branch.master.merge refs/heads/master" &&
403 git config branch.master.merge refs/heads/does-not-exist &&
404 git for-each-ref \
405 --format="%(upstream:track)$LF%(upstream:trackshort)" \
406 refs/heads >actual &&
407 test_cmp expected actual
410 test_expect_success 'Check for invalid refname format' '
411 test_must_fail git for-each-ref --format="%(refname:INVALID)"
414 test_expect_success 'set up color tests' '
415 cat >expected.color <<-EOF &&
416 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
417 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
418 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
419 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
421 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
422 color_format="%(objectname:short) %(color:green)%(refname:short)"
425 test_expect_success TTY '%(color) shows color with a tty' '
426 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
427 test_decode_color <actual.raw >actual &&
428 test_cmp expected.color actual
431 test_expect_success '%(color) does not show color without tty' '
432 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
433 test_cmp expected.bare actual
436 test_expect_success '--color can override tty check' '
437 git for-each-ref --color --format="$color_format" >actual.raw &&
438 test_decode_color <actual.raw >actual &&
439 test_cmp expected.color actual
442 test_expect_success 'color.ui=always does not override tty check' '
443 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
444 test_cmp expected.bare actual
447 cat >expected <<\EOF
448 heads/master
449 tags/master
452 test_expect_success 'Check ambiguous head and tag refs (strict)' '
453 git config --bool core.warnambiguousrefs true &&
454 git checkout -b newtag &&
455 echo "Using $datestamp" > one &&
456 git add one &&
457 git commit -m "Branch" &&
458 setdate_and_increment &&
459 git tag -m "Tagging at $datestamp" master &&
460 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
461 test_cmp expected actual
464 cat >expected <<\EOF
465 heads/master
466 master
469 test_expect_success 'Check ambiguous head and tag refs (loose)' '
470 git config --bool core.warnambiguousrefs false &&
471 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
472 test_cmp expected actual
475 cat >expected <<\EOF
476 heads/ambiguous
477 ambiguous
480 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
481 git checkout master &&
482 git tag ambiguous testtag^0 &&
483 git branch ambiguous testtag^0 &&
484 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
485 test_cmp expected actual
488 test_expect_success 'an unusual tag with an incomplete line' '
490 git tag -m "bogo" bogo &&
491 bogo=$(git cat-file tag bogo) &&
492 bogo=$(printf "%s" "$bogo" | git mktag) &&
493 git tag -f bogo "$bogo" &&
494 git for-each-ref --format "%(body)" refs/tags/bogo
498 test_expect_success 'create tag with subject and body content' '
499 cat >>msg <<-\EOF &&
500 the subject line
502 first body line
503 second body line
505 git tag -F msg subject-body
507 test_atom refs/tags/subject-body subject 'the subject line'
508 test_atom refs/tags/subject-body body 'first body line
509 second body line
511 test_atom refs/tags/subject-body contents 'the subject line
513 first body line
514 second body line
517 test_expect_success 'create tag with multiline subject' '
518 cat >msg <<-\EOF &&
519 first subject line
520 second subject line
522 first body line
523 second body line
525 git tag -F msg multiline
527 test_atom refs/tags/multiline subject 'first subject line second subject line'
528 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
529 test_atom refs/tags/multiline body 'first body line
530 second body line
532 test_atom refs/tags/multiline contents:body 'first body line
533 second body line
535 test_atom refs/tags/multiline contents:signature ''
536 test_atom refs/tags/multiline contents 'first subject line
537 second subject line
539 first body line
540 second body line
543 test_expect_success GPG 'create signed tags' '
544 git tag -s -m "" signed-empty &&
545 git tag -s -m "subject line" signed-short &&
546 cat >msg <<-\EOF &&
547 subject line
549 body contents
551 git tag -s -F msg signed-long
554 sig='-----BEGIN PGP SIGNATURE-----
555 -----END PGP SIGNATURE-----
558 PREREQ=GPG
559 test_atom refs/tags/signed-empty subject ''
560 test_atom refs/tags/signed-empty contents:subject ''
561 test_atom refs/tags/signed-empty body "$sig"
562 test_atom refs/tags/signed-empty contents:body ''
563 test_atom refs/tags/signed-empty contents:signature "$sig"
564 test_atom refs/tags/signed-empty contents "$sig"
566 test_atom refs/tags/signed-short subject 'subject line'
567 test_atom refs/tags/signed-short contents:subject 'subject line'
568 test_atom refs/tags/signed-short body "$sig"
569 test_atom refs/tags/signed-short contents:body ''
570 test_atom refs/tags/signed-short contents:signature "$sig"
571 test_atom refs/tags/signed-short contents "subject line
572 $sig"
574 test_atom refs/tags/signed-long subject 'subject line'
575 test_atom refs/tags/signed-long contents:subject 'subject line'
576 test_atom refs/tags/signed-long body "body contents
577 $sig"
578 test_atom refs/tags/signed-long contents:body 'body contents
580 test_atom refs/tags/signed-long contents:signature "$sig"
581 test_atom refs/tags/signed-long contents "subject line
583 body contents
584 $sig"
586 cat >expected <<EOF
587 $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
588 $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
591 test_expect_success 'Verify sort with multiple keys' '
592 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
593 refs/tags/bogo refs/tags/master > actual &&
594 test_cmp expected actual
598 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
599 test_when_finished "git checkout master" &&
600 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
601 sed -e "s/^\* / /" actual >expect &&
602 git checkout --orphan orphaned-branch &&
603 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
604 test_cmp expect actual
607 cat >trailers <<EOF
608 Reviewed-by: A U Thor <author@example.com>
609 Signed-off-by: A U Thor <author@example.com>
610 [ v2 updated patch description ]
611 Acked-by: A U Thor
612 <author@example.com>
615 unfold () {
616 perl -0pe 's/\n\s+/ /g'
619 test_expect_success 'set up trailers for next test' '
620 echo "Some contents" > two &&
621 git add two &&
622 git commit -F - <<-EOF
623 trailers: this commit message has trailers
625 Some message contents
627 $(cat trailers)
631 test_expect_success '%(trailers:unfold) unfolds trailers' '
632 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
634 unfold <trailers
635 echo
636 } >expect &&
637 test_cmp expect actual
640 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
641 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
643 grep -v patch.description <trailers &&
644 echo
645 } >expect &&
646 test_cmp expect actual
649 test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
650 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
651 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
652 test_cmp actual reverse &&
654 grep -v patch.description <trailers | unfold &&
655 echo
656 } >expect &&
657 test_cmp expect actual
660 test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
661 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
663 unfold <trailers
664 echo
665 } >expect &&
666 test_cmp expect actual
669 test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
670 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
672 grep -v patch.description <trailers &&
673 echo
674 } >expect &&
675 test_cmp expect actual
678 test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
679 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
680 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
681 test_cmp actual reverse &&
683 grep -v patch.description <trailers | unfold &&
684 echo
685 } >expect &&
686 test_cmp expect actual
689 test_expect_success '%(trailers) rejects unknown trailers arguments' '
690 # error message cannot be checked under i18n
691 cat >expect <<-EOF &&
692 fatal: unknown %(trailers) argument: unsupported
694 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
695 test_i18ncmp expect actual
698 test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
699 # error message cannot be checked under i18n
700 cat >expect <<-EOF &&
701 fatal: unknown %(trailers) argument: unsupported
703 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
704 test_i18ncmp expect actual
707 test_expect_success 'basic atom: head contents:trailers' '
708 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
709 sanitize_pgp <actual >actual.clean &&
710 # git for-each-ref ends with a blank line
711 cat >expect <<-EOF &&
712 $(cat trailers)
715 test_cmp expect actual.clean
718 test_expect_success 'Add symbolic ref for the following tests' '
719 git symbolic-ref refs/heads/sym refs/heads/master
722 cat >expected <<EOF
723 refs/heads/master
726 test_expect_success 'Verify usage of %(symref) atom' '
727 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
728 test_cmp expected actual
731 cat >expected <<EOF
732 heads/master
735 test_expect_success 'Verify usage of %(symref:short) atom' '
736 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
737 test_cmp expected actual
740 cat >expected <<EOF
741 master
742 heads/master
745 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
746 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
747 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
748 test_cmp expected actual &&
750 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
751 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
752 test_cmp expected actual
755 cat >expected <<EOF
756 refs
757 refs/heads
760 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
761 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
762 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
763 test_cmp expected actual
766 test_expect_success ':remotename and :remoteref' '
767 git init remote-tests &&
769 cd remote-tests &&
770 test_commit initial &&
771 git remote add from fifth.coffee:blub &&
772 git config branch.master.remote from &&
773 git config branch.master.merge refs/heads/stable &&
774 git remote add to southridge.audio:repo &&
775 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
776 git config branch.master.pushRemote to &&
777 for pair in "%(upstream)=refs/remotes/from/stable" \
778 "%(upstream:remotename)=from" \
779 "%(upstream:remoteref)=refs/heads/stable" \
780 "%(push)=refs/remotes/to/pushed/master" \
781 "%(push:remotename)=to" \
782 "%(push:remoteref)=refs/heads/pushed/master"
784 echo "${pair#*=}" >expect &&
785 git for-each-ref --format="${pair%=*}" \
786 refs/heads/master >actual &&
787 test_cmp expect actual
788 done &&
789 git branch push-simple &&
790 git config branch.push-simple.pushRemote from &&
791 actual="$(git for-each-ref \
792 --format="%(push:remotename),%(push:remoteref)" \
793 refs/heads/push-simple)" &&
794 test from, = "$actual"
798 test_done