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