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
55 # Automatically test "contents:size" atom after testing "contents"
56 if test "$2" = "contents"
58 case $(git cat-file -t "$ref") in
60 # We cannot use $3 as it expects sanitize_pgp to run
61 expect=$(git cat-file tag $ref | tail -n +6 | wc -c) ;;
65 expect=$(printf '%s' "$3" | wc -c) ;;
67 # Leave $expect unquoted to lose possible leading whitespaces
68 echo $expect >expected
69 test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" '
70 git for-each-ref --format="%(contents:size)" "$ref" >actual &&
71 test_cmp expected actual
76 hexlen=$(test_oid hexsz)
77 disklen=$(test_oid disklen)
79 test_atom head refname refs/heads/master
80 test_atom head refname: refs/heads/master
81 test_atom head refname:short master
82 test_atom head refname:lstrip=1 heads/master
83 test_atom head refname:lstrip=2 master
84 test_atom head refname:lstrip=-1 master
85 test_atom head refname:lstrip=-2 heads/master
86 test_atom head refname:rstrip=1 refs/heads
87 test_atom head refname:rstrip=2 refs
88 test_atom head refname:rstrip=-1 refs
89 test_atom head refname:rstrip=-2 refs/heads
90 test_atom head refname:strip=1 heads/master
91 test_atom head refname:strip=2 master
92 test_atom head refname:strip=-1 master
93 test_atom head refname:strip=-2 heads/master
94 test_atom head upstream refs/remotes/origin/master
95 test_atom head upstream:short origin/master
96 test_atom head upstream:lstrip=2 origin/master
97 test_atom head upstream:lstrip=-2 origin/master
98 test_atom head upstream:rstrip=2 refs/remotes
99 test_atom head upstream:rstrip=-2 refs/remotes
100 test_atom head upstream:strip=2 origin/master
101 test_atom head upstream:strip=-2 origin/master
102 test_atom head push refs/remotes/myfork/master
103 test_atom head push:short myfork/master
104 test_atom head push:lstrip=1 remotes/myfork/master
105 test_atom head push:lstrip=-1 master
106 test_atom head push:rstrip=1 refs/remotes/myfork
107 test_atom head push:rstrip=-1 refs
108 test_atom head push:strip=1 remotes/myfork/master
109 test_atom head push:strip=-1 master
110 test_atom head objecttype commit
111 test_atom head objectsize $((131 + hexlen))
112 test_atom head objectsize:disk $disklen
113 test_atom head deltabase $ZERO_OID
114 test_atom head objectname $(git rev-parse refs/heads/master)
115 test_atom head objectname:short $(git rev-parse --short refs/heads/master)
116 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
117 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
118 test_atom head tree $(git rev-parse refs/heads/master^{tree})
119 test_atom head parent ''
120 test_atom head numparent 0
121 test_atom head object ''
122 test_atom head type ''
123 test_atom head '*objectname' ''
124 test_atom head '*objecttype' ''
125 test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
126 test_atom head authorname 'A U Thor'
127 test_atom head authoremail '<author@example.com>'
128 test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
129 test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
130 test_atom head committername 'C O Mitter'
131 test_atom head committeremail '<committer@example.com>'
132 test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
133 test_atom head tag ''
134 test_atom head tagger ''
135 test_atom head taggername ''
136 test_atom head taggeremail ''
137 test_atom head taggerdate ''
138 test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
139 test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
140 test_atom head subject 'Initial'
141 test_atom head contents:subject 'Initial'
142 test_atom head body ''
143 test_atom head contents:body ''
144 test_atom head contents:signature ''
145 test_atom head contents 'Initial
147 test_atom head HEAD '*'
149 test_atom tag refname refs/tags/testtag
150 test_atom tag refname:short testtag
151 test_atom tag upstream ''
152 test_atom tag push ''
153 test_atom tag objecttype tag
154 test_atom tag objectsize $((114 + hexlen))
155 test_atom tag objectsize:disk $disklen
156 test_atom tag '*objectsize:disk' $disklen
157 test_atom tag deltabase $ZERO_OID
158 test_atom tag '*deltabase' $ZERO_OID
159 test_atom tag objectname $(git rev-parse refs/tags/testtag)
160 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
161 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
162 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
163 test_atom tag tree ''
164 test_atom tag parent ''
165 test_atom tag numparent ''
166 test_atom tag object $(git rev-parse refs/tags/testtag^0)
167 test_atom tag type 'commit'
168 test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
169 test_atom tag '*objecttype' 'commit'
170 test_atom tag author ''
171 test_atom tag authorname ''
172 test_atom tag authoremail ''
173 test_atom tag authordate ''
174 test_atom tag committer ''
175 test_atom tag committername ''
176 test_atom tag committeremail ''
177 test_atom tag committerdate ''
178 test_atom tag tag 'testtag'
179 test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
180 test_atom tag taggername 'C O Mitter'
181 test_atom tag taggeremail '<committer@example.com>'
182 test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
183 test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
184 test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
185 test_atom tag subject 'Tagging at 1151968727'
186 test_atom tag contents:subject 'Tagging at 1151968727'
187 test_atom tag body ''
188 test_atom tag contents:body ''
189 test_atom tag contents:signature ''
190 test_atom tag contents 'Tagging at 1151968727
192 test_atom tag HEAD ' '
194 test_expect_success 'Check invalid atoms names are errors' '
195 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
198 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
199 git for-each-ref --format="%(authordate)" refs/heads &&
200 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
201 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
202 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
205 test_expect_success 'Check valid format specifiers for date fields' '
206 git for-each-ref --format="%(authordate:default)" refs/heads &&
207 git for-each-ref --format="%(authordate:relative)" refs/heads &&
208 git for-each-ref --format="%(authordate:short)" refs/heads &&
209 git for-each-ref --format="%(authordate:local)" refs/heads &&
210 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
211 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
214 test_expect_success 'Check invalid format specifiers are errors' '
215 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
218 test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
219 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
220 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
221 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
229 cat >expected <<-EOF &&
230 'refs/heads/master' '$committer_date' '$author_date'
231 'refs/tags/testtag' '$tagger_date'
234 git for-each-ref --shell \
235 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
237 git for-each-ref --shell \
238 --format="%(refname) %(taggerdate${f:+:$f})" \
241 test_cmp expected actual
244 test_expect_success 'Check unformatted date fields output' '
246 "Tue Jul 4 01:18:43 2006 +0200" \
247 "Tue Jul 4 01:18:44 2006 +0200" \
248 "Tue Jul 4 01:18:45 2006 +0200"
251 test_expect_success 'Check format "default" formatted date fields output' '
253 "Tue Jul 4 01:18:43 2006 +0200" \
254 "Tue Jul 4 01:18:44 2006 +0200" \
255 "Tue Jul 4 01:18:45 2006 +0200"
258 test_expect_success 'Check format "default-local" date fields output' '
259 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"
262 # Don't know how to do relative check because I can't know when this script
263 # is going to be run and can't fake the current time to git, and hence can't
264 # provide expected output. Instead, I'll just make sure that "relative"
265 # doesn't exit in error
266 test_expect_success 'Check format "relative" date fields output' '
268 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
269 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
272 # We just check that this is the same as "relative" for now.
273 test_expect_success 'Check format "relative-local" date fields output' '
274 test_date relative-local \
275 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
276 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
277 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
280 test_expect_success 'Check format "short" date fields output' '
281 test_date short 2006-07-04 2006-07-04 2006-07-04
284 test_expect_success 'Check format "short-local" date fields output' '
285 test_date short-local 2006-07-03 2006-07-03 2006-07-03
288 test_expect_success 'Check format "local" date fields output' '
290 "Mon Jul 3 23:18:43 2006" \
291 "Mon Jul 3 23:18:44 2006" \
292 "Mon Jul 3 23:18:45 2006"
295 test_expect_success 'Check format "iso8601" date fields output' '
297 "2006-07-04 01:18:43 +0200" \
298 "2006-07-04 01:18:44 +0200" \
299 "2006-07-04 01:18:45 +0200"
302 test_expect_success 'Check format "iso8601-local" date fields output' '
303 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"
306 test_expect_success 'Check format "rfc2822" date fields output' '
308 "Tue, 4 Jul 2006 01:18:43 +0200" \
309 "Tue, 4 Jul 2006 01:18:44 +0200" \
310 "Tue, 4 Jul 2006 01:18:45 +0200"
313 test_expect_success 'Check format "rfc2822-local" date fields output' '
314 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"
317 test_expect_success 'Check format "raw" date fields output' '
318 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
321 test_expect_success 'Check format "raw-local" date fields output' '
322 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
325 test_expect_success 'Check format of strftime date fields' '
326 echo "my date is 2006-07-04" >expected &&
328 --format="%(authordate:format:my date is %Y-%m-%d)" \
329 refs/heads >actual &&
330 test_cmp expected actual
333 test_expect_success 'Check format of strftime-local date fields' '
334 echo "my date is 2006-07-03" >expected &&
336 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
337 refs/heads >actual &&
338 test_cmp expected actual
341 test_expect_success 'exercise strftime with odd fields' '
343 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
344 test_cmp expected actual &&
345 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
346 echo $long >expected &&
347 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
348 test_cmp expected actual
353 refs/remotes/origin/master
357 test_expect_success 'Verify ascending sort' '
358 git for-each-ref --format="%(refname)" --sort=refname >actual &&
359 test_cmp expected actual
365 refs/remotes/origin/master
369 test_expect_success 'Verify descending sort' '
370 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
371 test_cmp expected actual
379 test_expect_success 'exercise patterns with prefixes' '
381 test_when_finished "git tag -d testtag-2" &&
382 git for-each-ref --format="%(refname)" \
383 refs/tags/testtag refs/tags/testtag-2 >actual &&
384 test_cmp expected actual
392 test_expect_success 'exercise glob patterns with prefixes' '
394 test_when_finished "git tag -d testtag-2" &&
395 git for-each-ref --format="%(refname)" \
396 refs/tags/testtag "refs/tags/testtag-*" >actual &&
397 test_cmp expected actual
402 'refs/remotes/origin/master'
406 test_expect_success 'Quoting style: shell' '
407 git for-each-ref --shell --format="%(refname)" >actual &&
408 test_cmp expected actual
411 test_expect_success 'Quoting style: perl' '
412 git for-each-ref --perl --format="%(refname)" >actual &&
413 test_cmp expected actual
416 test_expect_success 'Quoting style: python' '
417 git for-each-ref --python --format="%(refname)" >actual &&
418 test_cmp expected actual
423 "refs/remotes/origin/master"
427 test_expect_success 'Quoting style: tcl' '
428 git for-each-ref --tcl --format="%(refname)" >actual &&
429 test_cmp expected actual
432 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
433 test_expect_success "more than one quoting style: $i" "
434 test_must_fail git for-each-ref $i 2>err &&
435 grep '^error: more than one quoting style' err
439 test_expect_success 'setup for upstream:track[short]' '
443 test_atom head upstream:track '[ahead 1]'
444 test_atom head upstream:trackshort '>'
445 test_atom head upstream:track,nobracket 'ahead 1'
446 test_atom head upstream:nobracket,track 'ahead 1'
448 test_expect_success 'setup for push:track[short]' '
450 git update-ref refs/remotes/myfork/master master &&
454 test_atom head push:track '[behind 1]'
455 test_atom head push:trackshort '<'
457 test_expect_success 'Check that :track[short] cannot be used with other atoms' '
458 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
459 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
462 test_expect_success 'Check that :track[short] works when upstream is invalid' '
463 cat >expected <<-\EOF &&
467 test_when_finished "git config branch.master.merge refs/heads/master" &&
468 git config branch.master.merge refs/heads/does-not-exist &&
470 --format="%(upstream:track)$LF%(upstream:trackshort)" \
471 refs/heads >actual &&
472 test_cmp expected actual
475 test_expect_success 'Check for invalid refname format' '
476 test_must_fail git for-each-ref --format="%(refname:INVALID)"
479 test_expect_success 'set up color tests' '
480 cat >expected.color <<-EOF &&
481 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
482 $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
483 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
484 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
485 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
486 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
488 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
489 color_format="%(objectname:short) %(color:green)%(refname:short)"
492 test_expect_success TTY '%(color) shows color with a tty' '
493 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
494 test_decode_color <actual.raw >actual &&
495 test_cmp expected.color actual
498 test_expect_success '%(color) does not show color without tty' '
499 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
500 test_cmp expected.bare actual
503 test_expect_success '--color can override tty check' '
504 git for-each-ref --color --format="$color_format" >actual.raw &&
505 test_decode_color <actual.raw >actual &&
506 test_cmp expected.color actual
509 test_expect_success 'color.ui=always does not override tty check' '
510 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
511 test_cmp expected.bare actual
519 test_expect_success 'Check ambiguous head and tag refs (strict)' '
520 git config --bool core.warnambiguousrefs true &&
521 git checkout -b newtag &&
522 echo "Using $datestamp" > one &&
524 git commit -m "Branch" &&
525 setdate_and_increment &&
526 git tag -m "Tagging at $datestamp" master &&
527 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
528 test_cmp expected actual
536 test_expect_success 'Check ambiguous head and tag refs (loose)' '
537 git config --bool core.warnambiguousrefs false &&
538 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
539 test_cmp expected actual
547 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
548 git checkout master &&
549 git tag ambiguous testtag^0 &&
550 git branch ambiguous testtag^0 &&
551 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
552 test_cmp expected actual
555 test_expect_success 'create tag without tagger' '
556 git tag -a -m "Broken tag" taggerless &&
557 git tag -f taggerless $(git cat-file tag taggerless |
558 sed -e "/^tagger /d" |
559 git hash-object --stdin -w -t tag)
562 test_atom refs/tags/taggerless type 'commit'
563 test_atom refs/tags/taggerless tag 'taggerless'
564 test_atom refs/tags/taggerless tagger ''
565 test_atom refs/tags/taggerless taggername ''
566 test_atom refs/tags/taggerless taggeremail ''
567 test_atom refs/tags/taggerless taggerdate ''
568 test_atom refs/tags/taggerless committer ''
569 test_atom refs/tags/taggerless committername ''
570 test_atom refs/tags/taggerless committeremail ''
571 test_atom refs/tags/taggerless committerdate ''
572 test_atom refs/tags/taggerless subject 'Broken tag'
574 test_expect_success 'an unusual tag with an incomplete line' '
576 git tag -m "bogo" bogo &&
577 bogo=$(git cat-file tag bogo) &&
578 bogo=$(printf "%s" "$bogo" | git mktag) &&
579 git tag -f bogo "$bogo" &&
580 git for-each-ref --format "%(body)" refs/tags/bogo
584 test_expect_success 'create tag with subject and body content' '
591 git tag -F msg subject-body
593 test_atom refs/tags/subject-body subject 'the subject line'
594 test_atom refs/tags/subject-body body 'first body line
597 test_atom refs/tags/subject-body contents 'the subject line
603 test_expect_success 'create tag with multiline subject' '
611 git tag -F msg multiline
613 test_atom refs/tags/multiline subject 'first subject line second subject line'
614 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
615 test_atom refs/tags/multiline body 'first body line
618 test_atom refs/tags/multiline contents:body 'first body line
621 test_atom refs/tags/multiline contents:signature ''
622 test_atom refs/tags/multiline contents 'first subject line
629 test_expect_success GPG 'create signed tags' '
630 git tag -s -m "" signed-empty &&
631 git tag -s -m "subject line" signed-short &&
637 git tag -s -F msg signed-long
640 sig='-----BEGIN PGP SIGNATURE-----
641 -----END PGP SIGNATURE-----
645 test_atom refs/tags/signed-empty subject ''
646 test_atom refs/tags/signed-empty contents:subject ''
647 test_atom refs/tags/signed-empty body "$sig"
648 test_atom refs/tags/signed-empty contents:body ''
649 test_atom refs/tags/signed-empty contents:signature "$sig"
650 test_atom refs/tags/signed-empty contents "$sig"
652 test_atom refs/tags/signed-short subject 'subject line'
653 test_atom refs/tags/signed-short contents:subject 'subject line'
654 test_atom refs/tags/signed-short body "$sig"
655 test_atom refs/tags/signed-short contents:body ''
656 test_atom refs/tags/signed-short contents:signature "$sig"
657 test_atom refs/tags/signed-short contents "subject line
660 test_atom refs/tags/signed-long subject 'subject line'
661 test_atom refs/tags/signed-long contents:subject 'subject line'
662 test_atom refs/tags/signed-long body "body contents
664 test_atom refs/tags/signed-long contents:body 'body contents
666 test_atom refs/tags/signed-long contents:signature "$sig"
667 test_atom refs/tags/signed-long contents "subject line
672 test_expect_success 'set up refs pointing to tree and blob' '
673 git update-ref refs/mytrees/first refs/heads/master^{tree} &&
674 git update-ref refs/myblobs/first refs/heads/master:one
677 test_atom refs/mytrees/first subject ""
678 test_atom refs/mytrees/first contents:subject ""
679 test_atom refs/mytrees/first body ""
680 test_atom refs/mytrees/first contents:body ""
681 test_atom refs/mytrees/first contents:signature ""
682 test_atom refs/mytrees/first contents ""
684 test_atom refs/myblobs/first subject ""
685 test_atom refs/myblobs/first contents:subject ""
686 test_atom refs/myblobs/first body ""
687 test_atom refs/myblobs/first contents:body ""
688 test_atom refs/myblobs/first contents:signature ""
689 test_atom refs/myblobs/first contents ""
691 test_expect_success 'set up multiple-sort tags' '
692 for when in 100000 200000
694 for email in user1 user2
698 GIT_COMMITTER_DATE="@$when +0000" \
699 GIT_COMMITTER_EMAIL="$email@example.com" \
700 git tag -m "tag $ref-$when-$email" \
701 multi-$ref-$when-$email || return 1
707 test_expect_success 'Verify sort with multiple keys' '
708 cat >expected <<-\EOF &&
709 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
710 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
711 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
712 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
713 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
714 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
715 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
716 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
719 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
723 "refs/tags/multi-*" >actual &&
724 test_cmp expected actual
727 test_expect_success 'equivalent sorts fall back on refname' '
728 cat >expected <<-\EOF &&
729 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
730 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
731 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
732 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
733 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
734 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
735 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
736 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
739 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
741 "refs/tags/multi-*" >actual &&
742 test_cmp expected actual
745 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
746 test_when_finished "git checkout master" &&
747 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
748 sed -e "s/^\* / /" actual >expect &&
749 git checkout --orphan orphaned-branch &&
750 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
751 test_cmp expect actual
755 Reviewed-by: A U Thor <author@example.com>
756 Signed-off-by: A U Thor <author@example.com>
757 [ v2 updated patch description ]
763 perl -0pe 's/\n\s+/ /g'
766 test_expect_success 'set up trailers for next test' '
767 echo "Some contents" > two &&
769 git commit -F - <<-EOF
770 trailers: this commit message has trailers
772 Some message contents
778 test_expect_success '%(trailers:unfold) unfolds trailers' '
783 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
784 test_cmp expect actual &&
785 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
786 test_cmp expect actual
789 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
791 grep -v patch.description <trailers &&
794 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
795 test_cmp expect actual &&
796 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
797 test_cmp expect actual
800 test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
802 grep -v patch.description <trailers | unfold &&
805 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
806 test_cmp expect actual &&
807 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >actual &&
808 test_cmp actual actual &&
809 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
810 test_cmp expect actual &&
811 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >actual &&
812 test_cmp actual actual
815 test_expect_success '%(trailers) rejects unknown trailers arguments' '
816 # error message cannot be checked under i18n
817 cat >expect <<-EOF &&
818 fatal: unknown %(trailers) argument: unsupported
820 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
821 test_i18ncmp expect actual &&
822 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
823 test_i18ncmp expect actual
826 test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
827 cat >expect <<-EOF &&
828 fatal: unrecognized %(contents) argument: trailersonly
830 test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
831 test_i18ncmp expect actual
834 test_expect_success 'basic atom: head contents:trailers' '
835 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
836 sanitize_pgp <actual >actual.clean &&
837 # git for-each-ref ends with a blank line
838 cat >expect <<-EOF &&
842 test_cmp expect actual.clean
845 test_expect_success 'trailer parsing not fooled by --- line' '
846 git commit --allow-empty -F - <<-\EOF &&
849 This is the body. The message has a "---" line which would confuse a
850 message+patch parser. But here we know we have only a commit message,
861 echo "trailer: right" &&
864 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
865 test_cmp expect actual
868 test_expect_success 'Add symbolic ref for the following tests' '
869 git symbolic-ref refs/heads/sym refs/heads/master
876 test_expect_success 'Verify usage of %(symref) atom' '
877 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
878 test_cmp expected actual
885 test_expect_success 'Verify usage of %(symref:short) atom' '
886 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
887 test_cmp expected actual
895 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
896 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
897 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
898 test_cmp expected actual &&
900 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
901 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
902 test_cmp expected actual
910 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
911 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
912 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
913 test_cmp expected actual
916 test_expect_success ':remotename and :remoteref' '
917 git init remote-tests &&
920 test_commit initial &&
921 git remote add from fifth.coffee:blub &&
922 git config branch.master.remote from &&
923 git config branch.master.merge refs/heads/stable &&
924 git remote add to southridge.audio:repo &&
925 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
926 git config branch.master.pushRemote to &&
927 for pair in "%(upstream)=refs/remotes/from/stable" \
928 "%(upstream:remotename)=from" \
929 "%(upstream:remoteref)=refs/heads/stable" \
930 "%(push)=refs/remotes/to/pushed/master" \
931 "%(push:remotename)=to" \
932 "%(push:remoteref)=refs/heads/pushed/master"
934 echo "${pair#*=}" >expect &&
935 git for-each-ref --format="${pair%=*}" \
936 refs/heads/master >actual &&
937 test_cmp expect actual
939 git branch push-simple &&
940 git config branch.push-simple.pushRemote from &&
941 actual="$(git for-each-ref \
942 --format="%(push:remotename),%(push:remoteref)" \
943 refs/heads/push-simple)" &&
944 test from, = "$actual"
948 test_expect_success 'for-each-ref --ignore-case ignores case' '
949 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
950 test_must_be_empty actual &&
952 echo refs/heads/master >expect &&
953 git for-each-ref --format="%(refname)" --ignore-case \
954 refs/heads/MASTER >actual &&
955 test_cmp expect actual
958 test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
959 # name refs numerically to avoid case-insensitive filesystem conflicts
963 for subject in a A b B
965 GIT_COMMITTER_EMAIL="$email@example.com" \
966 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
971 git for-each-ref --ignore-case \
972 --format="%(taggeremail) %(subject) %(refname)" \
976 refs/tags/icase-* >actual &&
977 cat >expect <<-\EOF &&
978 <a@example.com> tag a refs/tags/icase-00
979 <a@example.com> tag A refs/tags/icase-01
980 <A@example.com> tag a refs/tags/icase-04
981 <A@example.com> tag A refs/tags/icase-05
982 <a@example.com> tag b refs/tags/icase-02
983 <a@example.com> tag B refs/tags/icase-03
984 <A@example.com> tag b refs/tags/icase-06
985 <A@example.com> tag B refs/tags/icase-07
986 <b@example.com> tag a refs/tags/icase-08
987 <b@example.com> tag A refs/tags/icase-09
988 <B@example.com> tag a refs/tags/icase-12
989 <B@example.com> tag A refs/tags/icase-13
990 <b@example.com> tag b refs/tags/icase-10
991 <b@example.com> tag B refs/tags/icase-11
992 <B@example.com> tag b refs/tags/icase-14
993 <B@example.com> tag B refs/tags/icase-15
995 test_cmp expect actual