1#!/bin/sh
2#
3# Copyright (c) 2007 Andy Parkins
4#
5
6test_description='for-each-ref test'
7
8. ./test-lib.sh
9. "$TEST_DIRECTORY"/lib-gpg.sh
10. "$TEST_DIRECTORY"/lib-terminal.sh
11
12# Mon Jul 3 23:18:43 2006 +0000
13datestamp=1151968723
14setdate_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
20}
21
22test_expect_success setup '
23 setdate_and_increment &&
24 echo "Using $datestamp" > one &&
25 git add one &&
26 git commit -m "Initial" &&
27 setdate_and_increment &&
28 git tag -a -m "Tagging at $datestamp" testtag &&
29 git update-ref refs/remotes/origin/master master &&
30 git remote add origin nowhere &&
31 git config branch.master.remote origin &&
32 git config branch.master.merge refs/heads/master &&
33 git remote add myfork elsewhere &&
34 git config remote.pushdefault myfork &&
35 git config push.default current
36'
37
38test_atom() {
39 case "$1" in
40 head) ref=refs/heads/master ;;
41 tag) ref=refs/tags/testtag ;;
42 sym) ref=refs/heads/sym ;;
43 *) ref=$1 ;;
44 esac
45 printf '%s\n' "$3" >expected
46 test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
47 git for-each-ref --format='%($2)' $ref >actual &&
48 sanitize_pgp <actual >actual.clean &&
49 test_cmp expected actual.clean
50 "
51}
52
53test_atom head refname refs/heads/master
54test_atom head refname: refs/heads/master
55test_atom head refname:short master
56test_atom head refname:lstrip=1 heads/master
57test_atom head refname:lstrip=2 master
58test_atom head refname:lstrip=-1 master
59test_atom head refname:lstrip=-2 heads/master
60test_atom head refname:rstrip=1 refs/heads
61test_atom head refname:rstrip=2 refs
62test_atom head refname:rstrip=-1 refs
63test_atom head refname:rstrip=-2 refs/heads
64test_atom head refname:strip=1 heads/master
65test_atom head refname:strip=2 master
66test_atom head refname:strip=-1 master
67test_atom head refname:strip=-2 heads/master
68test_atom head upstream refs/remotes/origin/master
69test_atom head upstream:short origin/master
70test_atom head upstream:lstrip=2 origin/master
71test_atom head upstream:lstrip=-2 origin/master
72test_atom head upstream:rstrip=2 refs/remotes
73test_atom head upstream:rstrip=-2 refs/remotes
74test_atom head upstream:strip=2 origin/master
75test_atom head upstream:strip=-2 origin/master
76test_atom head push refs/remotes/myfork/master
77test_atom head push:short myfork/master
78test_atom head push:lstrip=1 remotes/myfork/master
79test_atom head push:lstrip=-1 master
80test_atom head push:rstrip=1 refs/remotes/myfork
81test_atom head push:rstrip=-1 refs
82test_atom head push:strip=1 remotes/myfork/master
83test_atom head push:strip=-1 master
84test_atom head objecttype commit
85test_atom head objectsize 171
86test_atom head objectname $(git rev-parse refs/heads/master)
87test_atom head objectname:short $(git rev-parse --short refs/heads/master)
88test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
89test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
90test_atom head tree $(git rev-parse refs/heads/master^{tree})
91test_atom head parent ''
92test_atom head numparent 0
93test_atom head object ''
94test_atom head type ''
95test_atom head '*objectname' ''
96test_atom head '*objecttype' ''
97test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
98test_atom head authorname 'A U Thor'
99test_atom head authoremail '<author@example.com>'
100test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
101test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
102test_atom head committername 'C O Mitter'
103test_atom head committeremail '<committer@example.com>'
104test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
105test_atom head tag ''
106test_atom head tagger ''
107test_atom head taggername ''
108test_atom head taggeremail ''
109test_atom head taggerdate ''
110test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
111test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
112test_atom head subject 'Initial'
113test_atom head contents:subject 'Initial'
114test_atom head body ''
115test_atom head contents:body ''
116test_atom head contents:signature ''
117test_atom head contents 'Initial
118'
119test_atom head HEAD '*'
120
121test_atom tag refname refs/tags/testtag
122test_atom tag refname:short testtag
123test_atom tag upstream ''
124test_atom tag push ''
125test_atom tag objecttype tag
126test_atom tag objectsize 154
127test_atom tag objectname $(git rev-parse refs/tags/testtag)
128test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
129test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
130test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
131test_atom tag tree ''
132test_atom tag parent ''
133test_atom tag numparent ''
134test_atom tag object $(git rev-parse refs/tags/testtag^0)
135test_atom tag type 'commit'
136test_atom tag '*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463'
137test_atom tag '*objecttype' 'commit'
138test_atom tag author ''
139test_atom tag authorname ''
140test_atom tag authoremail ''
141test_atom tag authordate ''
142test_atom tag committer ''
143test_atom tag committername ''
144test_atom tag committeremail ''
145test_atom tag committerdate ''
146test_atom tag tag 'testtag'
147test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
148test_atom tag taggername 'C O Mitter'
149test_atom tag taggeremail '<committer@example.com>'
150test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
151test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
152test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
153test_atom tag subject 'Tagging at 1151968727'
154test_atom tag contents:subject 'Tagging at 1151968727'
155test_atom tag body ''
156test_atom tag contents:body ''
157test_atom tag contents:signature ''
158test_atom tag contents 'Tagging at 1151968727
159'
160test_atom tag HEAD ' '
161
162test_expect_success 'Check invalid atoms names are errors' '
163 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
164'
165
166test_expect_success 'Check format specifiers are ignored in naming date atoms' '
167 git for-each-ref --format="%(authordate)" refs/heads &&
168 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
169 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
170 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
171'
172
173test_expect_success 'Check valid format specifiers for date fields' '
174 git for-each-ref --format="%(authordate:default)" refs/heads &&
175 git for-each-ref --format="%(authordate:relative)" refs/heads &&
176 git for-each-ref --format="%(authordate:short)" refs/heads &&
177 git for-each-ref --format="%(authordate:local)" refs/heads &&
178 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
179 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
180'
181
182test_expect_success 'Check invalid format specifiers are errors' '
183 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
184'
185
186test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
187 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
188 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
189 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
190'
191
192test_date () {
193 f=$1 &&
194 committer_date=$2 &&
195 author_date=$3 &&
196 tagger_date=$4 &&
197 cat >expected <<-EOF &&
198 'refs/heads/master' '$committer_date' '$author_date'
199 'refs/tags/testtag' '$tagger_date'
200 EOF
201 (
202 git for-each-ref --shell \
203 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
204 refs/heads &&
205 git for-each-ref --shell \
206 --format="%(refname) %(taggerdate${f:+:$f})" \
207 refs/tags
208 ) >actual &&
209 test_cmp expected actual
210}
211
212test_expect_success 'Check unformatted date fields output' '
213 test_date "" \
214 "Tue Jul 4 01:18:43 2006 +0200" \
215 "Tue Jul 4 01:18:44 2006 +0200" \
216 "Tue Jul 4 01:18:45 2006 +0200"
217'
218
219test_expect_success 'Check format "default" formatted date fields output' '
220 test_date default \
221 "Tue Jul 4 01:18:43 2006 +0200" \
222 "Tue Jul 4 01:18:44 2006 +0200" \
223 "Tue Jul 4 01:18:45 2006 +0200"
224'
225
226test_expect_success 'Check format "default-local" date fields output' '
227 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"
228'
229
230# Don't know how to do relative check because I can't know when this script
231# is going to be run and can't fake the current time to git, and hence can't
232# provide expected output. Instead, I'll just make sure that "relative"
233# doesn't exit in error
234test_expect_success 'Check format "relative" date fields output' '
235 f=relative &&
236 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
237 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
238'
239
240# We just check that this is the same as "relative" for now.
241test_expect_success 'Check format "relative-local" date fields output' '
242 test_date relative-local \
243 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
244 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
245 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
246'
247
248test_expect_success 'Check format "short" date fields output' '
249 test_date short 2006-07-04 2006-07-04 2006-07-04
250'
251
252test_expect_success 'Check format "short-local" date fields output' '
253 test_date short-local 2006-07-03 2006-07-03 2006-07-03
254'
255
256test_expect_success 'Check format "local" date fields output' '
257 test_date local \
258 "Mon Jul 3 23:18:43 2006" \
259 "Mon Jul 3 23:18:44 2006" \
260 "Mon Jul 3 23:18:45 2006"
261'
262
263test_expect_success 'Check format "iso8601" date fields output' '
264 test_date iso8601 \
265 "2006-07-04 01:18:43 +0200" \
266 "2006-07-04 01:18:44 +0200" \
267 "2006-07-04 01:18:45 +0200"
268'
269
270test_expect_success 'Check format "iso8601-local" date fields output' '
271 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"
272'
273
274test_expect_success 'Check format "rfc2822" date fields output' '
275 test_date rfc2822 \
276 "Tue, 4 Jul 2006 01:18:43 +0200" \
277 "Tue, 4 Jul 2006 01:18:44 +0200" \
278 "Tue, 4 Jul 2006 01:18:45 +0200"
279'
280
281test_expect_success 'Check format "rfc2822-local" date fields output' '
282 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"
283'
284
285test_expect_success 'Check format "raw" date fields output' '
286 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
287'
288
289test_expect_success 'Check format "raw-local" date fields output' '
290 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
291'
292
293test_expect_success 'Check format of strftime date fields' '
294 echo "my date is 2006-07-04" >expected &&
295 git for-each-ref \
296 --format="%(authordate:format:my date is %Y-%m-%d)" \
297 refs/heads >actual &&
298 test_cmp expected actual
299'
300
301test_expect_success 'Check format of strftime-local date fields' '
302 echo "my date is 2006-07-03" >expected &&
303 git for-each-ref \
304 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
305 refs/heads >actual &&
306 test_cmp expected actual
307'
308
309test_expect_success 'exercise strftime with odd fields' '
310 echo >expected &&
311 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
312 test_cmp expected actual &&
313 long="long format -- $_z40$_z40$_z40$_z40$_z40$_z40$_z40" &&
314 echo $long >expected &&
315 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
316 test_cmp expected actual
317'
318
319cat >expected <<\EOF
320refs/heads/master
321refs/remotes/origin/master
322refs/tags/testtag
323EOF
324
325test_expect_success 'Verify ascending sort' '
326 git for-each-ref --format="%(refname)" --sort=refname >actual &&
327 test_cmp expected actual
328'
329
330
331cat >expected <<\EOF
332refs/tags/testtag
333refs/remotes/origin/master
334refs/heads/master
335EOF
336
337test_expect_success 'Verify descending sort' '
338 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
339 test_cmp expected actual
340'
341
342cat >expected <<\EOF
343'refs/heads/master'
344'refs/remotes/origin/master'
345'refs/tags/testtag'
346EOF
347
348test_expect_success 'Quoting style: shell' '
349 git for-each-ref --shell --format="%(refname)" >actual &&
350 test_cmp expected actual
351'
352
353test_expect_success 'Quoting style: perl' '
354 git for-each-ref --perl --format="%(refname)" >actual &&
355 test_cmp expected actual
356'
357
358test_expect_success 'Quoting style: python' '
359 git for-each-ref --python --format="%(refname)" >actual &&
360 test_cmp expected actual
361'
362
363cat >expected <<\EOF
364"refs/heads/master"
365"refs/remotes/origin/master"
366"refs/tags/testtag"
367EOF
368
369test_expect_success 'Quoting style: tcl' '
370 git for-each-ref --tcl --format="%(refname)" >actual &&
371 test_cmp expected actual
372'
373
374for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
375 test_expect_success "more than one quoting style: $i" "
376 git for-each-ref $i 2>&1 | (read line &&
377 case \$line in
378 \"error: more than one quoting style\"*) : happy;;
379 *) false
380 esac)
381 "
382done
383
384test_expect_success 'setup for upstream:track[short]' '
385 test_commit two
386'
387
388test_atom head upstream:track '[ahead 1]'
389test_atom head upstream:trackshort '>'
390test_atom head upstream:track,nobracket 'ahead 1'
391test_atom head upstream:nobracket,track 'ahead 1'
392test_atom head push:track '[ahead 1]'
393test_atom head push:trackshort '>'
394
395test_expect_success 'Check that :track[short] cannot be used with other atoms' '
396 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
397 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
398'
399
400test_expect_success 'Check that :track[short] works when upstream is invalid' '
401 cat >expected <<-\EOF &&
402 [gone]
403
404 EOF
405 test_when_finished "git config branch.master.merge refs/heads/master" &&
406 git config branch.master.merge refs/heads/does-not-exist &&
407 git for-each-ref \
408 --format="%(upstream:track)$LF%(upstream:trackshort)" \
409 refs/heads >actual &&
410 test_cmp expected actual
411'
412
413test_expect_success 'Check for invalid refname format' '
414 test_must_fail git for-each-ref --format="%(refname:INVALID)"
415'
416
417test_expect_success 'set up color tests' '
418 cat >expected.color <<-EOF &&
419 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
420 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
421 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
422 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
423 EOF
424 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
425 color_format="%(objectname:short) %(color:green)%(refname:short)"
426'
427
428test_expect_success TTY '%(color) shows color with a tty' '
429 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
430 test_decode_color <actual.raw >actual &&
431 test_cmp expected.color actual
432'
433
434test_expect_success '%(color) does not show color without tty' '
435 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
436 test_cmp expected.bare actual
437'
438
439test_expect_success '--color can override tty check' '
440 git for-each-ref --color --format="$color_format" >actual.raw &&
441 test_decode_color <actual.raw >actual &&
442 test_cmp expected.color actual
443'
444
445cat >expected <<\EOF
446heads/master
447tags/master
448EOF
449
450test_expect_success 'Check ambiguous head and tag refs (strict)' '
451 git config --bool core.warnambiguousrefs true &&
452 git checkout -b newtag &&
453 echo "Using $datestamp" > one &&
454 git add one &&
455 git commit -m "Branch" &&
456 setdate_and_increment &&
457 git tag -m "Tagging at $datestamp" master &&
458 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
459 test_cmp expected actual
460'
461
462cat >expected <<\EOF
463heads/master
464master
465EOF
466
467test_expect_success 'Check ambiguous head and tag refs (loose)' '
468 git config --bool core.warnambiguousrefs false &&
469 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
470 test_cmp expected actual
471'
472
473cat >expected <<\EOF
474heads/ambiguous
475ambiguous
476EOF
477
478test_expect_success 'Check ambiguous head and tag refs II (loose)' '
479 git checkout master &&
480 git tag ambiguous testtag^0 &&
481 git branch ambiguous testtag^0 &&
482 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
483 test_cmp expected actual
484'
485
486test_expect_success 'an unusual tag with an incomplete line' '
487
488 git tag -m "bogo" bogo &&
489 bogo=$(git cat-file tag bogo) &&
490 bogo=$(printf "%s" "$bogo" | git mktag) &&
491 git tag -f bogo "$bogo" &&
492 git for-each-ref --format "%(body)" refs/tags/bogo
493
494'
495
496test_expect_success 'create tag with subject and body content' '
497 cat >>msg <<-\EOF &&
498 the subject line
499
500 first body line
501 second body line
502 EOF
503 git tag -F msg subject-body
504'
505test_atom refs/tags/subject-body subject 'the subject line'
506test_atom refs/tags/subject-body body 'first body line
507second body line
508'
509test_atom refs/tags/subject-body contents 'the subject line
510
511first body line
512second body line
513'
514
515test_expect_success 'create tag with multiline subject' '
516 cat >msg <<-\EOF &&
517 first subject line
518 second subject line
519
520 first body line
521 second body line
522 EOF
523 git tag -F msg multiline
524'
525test_atom refs/tags/multiline subject 'first subject line second subject line'
526test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
527test_atom refs/tags/multiline body 'first body line
528second body line
529'
530test_atom refs/tags/multiline contents:body 'first body line
531second body line
532'
533test_atom refs/tags/multiline contents:signature ''
534test_atom refs/tags/multiline contents 'first subject line
535second subject line
536
537first body line
538second body line
539'
540
541test_expect_success GPG 'create signed tags' '
542 git tag -s -m "" signed-empty &&
543 git tag -s -m "subject line" signed-short &&
544 cat >msg <<-\EOF &&
545 subject line
546
547 body contents
548 EOF
549 git tag -s -F msg signed-long
550'
551
552sig='-----BEGIN PGP SIGNATURE-----
553-----END PGP SIGNATURE-----
554'
555
556PREREQ=GPG
557test_atom refs/tags/signed-empty subject ''
558test_atom refs/tags/signed-empty contents:subject ''
559test_atom refs/tags/signed-empty body "$sig"
560test_atom refs/tags/signed-empty contents:body ''
561test_atom refs/tags/signed-empty contents:signature "$sig"
562test_atom refs/tags/signed-empty contents "$sig"
563
564test_atom refs/tags/signed-short subject 'subject line'
565test_atom refs/tags/signed-short contents:subject 'subject line'
566test_atom refs/tags/signed-short body "$sig"
567test_atom refs/tags/signed-short contents:body ''
568test_atom refs/tags/signed-short contents:signature "$sig"
569test_atom refs/tags/signed-short contents "subject line
570$sig"
571
572test_atom refs/tags/signed-long subject 'subject line'
573test_atom refs/tags/signed-long contents:subject 'subject line'
574test_atom refs/tags/signed-long body "body contents
575$sig"
576test_atom refs/tags/signed-long contents:body 'body contents
577'
578test_atom refs/tags/signed-long contents:signature "$sig"
579test_atom refs/tags/signed-long contents "subject line
580
581body contents
582$sig"
583
584cat >expected <<EOF
585$(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
586$(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
587EOF
588
589test_expect_success 'Verify sort with multiple keys' '
590 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
591 refs/tags/bogo refs/tags/master > actual &&
592 test_cmp expected actual
593'
594
595
596test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
597 test_when_finished "git checkout master" &&
598 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
599 sed -e "s/^\* / /" actual >expect &&
600 git checkout --orphan orphaned-branch &&
601 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
602 test_cmp expect actual
603'
604
605cat >trailers <<EOF
606Reviewed-by: A U Thor <author@example.com>
607Signed-off-by: A U Thor <author@example.com>
608[ v2 updated patch description ]
609Acked-by: A U Thor
610 <author@example.com>
611EOF
612
613unfold () {
614 perl -0pe 's/\n\s+/ /g'
615}
616
617test_expect_success 'set up trailers for next test' '
618 echo "Some contents" > two &&
619 git add two &&
620 git commit -F - <<-EOF
621 trailers: this commit message has trailers
622
623 Some message contents
624
625 $(cat trailers)
626 EOF
627'
628
629test_expect_success '%(trailers:unfold) unfolds trailers' '
630 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
631 {
632 unfold <trailers
633 echo
634 } >expect &&
635 test_cmp expect actual
636'
637
638test_expect_success '%(trailers:only) shows only "key: value" trailers' '
639 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
640 {
641 grep -v patch.description <trailers &&
642 echo
643 } >expect &&
644 test_cmp expect actual
645'
646
647test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
648 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
649 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
650 test_cmp actual reverse &&
651 {
652 grep -v patch.description <trailers | unfold &&
653 echo
654 } >expect &&
655 test_cmp expect actual
656'
657
658test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
659 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
660 {
661 unfold <trailers
662 echo
663 } >expect &&
664 test_cmp expect actual
665'
666
667test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
668 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
669 {
670 grep -v patch.description <trailers &&
671 echo
672 } >expect &&
673 test_cmp expect actual
674'
675
676test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
677 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
678 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
679 test_cmp actual reverse &&
680 {
681 grep -v patch.description <trailers | unfold &&
682 echo
683 } >expect &&
684 test_cmp expect actual
685'
686
687test_expect_success '%(trailers) rejects unknown trailers arguments' '
688 # error message cannot be checked under i18n
689 cat >expect <<-EOF &&
690 fatal: unknown %(trailers) argument: unsupported
691 EOF
692 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
693 test_i18ncmp expect actual
694'
695
696test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
697 # error message cannot be checked under i18n
698 cat >expect <<-EOF &&
699 fatal: unknown %(trailers) argument: unsupported
700 EOF
701 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
702 test_i18ncmp expect actual
703'
704
705test_expect_success 'basic atom: head contents:trailers' '
706 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
707 sanitize_pgp <actual >actual.clean &&
708 # git for-each-ref ends with a blank line
709 cat >expect <<-EOF &&
710 $(cat trailers)
711
712 EOF
713 test_cmp expect actual.clean
714'
715
716test_expect_success 'Add symbolic ref for the following tests' '
717 git symbolic-ref refs/heads/sym refs/heads/master
718'
719
720cat >expected <<EOF
721refs/heads/master
722EOF
723
724test_expect_success 'Verify usage of %(symref) atom' '
725 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
726 test_cmp expected actual
727'
728
729cat >expected <<EOF
730heads/master
731EOF
732
733test_expect_success 'Verify usage of %(symref:short) atom' '
734 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
735 test_cmp expected actual
736'
737
738cat >expected <<EOF
739master
740heads/master
741EOF
742
743test_expect_success 'Verify usage of %(symref:lstrip) atom' '
744 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
745 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
746 test_cmp expected actual &&
747
748 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
749 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
750 test_cmp expected actual
751'
752
753cat >expected <<EOF
754refs
755refs/heads
756EOF
757
758test_expect_success 'Verify usage of %(symref:rstrip) atom' '
759 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
760 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
761 test_cmp expected actual
762'
763
764test_done