3 # Copyright (c) 2007 Andy Parkins
6 test_description
='for-each-ref test'
9 .
"$TEST_DIRECTORY"/lib-gpg.sh
10 .
"$TEST_DIRECTORY"/lib-terminal.sh
12 # Mon Jul 3 23:18:43 2006 +0000
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 &&
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
40 head) ref
=refs
/heads
/master
;;
41 tag
) ref
=refs
/tags
/testtag
;;
42 sym
) ref
=refs
/heads
/sym
;;
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 objectsize
:disk
138
87 test_atom
head deltabase
0000000000000000000000000000000000000000
88 test_atom
head objectname $
(git rev-parse refs
/heads
/master
)
89 test_atom
head objectname
:short $
(git rev-parse
--short refs
/heads
/master
)
90 test_atom
head objectname
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/master
)
91 test_atom
head objectname
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/master
)
92 test_atom
head tree $
(git rev-parse refs
/heads
/master^
{tree
})
93 test_atom
head parent
''
94 test_atom
head numparent
0
95 test_atom
head object
''
96 test_atom
head type ''
97 test_atom
head '*objectname' ''
98 test_atom
head '*objecttype' ''
99 test_atom
head author
'A U Thor <author@example.com> 1151968724 +0200'
100 test_atom
head authorname
'A U Thor'
101 test_atom
head authoremail
'<author@example.com>'
102 test_atom
head authordate
'Tue Jul 4 01:18:44 2006 +0200'
103 test_atom
head committer
'C O Mitter <committer@example.com> 1151968723 +0200'
104 test_atom
head committername
'C O Mitter'
105 test_atom
head committeremail
'<committer@example.com>'
106 test_atom
head committerdate
'Tue Jul 4 01:18:43 2006 +0200'
107 test_atom
head tag
''
108 test_atom
head tagger
''
109 test_atom
head taggername
''
110 test_atom
head taggeremail
''
111 test_atom
head taggerdate
''
112 test_atom
head creator
'C O Mitter <committer@example.com> 1151968723 +0200'
113 test_atom
head creatordate
'Tue Jul 4 01:18:43 2006 +0200'
114 test_atom
head subject
'Initial'
115 test_atom
head contents
:subject
'Initial'
116 test_atom
head body
''
117 test_atom
head contents
:body
''
118 test_atom
head contents
:signature
''
119 test_atom
head contents
'Initial
121 test_atom
head HEAD
'*'
123 test_atom tag refname refs
/tags
/testtag
124 test_atom tag refname
:short testtag
125 test_atom tag upstream
''
126 test_atom tag push
''
127 test_atom tag objecttype tag
128 test_atom tag objectsize
154
129 test_atom tag objectsize
:disk
138
130 test_atom tag
'*objectsize:disk' 138
131 test_atom tag deltabase
0000000000000000000000000000000000000000
132 test_atom tag
'*deltabase' 0000000000000000000000000000000000000000
133 test_atom tag objectname $
(git rev-parse refs
/tags
/testtag
)
134 test_atom tag objectname
:short $
(git rev-parse
--short refs
/tags
/testtag
)
135 test_atom
head objectname
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/master
)
136 test_atom
head objectname
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/master
)
137 test_atom tag tree
''
138 test_atom tag parent
''
139 test_atom tag numparent
''
140 test_atom tag object $
(git rev-parse refs
/tags
/testtag^
0)
141 test_atom tag
type 'commit'
142 test_atom tag
'*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463'
143 test_atom tag
'*objecttype' 'commit'
144 test_atom tag author
''
145 test_atom tag authorname
''
146 test_atom tag authoremail
''
147 test_atom tag authordate
''
148 test_atom tag committer
''
149 test_atom tag committername
''
150 test_atom tag committeremail
''
151 test_atom tag committerdate
''
152 test_atom tag tag
'testtag'
153 test_atom tag tagger
'C O Mitter <committer@example.com> 1151968725 +0200'
154 test_atom tag taggername
'C O Mitter'
155 test_atom tag taggeremail
'<committer@example.com>'
156 test_atom tag taggerdate
'Tue Jul 4 01:18:45 2006 +0200'
157 test_atom tag creator
'C O Mitter <committer@example.com> 1151968725 +0200'
158 test_atom tag creatordate
'Tue Jul 4 01:18:45 2006 +0200'
159 test_atom tag subject
'Tagging at 1151968727'
160 test_atom tag contents
:subject
'Tagging at 1151968727'
161 test_atom tag body
''
162 test_atom tag contents
:body
''
163 test_atom tag contents
:signature
''
164 test_atom tag contents
'Tagging at 1151968727
166 test_atom tag HEAD
' '
168 test_expect_success
'Check invalid atoms names are errors' '
169 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
172 test_expect_success
'Check format specifiers are ignored in naming date atoms' '
173 git for-each-ref --format="%(authordate)" refs/heads &&
174 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
175 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
176 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
179 test_expect_success
'Check valid format specifiers for date fields' '
180 git for-each-ref --format="%(authordate:default)" refs/heads &&
181 git for-each-ref --format="%(authordate:relative)" refs/heads &&
182 git for-each-ref --format="%(authordate:short)" refs/heads &&
183 git for-each-ref --format="%(authordate:local)" refs/heads &&
184 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
185 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
188 test_expect_success
'Check invalid format specifiers are errors' '
189 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
192 test_expect_success
'arguments to %(objectname:short=) must be positive integers' '
193 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
194 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
195 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
203 cat >expected
<<-EOF &&
204 'refs/heads/master' '$committer_date' '$author_date'
205 'refs/tags/testtag' '$tagger_date'
208 git for-each-ref
--shell \
209 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
211 git for-each-ref
--shell \
212 --format="%(refname) %(taggerdate${f:+:$f})" \
215 test_cmp expected actual
218 test_expect_success
'Check unformatted date fields output' '
220 "Tue Jul 4 01:18:43 2006 +0200" \
221 "Tue Jul 4 01:18:44 2006 +0200" \
222 "Tue Jul 4 01:18:45 2006 +0200"
225 test_expect_success
'Check format "default" formatted date fields output' '
227 "Tue Jul 4 01:18:43 2006 +0200" \
228 "Tue Jul 4 01:18:44 2006 +0200" \
229 "Tue Jul 4 01:18:45 2006 +0200"
232 test_expect_success
'Check format "default-local" date fields output' '
233 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"
236 # Don't know how to do relative check because I can't know when this script
237 # is going to be run and can't fake the current time to git, and hence can't
238 # provide expected output. Instead, I'll just make sure that "relative"
239 # doesn't exit in error
240 test_expect_success
'Check format "relative" date fields output' '
242 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
243 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
246 # We just check that this is the same as "relative" for now.
247 test_expect_success
'Check format "relative-local" date fields output' '
248 test_date relative-local \
249 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
250 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
251 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
254 test_expect_success
'Check format "short" date fields output' '
255 test_date short 2006-07-04 2006-07-04 2006-07-04
258 test_expect_success
'Check format "short-local" date fields output' '
259 test_date short-local 2006-07-03 2006-07-03 2006-07-03
262 test_expect_success
'Check format "local" date fields output' '
264 "Mon Jul 3 23:18:43 2006" \
265 "Mon Jul 3 23:18:44 2006" \
266 "Mon Jul 3 23:18:45 2006"
269 test_expect_success
'Check format "iso8601" date fields output' '
271 "2006-07-04 01:18:43 +0200" \
272 "2006-07-04 01:18:44 +0200" \
273 "2006-07-04 01:18:45 +0200"
276 test_expect_success
'Check format "iso8601-local" date fields output' '
277 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"
280 test_expect_success
'Check format "rfc2822" date fields output' '
282 "Tue, 4 Jul 2006 01:18:43 +0200" \
283 "Tue, 4 Jul 2006 01:18:44 +0200" \
284 "Tue, 4 Jul 2006 01:18:45 +0200"
287 test_expect_success
'Check format "rfc2822-local" date fields output' '
288 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"
291 test_expect_success
'Check format "raw" date fields output' '
292 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
295 test_expect_success
'Check format "raw-local" date fields output' '
296 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
299 test_expect_success
'Check format of strftime date fields' '
300 echo "my date is 2006-07-04" >expected &&
302 --format="%(authordate:format:my date is %Y-%m-%d)" \
303 refs/heads >actual &&
304 test_cmp expected actual
307 test_expect_success
'Check format of strftime-local date fields' '
308 echo "my date is 2006-07-03" >expected &&
310 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
311 refs/heads >actual &&
312 test_cmp expected actual
315 test_expect_success
'exercise strftime with odd fields' '
317 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
318 test_cmp expected actual &&
319 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
320 echo $long >expected &&
321 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
322 test_cmp expected actual
327 refs
/remotes
/origin
/master
331 test_expect_success
'Verify ascending sort' '
332 git for-each-ref --format="%(refname)" --sort=refname >actual &&
333 test_cmp expected actual
339 refs
/remotes
/origin
/master
343 test_expect_success
'Verify descending sort' '
344 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
345 test_cmp expected actual
353 test_expect_success
'exercise patterns with prefixes' '
355 test_when_finished "git tag -d testtag-2" &&
356 git for-each-ref --format="%(refname)" \
357 refs/tags/testtag refs/tags/testtag-2 >actual &&
358 test_cmp expected actual
366 test_expect_success
'exercise glob patterns with prefixes' '
368 test_when_finished "git tag -d testtag-2" &&
369 git for-each-ref --format="%(refname)" \
370 refs/tags/testtag "refs/tags/testtag-*" >actual &&
371 test_cmp expected actual
376 'refs/remotes/origin/master'
380 test_expect_success
'Quoting style: shell' '
381 git for-each-ref --shell --format="%(refname)" >actual &&
382 test_cmp expected actual
385 test_expect_success
'Quoting style: perl' '
386 git for-each-ref --perl --format="%(refname)" >actual &&
387 test_cmp expected actual
390 test_expect_success
'Quoting style: python' '
391 git for-each-ref --python --format="%(refname)" >actual &&
392 test_cmp expected actual
397 "refs/remotes/origin/master"
401 test_expect_success
'Quoting style: tcl' '
402 git for-each-ref --tcl --format="%(refname)" >actual &&
403 test_cmp expected actual
406 for i
in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
407 test_expect_success
"more than one quoting style: $i" "
408 test_must_fail git for-each-ref $i 2>err &&
409 grep '^error: more than one quoting style' err
413 test_expect_success
'setup for upstream:track[short]' '
417 test_atom
head upstream
:track
'[ahead 1]'
418 test_atom
head upstream
:trackshort
'>'
419 test_atom
head upstream
:track
,nobracket
'ahead 1'
420 test_atom
head upstream
:nobracket
,track
'ahead 1'
422 test_expect_success
'setup for push:track[short]' '
424 git update-ref refs/remotes/myfork/master master &&
428 test_atom
head push
:track
'[behind 1]'
429 test_atom
head push
:trackshort
'<'
431 test_expect_success
'Check that :track[short] cannot be used with other atoms' '
432 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
433 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
436 test_expect_success
'Check that :track[short] works when upstream is invalid' '
437 cat >expected <<-\EOF &&
441 test_when_finished "git config branch.master.merge refs/heads/master" &&
442 git config branch.master.merge refs/heads/does-not-exist &&
444 --format="%(upstream:track)$LF%(upstream:trackshort)" \
445 refs/heads >actual &&
446 test_cmp expected actual
449 test_expect_success
'Check for invalid refname format' '
450 test_must_fail git for-each-ref --format="%(refname:INVALID)"
453 test_expect_success
'set up color tests' '
454 cat >expected.color <<-EOF &&
455 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
456 $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
457 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
458 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
459 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
460 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
462 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
463 color_format="%(objectname:short) %(color:green)%(refname:short)"
466 test_expect_success TTY
'%(color) shows color with a tty' '
467 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
468 test_decode_color <actual.raw >actual &&
469 test_cmp expected.color actual
472 test_expect_success
'%(color) does not show color without tty' '
473 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
474 test_cmp expected.bare actual
477 test_expect_success
'--color can override tty check' '
478 git for-each-ref --color --format="$color_format" >actual.raw &&
479 test_decode_color <actual.raw >actual &&
480 test_cmp expected.color actual
483 test_expect_success
'color.ui=always does not override tty check' '
484 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
485 test_cmp expected.bare actual
493 test_expect_success
'Check ambiguous head and tag refs (strict)' '
494 git config --bool core.warnambiguousrefs true &&
495 git checkout -b newtag &&
496 echo "Using $datestamp" > one &&
498 git commit -m "Branch" &&
499 setdate_and_increment &&
500 git tag -m "Tagging at $datestamp" master &&
501 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
502 test_cmp expected actual
510 test_expect_success
'Check ambiguous head and tag refs (loose)' '
511 git config --bool core.warnambiguousrefs false &&
512 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
513 test_cmp expected actual
521 test_expect_success
'Check ambiguous head and tag refs II (loose)' '
522 git checkout master &&
523 git tag ambiguous testtag^0 &&
524 git branch ambiguous testtag^0 &&
525 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
526 test_cmp expected actual
529 test_expect_success
'an unusual tag with an incomplete line' '
531 git tag -m "bogo" bogo &&
532 bogo=$(git cat-file tag bogo) &&
533 bogo=$(printf "%s" "$bogo" | git mktag) &&
534 git tag -f bogo "$bogo" &&
535 git for-each-ref --format "%(body)" refs/tags/bogo
539 test_expect_success
'create tag with subject and body content' '
546 git tag -F msg subject-body
548 test_atom refs
/tags
/subject-body subject
'the subject line'
549 test_atom refs
/tags
/subject-body body
'first body line
552 test_atom refs
/tags
/subject-body contents
'the subject line
558 test_expect_success
'create tag with multiline subject' '
566 git tag -F msg multiline
568 test_atom refs
/tags
/multiline subject
'first subject line second subject line'
569 test_atom refs
/tags
/multiline contents
:subject
'first subject line second subject line'
570 test_atom refs
/tags
/multiline body
'first body line
573 test_atom refs
/tags
/multiline contents
:body
'first body line
576 test_atom refs
/tags
/multiline contents
:signature
''
577 test_atom refs
/tags
/multiline contents
'first subject line
584 test_expect_success GPG
'create signed tags' '
585 git tag -s -m "" signed-empty &&
586 git tag -s -m "subject line" signed-short &&
592 git tag -s -F msg signed-long
595 sig
='-----BEGIN PGP SIGNATURE-----
596 -----END PGP SIGNATURE-----
600 test_atom refs
/tags
/signed-empty subject
''
601 test_atom refs
/tags
/signed-empty contents
:subject
''
602 test_atom refs
/tags
/signed-empty body
"$sig"
603 test_atom refs
/tags
/signed-empty contents
:body
''
604 test_atom refs
/tags
/signed-empty contents
:signature
"$sig"
605 test_atom refs
/tags
/signed-empty contents
"$sig"
607 test_atom refs
/tags
/signed-short subject
'subject line'
608 test_atom refs
/tags
/signed-short contents
:subject
'subject line'
609 test_atom refs
/tags
/signed-short body
"$sig"
610 test_atom refs
/tags
/signed-short contents
:body
''
611 test_atom refs
/tags
/signed-short contents
:signature
"$sig"
612 test_atom refs
/tags
/signed-short contents
"subject line
615 test_atom refs
/tags
/signed-long subject
'subject line'
616 test_atom refs
/tags
/signed-long contents
:subject
'subject line'
617 test_atom refs
/tags
/signed-long body
"body contents
619 test_atom refs
/tags
/signed-long contents
:body
'body contents
621 test_atom refs
/tags
/signed-long contents
:signature
"$sig"
622 test_atom refs
/tags
/signed-long contents
"subject line
628 $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
629 $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
632 test_expect_success
'Verify sort with multiple keys' '
633 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
634 refs/tags/bogo refs/tags/master > actual &&
635 test_cmp expected actual
639 test_expect_success
'do not dereference NULL upon %(HEAD) on unborn branch' '
640 test_when_finished "git checkout master" &&
641 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
642 sed -e "s/^\* / /" actual >expect &&
643 git checkout --orphan orphaned-branch &&
644 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
645 test_cmp expect actual
649 Reviewed-by: A U Thor <author@example.com>
650 Signed-off-by: A U Thor <author@example.com>
651 [ v2 updated patch description ]
657 perl
-0pe 's/\n\s+/ /g'
660 test_expect_success
'set up trailers for next test' '
661 echo "Some contents" > two &&
663 git commit -F - <<-EOF
664 trailers: this commit message has trailers
666 Some message contents
672 test_expect_success
'%(trailers:unfold) unfolds trailers' '
673 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
678 test_cmp expect actual
681 test_expect_success
'%(trailers:only) shows only "key: value" trailers' '
682 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
684 grep -v patch.description <trailers &&
687 test_cmp expect actual
690 test_expect_success
'%(trailers:only) and %(trailers:unfold) work together' '
691 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
692 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
693 test_cmp actual reverse &&
695 grep -v patch.description <trailers | unfold &&
698 test_cmp expect actual
701 test_expect_success
'%(contents:trailers:unfold) unfolds trailers' '
702 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
707 test_cmp expect actual
710 test_expect_success
'%(contents:trailers:only) shows only "key: value" trailers' '
711 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
713 grep -v patch.description <trailers &&
716 test_cmp expect actual
719 test_expect_success
'%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
720 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
721 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
722 test_cmp actual reverse &&
724 grep -v patch.description <trailers | unfold &&
727 test_cmp expect actual
730 test_expect_success
'%(trailers) rejects unknown trailers arguments' '
731 # error message cannot be checked under i18n
732 cat >expect <<-EOF &&
733 fatal: unknown %(trailers) argument: unsupported
735 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
736 test_i18ncmp expect actual
739 test_expect_success
'%(contents:trailers) rejects unknown trailers arguments' '
740 # error message cannot be checked under i18n
741 cat >expect <<-EOF &&
742 fatal: unknown %(trailers) argument: unsupported
744 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
745 test_i18ncmp expect actual
748 test_expect_success
'basic atom: head contents:trailers' '
749 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
750 sanitize_pgp <actual >actual.clean &&
751 # git for-each-ref ends with a blank line
752 cat >expect <<-EOF &&
756 test_cmp expect actual.clean
759 test_expect_success
'trailer parsing not fooled by --- line' '
760 git commit --allow-empty -F - <<-\EOF &&
763 This is the body. The message has a "---" line which would confuse a
764 message+patch parser. But here we know we have only a commit message,
775 echo "trailer: right" &&
778 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
779 test_cmp expect actual
782 test_expect_success
'Add symbolic ref for the following tests' '
783 git symbolic-ref refs/heads/sym refs/heads/master
790 test_expect_success
'Verify usage of %(symref) atom' '
791 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
792 test_cmp expected actual
799 test_expect_success
'Verify usage of %(symref:short) atom' '
800 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
801 test_cmp expected actual
809 test_expect_success
'Verify usage of %(symref:lstrip) atom' '
810 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
811 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
812 test_cmp expected actual &&
814 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
815 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
816 test_cmp expected actual
824 test_expect_success
'Verify usage of %(symref:rstrip) atom' '
825 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
826 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
827 test_cmp expected actual
830 test_expect_success
':remotename and :remoteref' '
831 git init remote-tests &&
834 test_commit initial &&
835 git remote add from fifth.coffee:blub &&
836 git config branch.master.remote from &&
837 git config branch.master.merge refs/heads/stable &&
838 git remote add to southridge.audio:repo &&
839 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
840 git config branch.master.pushRemote to &&
841 for pair in "%(upstream)=refs/remotes/from/stable" \
842 "%(upstream:remotename)=from" \
843 "%(upstream:remoteref)=refs/heads/stable" \
844 "%(push)=refs/remotes/to/pushed/master" \
845 "%(push:remotename)=to" \
846 "%(push:remoteref)=refs/heads/pushed/master"
848 echo "${pair#*=}" >expect &&
849 git for-each-ref --format="${pair%=*}" \
850 refs/heads/master >actual &&
851 test_cmp expect actual
853 git branch push-simple &&
854 git config branch.push-simple.pushRemote from &&
855 actual="$(git for-each-ref \
856 --format="%(push:remotename),%(push:remoteref)" \
857 refs/heads/push-simple)" &&
858 test from, = "$actual"
862 test_expect_success
'for-each-ref --ignore-case ignores case' '
863 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
864 test_must_be_empty actual &&
866 echo refs/heads/master >expect &&
867 git for-each-ref --format="%(refname)" --ignore-case \
868 refs/heads/MASTER >actual &&
869 test_cmp expect actual