Merge branch 'dl/test-must-fail-fixes-5'
[git/raj.git] / t / t6300-for-each-ref.sh
blobda59fadc5d8f915cbb60cd426c58becb04e7c42a
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 test_oid_cache <<-EOF &&
24 disklen sha1:138
25 disklen sha256:154
26 EOF
27 setdate_and_increment &&
28 echo "Using $datestamp" > one &&
29 git add 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
42 test_atom() {
43 case "$1" in
44 head) ref=refs/heads/master ;;
45 tag) ref=refs/tags/testtag ;;
46 sym) ref=refs/heads/sym ;;
47 *) ref=$1 ;;
48 esac
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)"
205 test_date () {
206 f=$1 &&
207 committer_date=$2 &&
208 author_date=$3 &&
209 tagger_date=$4 &&
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})" \
217 refs/heads &&
218 git for-each-ref --shell \
219 --format="%(refname) %(taggerdate${f:+:$f})" \
220 refs/tags
221 ) >actual &&
222 test_cmp expected actual
225 test_expect_success 'Check unformatted date fields output' '
226 test_date "" \
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' '
233 test_date default \
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' '
248 f=relative &&
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' '
270 test_date local \
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' '
277 test_date iso8601 \
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' '
288 test_date rfc2822 \
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 &&
308 git for-each-ref \
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 &&
316 git for-each-ref \
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' '
323 echo >expected &&
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
332 cat >expected <<\EOF
333 refs/heads/master
334 refs/remotes/origin/master
335 refs/tags/testtag
338 test_expect_success 'Verify ascending sort' '
339 git for-each-ref --format="%(refname)" --sort=refname >actual &&
340 test_cmp expected actual
344 cat >expected <<\EOF
345 refs/tags/testtag
346 refs/remotes/origin/master
347 refs/heads/master
350 test_expect_success 'Verify descending sort' '
351 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
352 test_cmp expected actual
355 cat >expected <<\EOF
356 refs/tags/testtag
357 refs/tags/testtag-2
360 test_expect_success 'exercise patterns with prefixes' '
361 git tag testtag-2 &&
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
368 cat >expected <<\EOF
369 refs/tags/testtag
370 refs/tags/testtag-2
373 test_expect_success 'exercise glob patterns with prefixes' '
374 git tag testtag-2 &&
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
381 cat >expected <<\EOF
382 'refs/heads/master'
383 'refs/remotes/origin/master'
384 'refs/tags/testtag'
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
402 cat >expected <<\EOF
403 "refs/heads/master"
404 "refs/remotes/origin/master"
405 "refs/tags/testtag"
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
418 done
420 test_expect_success 'setup for upstream:track[short]' '
421 test_commit two
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]' '
430 test_commit third &&
431 git update-ref refs/remotes/myfork/master master &&
432 git reset master~1
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 &&
445 [gone]
448 test_when_finished "git config branch.master.merge refs/heads/master" &&
449 git config branch.master.merge refs/heads/does-not-exist &&
450 git for-each-ref \
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
495 cat >expected <<\EOF
496 heads/master
497 tags/master
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 &&
504 git add 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
512 cat >expected <<\EOF
513 heads/master
514 master
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
523 cat >expected <<\EOF
524 heads/ambiguous
525 ambiguous
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' '
566 cat >>msg <<-\EOF &&
567 the subject line
569 first body line
570 second body line
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
576 second body line
578 test_atom refs/tags/subject-body contents 'the subject line
580 first body line
581 second body line
584 test_expect_success 'create tag with multiline subject' '
585 cat >msg <<-\EOF &&
586 first subject line
587 second subject line
589 first body line
590 second body line
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
597 second body line
599 test_atom refs/tags/multiline contents:body 'first body line
600 second body line
602 test_atom refs/tags/multiline contents:signature ''
603 test_atom refs/tags/multiline contents 'first subject line
604 second subject line
606 first body line
607 second body 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 &&
613 cat >msg <<-\EOF &&
614 subject line
616 body contents
618 git tag -s -F msg signed-long
621 sig='-----BEGIN PGP SIGNATURE-----
622 -----END PGP SIGNATURE-----
625 PREREQ=GPG
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
639 $sig"
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
644 $sig"
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
650 body contents
651 $sig"
653 test_expect_success 'set up multiple-sort tags' '
654 for when in 100000 200000
656 for email in user1 user2
658 for ref in ref1 ref2
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
664 done
665 done
666 done
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
680 git for-each-ref \
681 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
682 --sort=-refname \
683 --sort=taggeremail \
684 --sort=taggerdate \
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
700 git for-each-ref \
701 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
702 --sort=taggerdate \
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
716 cat >trailers <<EOF
717 Reviewed-by: A U Thor <author@example.com>
718 Signed-off-by: A U Thor <author@example.com>
719 [ v2 updated patch description ]
720 Acked-by: A U Thor
721 <author@example.com>
724 unfold () {
725 perl -0pe 's/\n\s+/ /g'
728 test_expect_success 'set up trailers for next test' '
729 echo "Some contents" > two &&
730 git add two &&
731 git commit -F - <<-EOF
732 trailers: this commit message has trailers
734 Some message contents
736 $(cat trailers)
740 test_expect_success '%(trailers:unfold) unfolds trailers' '
741 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
743 unfold <trailers
744 echo
745 } >expect &&
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 &&
753 echo
754 } >expect &&
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 &&
764 echo
765 } >expect &&
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 &&
772 unfold <trailers
773 echo
774 } >expect &&
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 &&
782 echo
783 } >expect &&
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 &&
793 echo
794 } >expect &&
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 &&
821 $(cat trailers)
824 test_cmp expect actual.clean
827 test_expect_success 'trailer parsing not fooled by --- line' '
828 git commit --allow-empty -F - <<-\EOF &&
829 this is the subject
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,
833 so we get it right.
835 trailer: wrong
837 This is more body.
839 trailer: right
843 echo "trailer: right" &&
844 echo
845 } >expect &&
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
854 cat >expected <<EOF
855 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
863 cat >expected <<EOF
864 heads/master
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
872 cat >expected <<EOF
873 master
874 heads/master
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
887 cat >expected <<EOF
888 refs
889 refs/heads
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 &&
901 cd 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
920 done &&
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
942 nr=0 &&
943 for email in a A b B
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) &&
949 nr=$((nr+1))||
950 return 1
951 done
952 done &&
953 git for-each-ref --ignore-case \
954 --format="%(taggeremail) %(subject) %(refname)" \
955 --sort=refname \
956 --sort=subject \
957 --sort=taggeremail \
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
980 test_done