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 test_oid_cache <<-EOF &&
27 setdate_and_increment &&
28 echo "Using $datestamp" > one &&
30 git commit -m "Initial" &&
31 setdate_and_increment &&
32 git tag -a -m "Tagging at $datestamp" testtag &&
33 git update-ref refs/remotes/origin/master master &&
34 git remote add origin nowhere &&
35 git config branch.master.remote origin &&
36 git config branch.master.merge refs/heads/master &&
37 git remote add myfork elsewhere &&
38 git config remote.pushdefault myfork &&
39 git config push.default current
44 head) ref
=refs
/heads
/master
;;
45 tag
) ref
=refs
/tags
/testtag
;;
46 sym
) ref
=refs
/heads
/sym
;;
49 printf '%s\n' "$3" >expected
50 test_expect_
${4:-success} $PREREQ "basic atom: $1 $2" "
51 git for-each-ref --format='%($2)' $ref >actual &&
52 sanitize_pgp <actual >actual.clean &&
53 test_cmp expected actual.clean
57 hexlen
=$
(test_oid hexsz
)
58 disklen
=$
(test_oid disklen
)
60 test_atom
head refname refs
/heads
/master
61 test_atom
head refname
: refs
/heads
/master
62 test_atom
head refname
:short master
63 test_atom
head refname
:lstrip
=1 heads
/master
64 test_atom
head refname
:lstrip
=2 master
65 test_atom
head refname
:lstrip
=-1 master
66 test_atom
head refname
:lstrip
=-2 heads
/master
67 test_atom
head refname
:rstrip
=1 refs
/heads
68 test_atom
head refname
:rstrip
=2 refs
69 test_atom
head refname
:rstrip
=-1 refs
70 test_atom
head refname
:rstrip
=-2 refs
/heads
71 test_atom
head refname
:strip
=1 heads
/master
72 test_atom
head refname
:strip
=2 master
73 test_atom
head refname
:strip
=-1 master
74 test_atom
head refname
:strip
=-2 heads
/master
75 test_atom
head upstream refs
/remotes
/origin
/master
76 test_atom
head upstream
:short origin
/master
77 test_atom
head upstream
:lstrip
=2 origin
/master
78 test_atom
head upstream
:lstrip
=-2 origin
/master
79 test_atom
head upstream
:rstrip
=2 refs
/remotes
80 test_atom
head upstream
:rstrip
=-2 refs
/remotes
81 test_atom
head upstream
:strip
=2 origin
/master
82 test_atom
head upstream
:strip
=-2 origin
/master
83 test_atom
head push refs
/remotes
/myfork
/master
84 test_atom
head push
:short myfork
/master
85 test_atom
head push
:lstrip
=1 remotes
/myfork
/master
86 test_atom
head push
:lstrip
=-1 master
87 test_atom
head push
:rstrip
=1 refs
/remotes
/myfork
88 test_atom
head push
:rstrip
=-1 refs
89 test_atom
head push
:strip
=1 remotes
/myfork
/master
90 test_atom
head push
:strip
=-1 master
91 test_atom
head objecttype commit
92 test_atom
head objectsize $
((131 + hexlen
))
93 test_atom
head objectsize
:disk
$disklen
94 test_atom
head deltabase
$ZERO_OID
95 test_atom
head objectname $
(git rev-parse refs
/heads
/master
)
96 test_atom
head objectname
:short $
(git rev-parse
--short refs
/heads
/master
)
97 test_atom
head objectname
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/master
)
98 test_atom
head objectname
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/master
)
99 test_atom
head tree $
(git rev-parse refs
/heads
/master^
{tree
})
100 test_atom
head parent
''
101 test_atom
head numparent
0
102 test_atom
head object
''
103 test_atom
head type ''
104 test_atom
head '*objectname' ''
105 test_atom
head '*objecttype' ''
106 test_atom
head author
'A U Thor <author@example.com> 1151968724 +0200'
107 test_atom
head authorname
'A U Thor'
108 test_atom
head authoremail
'<author@example.com>'
109 test_atom
head authordate
'Tue Jul 4 01:18:44 2006 +0200'
110 test_atom
head committer
'C O Mitter <committer@example.com> 1151968723 +0200'
111 test_atom
head committername
'C O Mitter'
112 test_atom
head committeremail
'<committer@example.com>'
113 test_atom
head committerdate
'Tue Jul 4 01:18:43 2006 +0200'
114 test_atom
head tag
''
115 test_atom
head tagger
''
116 test_atom
head taggername
''
117 test_atom
head taggeremail
''
118 test_atom
head taggerdate
''
119 test_atom
head creator
'C O Mitter <committer@example.com> 1151968723 +0200'
120 test_atom
head creatordate
'Tue Jul 4 01:18:43 2006 +0200'
121 test_atom
head subject
'Initial'
122 test_atom
head contents
:subject
'Initial'
123 test_atom
head body
''
124 test_atom
head contents
:body
''
125 test_atom
head contents
:signature
''
126 test_atom
head contents
'Initial
128 test_atom
head HEAD
'*'
130 test_atom tag refname refs
/tags
/testtag
131 test_atom tag refname
:short testtag
132 test_atom tag upstream
''
133 test_atom tag push
''
134 test_atom tag objecttype tag
135 test_atom tag objectsize $
((114 + hexlen
))
136 test_atom tag objectsize
:disk
$disklen
137 test_atom tag
'*objectsize:disk' $disklen
138 test_atom tag deltabase
$ZERO_OID
139 test_atom tag
'*deltabase' $ZERO_OID
140 test_atom tag objectname $
(git rev-parse refs
/tags
/testtag
)
141 test_atom tag objectname
:short $
(git rev-parse
--short refs
/tags
/testtag
)
142 test_atom
head objectname
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/master
)
143 test_atom
head objectname
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/master
)
144 test_atom tag tree
''
145 test_atom tag parent
''
146 test_atom tag numparent
''
147 test_atom tag object $
(git rev-parse refs
/tags
/testtag^
0)
148 test_atom tag
type 'commit'
149 test_atom tag
'*objectname' $
(git rev-parse refs
/tags
/testtag^
{})
150 test_atom tag
'*objecttype' 'commit'
151 test_atom tag author
''
152 test_atom tag authorname
''
153 test_atom tag authoremail
''
154 test_atom tag authordate
''
155 test_atom tag committer
''
156 test_atom tag committername
''
157 test_atom tag committeremail
''
158 test_atom tag committerdate
''
159 test_atom tag tag
'testtag'
160 test_atom tag tagger
'C O Mitter <committer@example.com> 1151968725 +0200'
161 test_atom tag taggername
'C O Mitter'
162 test_atom tag taggeremail
'<committer@example.com>'
163 test_atom tag taggerdate
'Tue Jul 4 01:18:45 2006 +0200'
164 test_atom tag creator
'C O Mitter <committer@example.com> 1151968725 +0200'
165 test_atom tag creatordate
'Tue Jul 4 01:18:45 2006 +0200'
166 test_atom tag subject
'Tagging at 1151968727'
167 test_atom tag contents
:subject
'Tagging at 1151968727'
168 test_atom tag body
''
169 test_atom tag contents
:body
''
170 test_atom tag contents
:signature
''
171 test_atom tag contents
'Tagging at 1151968727
173 test_atom tag HEAD
' '
175 test_expect_success
'Check invalid atoms names are errors' '
176 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
179 test_expect_success
'Check format specifiers are ignored in naming date atoms' '
180 git for-each-ref --format="%(authordate)" refs/heads &&
181 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
182 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
183 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
186 test_expect_success
'Check valid format specifiers for date fields' '
187 git for-each-ref --format="%(authordate:default)" refs/heads &&
188 git for-each-ref --format="%(authordate:relative)" refs/heads &&
189 git for-each-ref --format="%(authordate:short)" refs/heads &&
190 git for-each-ref --format="%(authordate:local)" refs/heads &&
191 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
192 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
195 test_expect_success
'Check invalid format specifiers are errors' '
196 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
199 test_expect_success
'arguments to %(objectname:short=) must be positive integers' '
200 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
201 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
202 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
210 cat >expected
<<-EOF &&
211 'refs/heads/master' '$committer_date' '$author_date'
212 'refs/tags/testtag' '$tagger_date'
215 git for-each-ref
--shell \
216 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
218 git for-each-ref
--shell \
219 --format="%(refname) %(taggerdate${f:+:$f})" \
222 test_cmp expected actual
225 test_expect_success
'Check unformatted 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" formatted date fields output' '
234 "Tue Jul 4 01:18:43 2006 +0200" \
235 "Tue Jul 4 01:18:44 2006 +0200" \
236 "Tue Jul 4 01:18:45 2006 +0200"
239 test_expect_success
'Check format "default-local" date fields output' '
240 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"
243 # Don't know how to do relative check because I can't know when this script
244 # is going to be run and can't fake the current time to git, and hence can't
245 # provide expected output. Instead, I'll just make sure that "relative"
246 # doesn't exit in error
247 test_expect_success
'Check format "relative" date fields output' '
249 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
250 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
253 # We just check that this is the same as "relative" for now.
254 test_expect_success
'Check format "relative-local" date fields output' '
255 test_date relative-local \
256 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
257 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
258 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
261 test_expect_success
'Check format "short" date fields output' '
262 test_date short 2006-07-04 2006-07-04 2006-07-04
265 test_expect_success
'Check format "short-local" date fields output' '
266 test_date short-local 2006-07-03 2006-07-03 2006-07-03
269 test_expect_success
'Check format "local" date fields output' '
271 "Mon Jul 3 23:18:43 2006" \
272 "Mon Jul 3 23:18:44 2006" \
273 "Mon Jul 3 23:18:45 2006"
276 test_expect_success
'Check format "iso8601" date fields output' '
278 "2006-07-04 01:18:43 +0200" \
279 "2006-07-04 01:18:44 +0200" \
280 "2006-07-04 01:18:45 +0200"
283 test_expect_success
'Check format "iso8601-local" date fields output' '
284 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"
287 test_expect_success
'Check format "rfc2822" date fields output' '
289 "Tue, 4 Jul 2006 01:18:43 +0200" \
290 "Tue, 4 Jul 2006 01:18:44 +0200" \
291 "Tue, 4 Jul 2006 01:18:45 +0200"
294 test_expect_success
'Check format "rfc2822-local" date fields output' '
295 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"
298 test_expect_success
'Check format "raw" date fields output' '
299 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
302 test_expect_success
'Check format "raw-local" date fields output' '
303 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
306 test_expect_success
'Check format of strftime date fields' '
307 echo "my date is 2006-07-04" >expected &&
309 --format="%(authordate:format:my date is %Y-%m-%d)" \
310 refs/heads >actual &&
311 test_cmp expected actual
314 test_expect_success
'Check format of strftime-local date fields' '
315 echo "my date is 2006-07-03" >expected &&
317 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
318 refs/heads >actual &&
319 test_cmp expected actual
322 test_expect_success
'exercise strftime with odd fields' '
324 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
325 test_cmp expected actual &&
326 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
327 echo $long >expected &&
328 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
329 test_cmp expected actual
334 refs
/remotes
/origin
/master
338 test_expect_success
'Verify ascending sort' '
339 git for-each-ref --format="%(refname)" --sort=refname >actual &&
340 test_cmp expected actual
346 refs
/remotes
/origin
/master
350 test_expect_success
'Verify descending sort' '
351 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
352 test_cmp expected actual
360 test_expect_success
'exercise patterns with prefixes' '
362 test_when_finished "git tag -d testtag-2" &&
363 git for-each-ref --format="%(refname)" \
364 refs/tags/testtag refs/tags/testtag-2 >actual &&
365 test_cmp expected actual
373 test_expect_success
'exercise glob patterns with prefixes' '
375 test_when_finished "git tag -d testtag-2" &&
376 git for-each-ref --format="%(refname)" \
377 refs/tags/testtag "refs/tags/testtag-*" >actual &&
378 test_cmp expected actual
383 'refs/remotes/origin/master'
387 test_expect_success
'Quoting style: shell' '
388 git for-each-ref --shell --format="%(refname)" >actual &&
389 test_cmp expected actual
392 test_expect_success
'Quoting style: perl' '
393 git for-each-ref --perl --format="%(refname)" >actual &&
394 test_cmp expected actual
397 test_expect_success
'Quoting style: python' '
398 git for-each-ref --python --format="%(refname)" >actual &&
399 test_cmp expected actual
404 "refs/remotes/origin/master"
408 test_expect_success
'Quoting style: tcl' '
409 git for-each-ref --tcl --format="%(refname)" >actual &&
410 test_cmp expected actual
413 for i
in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
414 test_expect_success
"more than one quoting style: $i" "
415 test_must_fail git for-each-ref $i 2>err &&
416 grep '^error: more than one quoting style' err
420 test_expect_success
'setup for upstream:track[short]' '
424 test_atom
head upstream
:track
'[ahead 1]'
425 test_atom
head upstream
:trackshort
'>'
426 test_atom
head upstream
:track
,nobracket
'ahead 1'
427 test_atom
head upstream
:nobracket
,track
'ahead 1'
429 test_expect_success
'setup for push:track[short]' '
431 git update-ref refs/remotes/myfork/master master &&
435 test_atom
head push
:track
'[behind 1]'
436 test_atom
head push
:trackshort
'<'
438 test_expect_success
'Check that :track[short] cannot be used with other atoms' '
439 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
440 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
443 test_expect_success
'Check that :track[short] works when upstream is invalid' '
444 cat >expected <<-\EOF &&
448 test_when_finished "git config branch.master.merge refs/heads/master" &&
449 git config branch.master.merge refs/heads/does-not-exist &&
451 --format="%(upstream:track)$LF%(upstream:trackshort)" \
452 refs/heads >actual &&
453 test_cmp expected actual
456 test_expect_success
'Check for invalid refname format' '
457 test_must_fail git for-each-ref --format="%(refname:INVALID)"
460 test_expect_success
'set up color tests' '
461 cat >expected.color <<-EOF &&
462 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
463 $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
464 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
465 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
466 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
467 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
469 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
470 color_format="%(objectname:short) %(color:green)%(refname:short)"
473 test_expect_success TTY
'%(color) shows color with a tty' '
474 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
475 test_decode_color <actual.raw >actual &&
476 test_cmp expected.color actual
479 test_expect_success
'%(color) does not show color without tty' '
480 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
481 test_cmp expected.bare actual
484 test_expect_success
'--color can override tty check' '
485 git for-each-ref --color --format="$color_format" >actual.raw &&
486 test_decode_color <actual.raw >actual &&
487 test_cmp expected.color actual
490 test_expect_success
'color.ui=always does not override tty check' '
491 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
492 test_cmp expected.bare actual
500 test_expect_success
'Check ambiguous head and tag refs (strict)' '
501 git config --bool core.warnambiguousrefs true &&
502 git checkout -b newtag &&
503 echo "Using $datestamp" > one &&
505 git commit -m "Branch" &&
506 setdate_and_increment &&
507 git tag -m "Tagging at $datestamp" master &&
508 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
509 test_cmp expected actual
517 test_expect_success
'Check ambiguous head and tag refs (loose)' '
518 git config --bool core.warnambiguousrefs false &&
519 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
520 test_cmp expected actual
528 test_expect_success
'Check ambiguous head and tag refs II (loose)' '
529 git checkout master &&
530 git tag ambiguous testtag^0 &&
531 git branch ambiguous testtag^0 &&
532 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
533 test_cmp expected actual
536 test_expect_success
'create tag without tagger' '
537 git tag -a -m "Broken tag" taggerless &&
538 git tag -f taggerless $(git cat-file tag taggerless |
539 sed -e "/^tagger /d" |
540 git hash-object --stdin -w -t tag)
543 test_atom refs
/tags
/taggerless
type 'commit'
544 test_atom refs
/tags
/taggerless tag
'taggerless'
545 test_atom refs
/tags
/taggerless tagger
''
546 test_atom refs
/tags
/taggerless taggername
''
547 test_atom refs
/tags
/taggerless taggeremail
''
548 test_atom refs
/tags
/taggerless taggerdate
''
549 test_atom refs
/tags
/taggerless committer
''
550 test_atom refs
/tags
/taggerless committername
''
551 test_atom refs
/tags
/taggerless committeremail
''
552 test_atom refs
/tags
/taggerless committerdate
''
553 test_atom refs
/tags
/taggerless subject
'Broken tag'
555 test_expect_success
'an unusual tag with an incomplete line' '
557 git tag -m "bogo" bogo &&
558 bogo=$(git cat-file tag bogo) &&
559 bogo=$(printf "%s" "$bogo" | git mktag) &&
560 git tag -f bogo "$bogo" &&
561 git for-each-ref --format "%(body)" refs/tags/bogo
565 test_expect_success
'create tag with subject and body content' '
572 git tag -F msg subject-body
574 test_atom refs
/tags
/subject-body subject
'the subject line'
575 test_atom refs
/tags
/subject-body body
'first body line
578 test_atom refs
/tags
/subject-body contents
'the subject line
584 test_expect_success
'create tag with multiline subject' '
592 git tag -F msg multiline
594 test_atom refs
/tags
/multiline subject
'first subject line second subject line'
595 test_atom refs
/tags
/multiline contents
:subject
'first subject line second subject line'
596 test_atom refs
/tags
/multiline body
'first body line
599 test_atom refs
/tags
/multiline contents
:body
'first body line
602 test_atom refs
/tags
/multiline contents
:signature
''
603 test_atom refs
/tags
/multiline contents
'first subject line
610 test_expect_success GPG
'create signed tags' '
611 git tag -s -m "" signed-empty &&
612 git tag -s -m "subject line" signed-short &&
618 git tag -s -F msg signed-long
621 sig
='-----BEGIN PGP SIGNATURE-----
622 -----END PGP SIGNATURE-----
626 test_atom refs
/tags
/signed-empty subject
''
627 test_atom refs
/tags
/signed-empty contents
:subject
''
628 test_atom refs
/tags
/signed-empty body
"$sig"
629 test_atom refs
/tags
/signed-empty contents
:body
''
630 test_atom refs
/tags
/signed-empty contents
:signature
"$sig"
631 test_atom refs
/tags
/signed-empty contents
"$sig"
633 test_atom refs
/tags
/signed-short subject
'subject line'
634 test_atom refs
/tags
/signed-short contents
:subject
'subject line'
635 test_atom refs
/tags
/signed-short body
"$sig"
636 test_atom refs
/tags
/signed-short contents
:body
''
637 test_atom refs
/tags
/signed-short contents
:signature
"$sig"
638 test_atom refs
/tags
/signed-short contents
"subject line
641 test_atom refs
/tags
/signed-long subject
'subject line'
642 test_atom refs
/tags
/signed-long contents
:subject
'subject line'
643 test_atom refs
/tags
/signed-long body
"body contents
645 test_atom refs
/tags
/signed-long contents
:body
'body contents
647 test_atom refs
/tags
/signed-long contents
:signature
"$sig"
648 test_atom refs
/tags
/signed-long contents
"subject line
653 test_expect_success
'set up multiple-sort tags' '
654 for when in 100000 200000
656 for email in user1 user2
660 GIT_COMMITTER_DATE="@$when +0000" \
661 GIT_COMMITTER_EMAIL="$email@example.com" \
662 git tag -m "tag $ref-$when-$email" \
663 multi-$ref-$when-$email || return 1
669 test_expect_success
'Verify sort with multiple keys' '
670 cat >expected <<-\EOF &&
671 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
672 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
673 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
674 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
675 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
676 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
677 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
678 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
681 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
685 "refs/tags/multi-*" >actual &&
686 test_cmp expected actual
689 test_expect_success
'equivalent sorts fall back on refname' '
690 cat >expected <<-\EOF &&
691 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
692 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
693 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
694 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
695 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
696 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
697 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
698 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
701 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
703 "refs/tags/multi-*" >actual &&
704 test_cmp expected actual
707 test_expect_success
'do not dereference NULL upon %(HEAD) on unborn branch' '
708 test_when_finished "git checkout master" &&
709 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
710 sed -e "s/^\* / /" actual >expect &&
711 git checkout --orphan orphaned-branch &&
712 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
713 test_cmp expect actual
717 Reviewed-by: A U Thor <author@example.com>
718 Signed-off-by: A U Thor <author@example.com>
719 [ v2 updated patch description ]
725 perl
-0pe 's/\n\s+/ /g'
728 test_expect_success
'set up trailers for next test' '
729 echo "Some contents" > two &&
731 git commit -F - <<-EOF
732 trailers: this commit message has trailers
734 Some message contents
740 test_expect_success
'%(trailers:unfold) unfolds trailers' '
741 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
746 test_cmp expect actual
749 test_expect_success
'%(trailers:only) shows only "key: value" trailers' '
750 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
752 grep -v patch.description <trailers &&
755 test_cmp expect actual
758 test_expect_success
'%(trailers:only) and %(trailers:unfold) work together' '
759 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
760 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
761 test_cmp actual reverse &&
763 grep -v patch.description <trailers | unfold &&
766 test_cmp expect actual
769 test_expect_success
'%(contents:trailers:unfold) unfolds trailers' '
770 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
775 test_cmp expect actual
778 test_expect_success
'%(contents:trailers:only) shows only "key: value" trailers' '
779 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
781 grep -v patch.description <trailers &&
784 test_cmp expect actual
787 test_expect_success
'%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
788 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
789 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
790 test_cmp actual reverse &&
792 grep -v patch.description <trailers | unfold &&
795 test_cmp expect actual
798 test_expect_success
'%(trailers) rejects unknown trailers arguments' '
799 # error message cannot be checked under i18n
800 cat >expect <<-EOF &&
801 fatal: unknown %(trailers) argument: unsupported
803 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
804 test_i18ncmp expect actual
807 test_expect_success
'%(contents:trailers) rejects unknown trailers arguments' '
808 # error message cannot be checked under i18n
809 cat >expect <<-EOF &&
810 fatal: unknown %(trailers) argument: unsupported
812 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
813 test_i18ncmp expect actual
816 test_expect_success
'basic atom: head contents:trailers' '
817 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
818 sanitize_pgp <actual >actual.clean &&
819 # git for-each-ref ends with a blank line
820 cat >expect <<-EOF &&
824 test_cmp expect actual.clean
827 test_expect_success
'trailer parsing not fooled by --- line' '
828 git commit --allow-empty -F - <<-\EOF &&
831 This is the body. The message has a "---" line which would confuse a
832 message+patch parser. But here we know we have only a commit message,
843 echo "trailer: right" &&
846 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
847 test_cmp expect actual
850 test_expect_success
'Add symbolic ref for the following tests' '
851 git symbolic-ref refs/heads/sym refs/heads/master
858 test_expect_success
'Verify usage of %(symref) atom' '
859 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
860 test_cmp expected actual
867 test_expect_success
'Verify usage of %(symref:short) atom' '
868 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
869 test_cmp expected actual
877 test_expect_success
'Verify usage of %(symref:lstrip) atom' '
878 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
879 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
880 test_cmp expected actual &&
882 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
883 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
884 test_cmp expected actual
892 test_expect_success
'Verify usage of %(symref:rstrip) atom' '
893 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
894 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
895 test_cmp expected actual
898 test_expect_success
':remotename and :remoteref' '
899 git init remote-tests &&
902 test_commit initial &&
903 git remote add from fifth.coffee:blub &&
904 git config branch.master.remote from &&
905 git config branch.master.merge refs/heads/stable &&
906 git remote add to southridge.audio:repo &&
907 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
908 git config branch.master.pushRemote to &&
909 for pair in "%(upstream)=refs/remotes/from/stable" \
910 "%(upstream:remotename)=from" \
911 "%(upstream:remoteref)=refs/heads/stable" \
912 "%(push)=refs/remotes/to/pushed/master" \
913 "%(push:remotename)=to" \
914 "%(push:remoteref)=refs/heads/pushed/master"
916 echo "${pair#*=}" >expect &&
917 git for-each-ref --format="${pair%=*}" \
918 refs/heads/master >actual &&
919 test_cmp expect actual
921 git branch push-simple &&
922 git config branch.push-simple.pushRemote from &&
923 actual="$(git for-each-ref \
924 --format="%(push:remotename),%(push:remoteref)" \
925 refs/heads/push-simple)" &&
926 test from, = "$actual"
930 test_expect_success
'for-each-ref --ignore-case ignores case' '
931 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
932 test_must_be_empty actual &&
934 echo refs/heads/master >expect &&
935 git for-each-ref --format="%(refname)" --ignore-case \
936 refs/heads/MASTER >actual &&
937 test_cmp expect actual
940 test_expect_success
'for-each-ref --ignore-case works on multiple sort keys' '
941 # name refs numerically to avoid case-insensitive filesystem conflicts
945 for subject in a A b B
947 GIT_COMMITTER_EMAIL="$email@example.com" \
948 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
953 git for-each-ref --ignore-case \
954 --format="%(taggeremail) %(subject) %(refname)" \
958 refs/tags/icase-* >actual &&
959 cat >expect <<-\EOF &&
960 <a@example.com> tag a refs/tags/icase-00
961 <a@example.com> tag A refs/tags/icase-01
962 <A@example.com> tag a refs/tags/icase-04
963 <A@example.com> tag A refs/tags/icase-05
964 <a@example.com> tag b refs/tags/icase-02
965 <a@example.com> tag B refs/tags/icase-03
966 <A@example.com> tag b refs/tags/icase-06
967 <A@example.com> tag B refs/tags/icase-07
968 <b@example.com> tag a refs/tags/icase-08
969 <b@example.com> tag A refs/tags/icase-09
970 <B@example.com> tag a refs/tags/icase-12
971 <B@example.com> tag A refs/tags/icase-13
972 <b@example.com> tag b refs/tags/icase-10
973 <b@example.com> tag B refs/tags/icase-11
974 <B@example.com> tag b refs/tags/icase-14
975 <B@example.com> tag B refs/tags/icase-15
977 test_cmp expect actual