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 tree:short $(git rev-parse --short refs/heads/master^{tree})
120 test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/master^{tree})
121 test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/master^{tree})
122 test_atom head parent ''
123 test_atom head parent:short ''
124 test_atom head parent:short=1 ''
125 test_atom head parent:short=10 ''
126 test_atom head numparent 0
127 test_atom head object ''
128 test_atom head type ''
129 test_atom head '*objectname' ''
130 test_atom head '*objecttype' ''
131 test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
132 test_atom head authorname 'A U Thor'
133 test_atom head authoremail '<author@example.com>'
134 test_atom head authoremail:trim 'author@example.com'
135 test_atom head authoremail:localpart 'author'
136 test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
137 test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
138 test_atom head committername 'C O Mitter'
139 test_atom head committeremail '<committer@example.com>'
140 test_atom head committeremail:trim 'committer@example.com'
141 test_atom head committeremail:localpart 'committer'
142 test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
143 test_atom head tag ''
144 test_atom head tagger ''
145 test_atom head taggername ''
146 test_atom head taggeremail ''
147 test_atom head taggeremail:trim ''
148 test_atom head taggeremail:localpart ''
149 test_atom head taggerdate ''
150 test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
151 test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
152 test_atom head subject 'Initial'
153 test_atom head subject:sanitize 'Initial'
154 test_atom head contents:subject 'Initial'
155 test_atom head body ''
156 test_atom head contents:body ''
157 test_atom head contents:signature ''
158 test_atom head contents 'Initial
160 test_atom head HEAD '*'
162 test_atom tag refname refs/tags/testtag
163 test_atom tag refname:short testtag
164 test_atom tag upstream ''
165 test_atom tag push ''
166 test_atom tag objecttype tag
167 test_atom tag objectsize $((114 + hexlen))
168 test_atom tag objectsize:disk $disklen
169 test_atom tag '*objectsize:disk' $disklen
170 test_atom tag deltabase $ZERO_OID
171 test_atom tag '*deltabase' $ZERO_OID
172 test_atom tag objectname $(git rev-parse refs/tags/testtag)
173 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
174 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
175 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
176 test_atom tag tree ''
177 test_atom tag tree:short ''
178 test_atom tag tree:short=1 ''
179 test_atom tag tree:short=10 ''
180 test_atom tag parent ''
181 test_atom tag parent:short ''
182 test_atom tag parent:short=1 ''
183 test_atom tag parent:short=10 ''
184 test_atom tag numparent ''
185 test_atom tag object $(git rev-parse refs/tags/testtag^0)
186 test_atom tag type 'commit'
187 test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
188 test_atom tag '*objecttype' 'commit'
189 test_atom tag author ''
190 test_atom tag authorname ''
191 test_atom tag authoremail ''
192 test_atom tag authoremail:trim ''
193 test_atom tag authoremail:localpart ''
194 test_atom tag authordate ''
195 test_atom tag committer ''
196 test_atom tag committername ''
197 test_atom tag committeremail ''
198 test_atom tag committeremail:trim ''
199 test_atom tag committeremail:localpart ''
200 test_atom tag committerdate ''
201 test_atom tag tag 'testtag'
202 test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
203 test_atom tag taggername 'C O Mitter'
204 test_atom tag taggeremail '<committer@example.com>'
205 test_atom tag taggeremail:trim 'committer@example.com'
206 test_atom tag taggeremail:localpart 'committer'
207 test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
208 test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
209 test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
210 test_atom tag subject 'Tagging at 1151968727'
211 test_atom tag subject:sanitize 'Tagging-at-1151968727'
212 test_atom tag contents:subject 'Tagging at 1151968727'
213 test_atom tag body ''
214 test_atom tag contents:body ''
215 test_atom tag contents:signature ''
216 test_atom tag contents 'Tagging at 1151968727
218 test_atom tag HEAD ' '
220 test_expect_success 'Check invalid atoms names are errors' '
221 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
224 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
225 git for-each-ref --format="%(authordate)" refs/heads &&
226 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
227 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
228 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
231 test_expect_success 'Check valid format specifiers for date fields' '
232 git for-each-ref --format="%(authordate:default)" refs/heads &&
233 git for-each-ref --format="%(authordate:relative)" refs/heads &&
234 git for-each-ref --format="%(authordate:short)" refs/heads &&
235 git for-each-ref --format="%(authordate:local)" refs/heads &&
236 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
237 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
240 test_expect_success 'Check invalid format specifiers are errors' '
241 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
244 test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
245 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
246 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
247 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
255 cat >expected <<-EOF &&
256 'refs/heads/master' '$committer_date' '$author_date'
257 'refs/tags/testtag' '$tagger_date'
260 git for-each-ref --shell \
261 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
263 git for-each-ref --shell \
264 --format="%(refname) %(taggerdate${f:+:$f})" \
267 test_cmp expected actual
270 test_expect_success 'Check unformatted date fields output' '
272 "Tue Jul 4 01:18:43 2006 +0200" \
273 "Tue Jul 4 01:18:44 2006 +0200" \
274 "Tue Jul 4 01:18:45 2006 +0200"
277 test_expect_success 'Check format "default" formatted date fields output' '
279 "Tue Jul 4 01:18:43 2006 +0200" \
280 "Tue Jul 4 01:18:44 2006 +0200" \
281 "Tue Jul 4 01:18:45 2006 +0200"
284 test_expect_success 'Check format "default-local" date fields output' '
285 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"
288 # Don't know how to do relative check because I can't know when this script
289 # is going to be run and can't fake the current time to git, and hence can't
290 # provide expected output. Instead, I'll just make sure that "relative"
291 # doesn't exit in error
292 test_expect_success 'Check format "relative" date fields output' '
294 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
295 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
298 # We just check that this is the same as "relative" for now.
299 test_expect_success 'Check format "relative-local" date fields output' '
300 test_date relative-local \
301 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
302 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
303 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
306 test_expect_success 'Check format "short" date fields output' '
307 test_date short 2006-07-04 2006-07-04 2006-07-04
310 test_expect_success 'Check format "short-local" date fields output' '
311 test_date short-local 2006-07-03 2006-07-03 2006-07-03
314 test_expect_success 'Check format "local" date fields output' '
316 "Mon Jul 3 23:18:43 2006" \
317 "Mon Jul 3 23:18:44 2006" \
318 "Mon Jul 3 23:18:45 2006"
321 test_expect_success 'Check format "iso8601" date fields output' '
323 "2006-07-04 01:18:43 +0200" \
324 "2006-07-04 01:18:44 +0200" \
325 "2006-07-04 01:18:45 +0200"
328 test_expect_success 'Check format "iso8601-local" date fields output' '
329 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"
332 test_expect_success 'Check format "rfc2822" date fields output' '
334 "Tue, 4 Jul 2006 01:18:43 +0200" \
335 "Tue, 4 Jul 2006 01:18:44 +0200" \
336 "Tue, 4 Jul 2006 01:18:45 +0200"
339 test_expect_success 'Check format "rfc2822-local" date fields output' '
340 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"
343 test_expect_success 'Check format "raw" date fields output' '
344 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
347 test_expect_success 'Check format "raw-local" date fields output' '
348 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
351 test_expect_success 'Check format of strftime date fields' '
352 echo "my date is 2006-07-04" >expected &&
354 --format="%(authordate:format:my date is %Y-%m-%d)" \
355 refs/heads >actual &&
356 test_cmp expected actual
359 test_expect_success 'Check format of strftime-local date fields' '
360 echo "my date is 2006-07-03" >expected &&
362 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
363 refs/heads >actual &&
364 test_cmp expected actual
367 test_expect_success 'exercise strftime with odd fields' '
369 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
370 test_cmp expected actual &&
371 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
372 echo $long >expected &&
373 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
374 test_cmp expected actual
379 refs/remotes/origin/master
383 test_expect_success 'Verify ascending sort' '
384 git for-each-ref --format="%(refname)" --sort=refname >actual &&
385 test_cmp expected actual
391 refs/remotes/origin/master
395 test_expect_success 'Verify descending sort' '
396 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
397 test_cmp expected actual
405 test_expect_success 'exercise patterns with prefixes' '
407 test_when_finished "git tag -d testtag-2" &&
408 git for-each-ref --format="%(refname)" \
409 refs/tags/testtag refs/tags/testtag-2 >actual &&
410 test_cmp expected actual
418 test_expect_success 'exercise glob patterns with prefixes' '
420 test_when_finished "git tag -d testtag-2" &&
421 git for-each-ref --format="%(refname)" \
422 refs/tags/testtag "refs/tags/testtag-*" >actual &&
423 test_cmp expected actual
428 'refs/remotes/origin/master'
432 test_expect_success 'Quoting style: shell' '
433 git for-each-ref --shell --format="%(refname)" >actual &&
434 test_cmp expected actual
437 test_expect_success 'Quoting style: perl' '
438 git for-each-ref --perl --format="%(refname)" >actual &&
439 test_cmp expected actual
442 test_expect_success 'Quoting style: python' '
443 git for-each-ref --python --format="%(refname)" >actual &&
444 test_cmp expected actual
449 "refs/remotes/origin/master"
453 test_expect_success 'Quoting style: tcl' '
454 git for-each-ref --tcl --format="%(refname)" >actual &&
455 test_cmp expected actual
458 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
459 test_expect_success "more than one quoting style: $i" "
460 test_must_fail git for-each-ref $i 2>err &&
461 grep '^error: more than one quoting style' err
465 test_expect_success 'setup for upstream:track[short]' '
469 test_atom head upstream:track '[ahead 1]'
470 test_atom head upstream:trackshort '>'
471 test_atom head upstream:track,nobracket 'ahead 1'
472 test_atom head upstream:nobracket,track 'ahead 1'
474 test_expect_success 'setup for push:track[short]' '
476 git update-ref refs/remotes/myfork/master master &&
480 test_atom head push:track '[behind 1]'
481 test_atom head push:trackshort '<'
483 test_expect_success 'Check that :track[short] cannot be used with other atoms' '
484 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
485 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
488 test_expect_success 'Check that :track[short] works when upstream is invalid' '
489 cat >expected <<-\EOF &&
493 test_when_finished "git config branch.master.merge refs/heads/master" &&
494 git config branch.master.merge refs/heads/does-not-exist &&
496 --format="%(upstream:track)$LF%(upstream:trackshort)" \
497 refs/heads >actual &&
498 test_cmp expected actual
501 test_expect_success 'Check for invalid refname format' '
502 test_must_fail git for-each-ref --format="%(refname:INVALID)"
505 test_expect_success 'set up color tests' '
506 cat >expected.color <<-EOF &&
507 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
508 $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
509 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
510 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
511 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
512 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
514 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
515 color_format="%(objectname:short) %(color:green)%(refname:short)"
518 test_expect_success TTY '%(color) shows color with a tty' '
519 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
520 test_decode_color <actual.raw >actual &&
521 test_cmp expected.color actual
524 test_expect_success '%(color) does not show color without tty' '
525 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
526 test_cmp expected.bare actual
529 test_expect_success '--color can override tty check' '
530 git for-each-ref --color --format="$color_format" >actual.raw &&
531 test_decode_color <actual.raw >actual &&
532 test_cmp expected.color actual
535 test_expect_success 'color.ui=always does not override tty check' '
536 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
537 test_cmp expected.bare actual
545 test_expect_success 'Check ambiguous head and tag refs (strict)' '
546 git config --bool core.warnambiguousrefs true &&
547 git checkout -b newtag &&
548 echo "Using $datestamp" > one &&
550 git commit -m "Branch" &&
551 setdate_and_increment &&
552 git tag -m "Tagging at $datestamp" master &&
553 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
554 test_cmp expected actual
562 test_expect_success 'Check ambiguous head and tag refs (loose)' '
563 git config --bool core.warnambiguousrefs false &&
564 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
565 test_cmp expected actual
573 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
574 git checkout master &&
575 git tag ambiguous testtag^0 &&
576 git branch ambiguous testtag^0 &&
577 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
578 test_cmp expected actual
581 test_expect_success 'create tag without tagger' '
582 git tag -a -m "Broken tag" taggerless &&
583 git tag -f taggerless $(git cat-file tag taggerless |
584 sed -e "/^tagger /d" |
585 git hash-object --stdin -w -t tag)
588 test_atom refs/tags/taggerless type 'commit'
589 test_atom refs/tags/taggerless tag 'taggerless'
590 test_atom refs/tags/taggerless tagger ''
591 test_atom refs/tags/taggerless taggername ''
592 test_atom refs/tags/taggerless taggeremail ''
593 test_atom refs/tags/taggerless taggeremail:trim ''
594 test_atom refs/tags/taggerless taggeremail:localpart ''
595 test_atom refs/tags/taggerless taggerdate ''
596 test_atom refs/tags/taggerless committer ''
597 test_atom refs/tags/taggerless committername ''
598 test_atom refs/tags/taggerless committeremail ''
599 test_atom refs/tags/taggerless committeremail:trim ''
600 test_atom refs/tags/taggerless committeremail:localpart ''
601 test_atom refs/tags/taggerless committerdate ''
602 test_atom refs/tags/taggerless subject 'Broken tag'
604 test_expect_success 'an unusual tag with an incomplete line' '
606 git tag -m "bogo" bogo &&
607 bogo=$(git cat-file tag bogo) &&
608 bogo=$(printf "%s" "$bogo" | git mktag) &&
609 git tag -f bogo "$bogo" &&
610 git for-each-ref --format "%(body)" refs/tags/bogo
614 test_expect_success 'create tag with subject and body content' '
621 git tag -F msg subject-body
623 test_atom refs/tags/subject-body subject 'the subject line'
624 test_atom refs/tags/subject-body subject:sanitize 'the-subject-line'
625 test_atom refs/tags/subject-body body 'first body line
628 test_atom refs/tags/subject-body contents 'the subject line
634 test_expect_success 'create tag with multiline subject' '
642 git tag -F msg multiline
644 test_atom refs/tags/multiline subject 'first subject line second subject line'
645 test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line'
646 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
647 test_atom refs/tags/multiline body 'first body line
650 test_atom refs/tags/multiline contents:body 'first body line
653 test_atom refs/tags/multiline contents:signature ''
654 test_atom refs/tags/multiline contents 'first subject line
661 test_expect_success GPG 'create signed tags' '
662 git tag -s -m "" signed-empty &&
663 git tag -s -m "subject line" signed-short &&
669 git tag -s -F msg signed-long
672 sig='-----BEGIN PGP SIGNATURE-----
673 -----END PGP SIGNATURE-----
677 test_atom refs/tags/signed-empty subject ''
678 test_atom refs/tags/signed-empty subject:sanitize ''
679 test_atom refs/tags/signed-empty contents:subject ''
680 test_atom refs/tags/signed-empty body "$sig"
681 test_atom refs/tags/signed-empty contents:body ''
682 test_atom refs/tags/signed-empty contents:signature "$sig"
683 test_atom refs/tags/signed-empty contents "$sig"
685 test_atom refs/tags/signed-short subject 'subject line'
686 test_atom refs/tags/signed-short subject:sanitize 'subject-line'
687 test_atom refs/tags/signed-short contents:subject 'subject line'
688 test_atom refs/tags/signed-short body "$sig"
689 test_atom refs/tags/signed-short contents:body ''
690 test_atom refs/tags/signed-short contents:signature "$sig"
691 test_atom refs/tags/signed-short contents "subject line
694 test_atom refs/tags/signed-long subject 'subject line'
695 test_atom refs/tags/signed-long subject:sanitize 'subject-line'
696 test_atom refs/tags/signed-long contents:subject 'subject line'
697 test_atom refs/tags/signed-long body "body contents
699 test_atom refs/tags/signed-long contents:body 'body contents
701 test_atom refs/tags/signed-long contents:signature "$sig"
702 test_atom refs/tags/signed-long contents "subject line
707 test_expect_success 'set up refs pointing to tree and blob' '
708 git update-ref refs/mytrees/first refs/heads/master^{tree} &&
709 git update-ref refs/myblobs/first refs/heads/master:one
712 test_atom refs/mytrees/first subject ""
713 test_atom refs/mytrees/first contents:subject ""
714 test_atom refs/mytrees/first body ""
715 test_atom refs/mytrees/first contents:body ""
716 test_atom refs/mytrees/first contents:signature ""
717 test_atom refs/mytrees/first contents ""
719 test_atom refs/myblobs/first subject ""
720 test_atom refs/myblobs/first contents:subject ""
721 test_atom refs/myblobs/first body ""
722 test_atom refs/myblobs/first contents:body ""
723 test_atom refs/myblobs/first contents:signature ""
724 test_atom refs/myblobs/first contents ""
726 test_expect_success 'set up multiple-sort tags' '
727 for when in 100000 200000
729 for email in user1 user2
733 GIT_COMMITTER_DATE="@$when +0000" \
734 GIT_COMMITTER_EMAIL="$email@example.com" \
735 git tag -m "tag $ref-$when-$email" \
736 multi-$ref-$when-$email || return 1
742 test_expect_success 'Verify sort with multiple keys' '
743 cat >expected <<-\EOF &&
744 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
745 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
746 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
747 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
748 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
749 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
750 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
751 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
754 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
758 "refs/tags/multi-*" >actual &&
759 test_cmp expected actual
762 test_expect_success 'equivalent sorts fall back on refname' '
763 cat >expected <<-\EOF &&
764 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
765 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
766 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
767 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
768 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
769 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
770 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
771 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
774 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
776 "refs/tags/multi-*" >actual &&
777 test_cmp expected actual
780 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
781 test_when_finished "git checkout master" &&
782 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
783 sed -e "s/^\* / /" actual >expect &&
784 git checkout --orphan orphaned-branch &&
785 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
786 test_cmp expect actual
790 Reviewed-by: A U Thor <author@example.com>
791 Signed-off-by: A U Thor <author@example.com>
792 [ v2 updated patch description ]
798 perl -0pe 's/\n\s+/ /g'
801 test_expect_success 'set up trailers for next test' '
802 echo "Some contents" > two &&
804 git commit -F - <<-EOF
805 trailers: this commit message has trailers
807 Some message contents
813 test_expect_success '%(trailers:unfold) unfolds trailers' '
818 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
819 test_cmp expect actual &&
820 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
821 test_cmp expect actual
824 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
826 grep -v patch.description <trailers &&
829 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
830 test_cmp expect actual &&
831 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
832 test_cmp expect actual
835 test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
837 grep -v patch.description <trailers | unfold &&
840 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
841 test_cmp expect actual &&
842 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >actual &&
843 test_cmp actual actual &&
844 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
845 test_cmp expect actual &&
846 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >actual &&
847 test_cmp actual actual
850 test_expect_success '%(trailers) rejects unknown trailers arguments' '
851 # error message cannot be checked under i18n
852 cat >expect <<-EOF &&
853 fatal: unknown %(trailers) argument: unsupported
855 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
856 test_i18ncmp expect actual &&
857 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
858 test_i18ncmp expect actual
861 test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
862 cat >expect <<-EOF &&
863 fatal: unrecognized %(contents) argument: trailersonly
865 test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
866 test_i18ncmp expect actual
869 test_expect_success 'basic atom: head contents:trailers' '
870 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
871 sanitize_pgp <actual >actual.clean &&
872 # git for-each-ref ends with a blank line
873 cat >expect <<-EOF &&
877 test_cmp expect actual.clean
880 test_expect_success 'trailer parsing not fooled by --- line' '
881 git commit --allow-empty -F - <<-\EOF &&
884 This is the body. The message has a "---" line which would confuse a
885 message+patch parser. But here we know we have only a commit message,
896 echo "trailer: right" &&
899 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
900 test_cmp expect actual
903 test_expect_success 'Add symbolic ref for the following tests' '
904 git symbolic-ref refs/heads/sym refs/heads/master
911 test_expect_success 'Verify usage of %(symref) atom' '
912 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
913 test_cmp expected actual
920 test_expect_success 'Verify usage of %(symref:short) atom' '
921 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
922 test_cmp expected actual
930 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
931 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
932 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
933 test_cmp expected actual &&
935 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
936 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
937 test_cmp expected actual
945 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
946 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
947 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
948 test_cmp expected actual
951 test_expect_success ':remotename and :remoteref' '
952 git init remote-tests &&
955 test_commit initial &&
956 git remote add from fifth.coffee:blub &&
957 git config branch.master.remote from &&
958 git config branch.master.merge refs/heads/stable &&
959 git remote add to southridge.audio:repo &&
960 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
961 git config branch.master.pushRemote to &&
962 for pair in "%(upstream)=refs/remotes/from/stable" \
963 "%(upstream:remotename)=from" \
964 "%(upstream:remoteref)=refs/heads/stable" \
965 "%(push)=refs/remotes/to/pushed/master" \
966 "%(push:remotename)=to" \
967 "%(push:remoteref)=refs/heads/pushed/master"
969 echo "${pair#*=}" >expect &&
970 git for-each-ref --format="${pair%=*}" \
971 refs/heads/master >actual &&
972 test_cmp expect actual
974 git branch push-simple &&
975 git config branch.push-simple.pushRemote from &&
976 actual="$(git for-each-ref \
977 --format="%(push:remotename),%(push:remoteref)" \
978 refs/heads/push-simple)" &&
979 test from, = "$actual"
983 test_expect_success 'for-each-ref --ignore-case ignores case' '
984 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
985 test_must_be_empty actual &&
987 echo refs/heads/master >expect &&
988 git for-each-ref --format="%(refname)" --ignore-case \
989 refs/heads/MASTER >actual &&
990 test_cmp expect actual
993 test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
994 # name refs numerically to avoid case-insensitive filesystem conflicts
998 for subject in a A b B
1000 GIT_COMMITTER_EMAIL="$email@example.com" \
1001 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
1006 git for-each-ref --ignore-case \
1007 --format="%(taggeremail) %(subject) %(refname)" \
1010 --sort=taggeremail \
1011 refs/tags/icase-* >actual &&
1012 cat >expect <<-\EOF &&
1013 <a@example.com> tag a refs/tags/icase-00
1014 <a@example.com> tag A refs/tags/icase-01
1015 <A@example.com> tag a refs/tags/icase-04
1016 <A@example.com> tag A refs/tags/icase-05
1017 <a@example.com> tag b refs/tags/icase-02
1018 <a@example.com> tag B refs/tags/icase-03
1019 <A@example.com> tag b refs/tags/icase-06
1020 <A@example.com> tag B refs/tags/icase-07
1021 <b@example.com> tag a refs/tags/icase-08
1022 <b@example.com> tag A refs/tags/icase-09
1023 <B@example.com> tag a refs/tags/icase-12
1024 <B@example.com> tag A refs/tags/icase-13
1025 <b@example.com> tag b refs/tags/icase-10
1026 <b@example.com> tag B refs/tags/icase-11
1027 <B@example.com> tag b refs/tags/icase-14
1028 <B@example.com> tag B refs/tags/icase-15
1030 test_cmp expect actual