]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6300-for-each-ref.sh
Merge branch 'dd/mailinfo-with-nul'
[thirdparty/git.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 . "$TEST_DIRECTORY"/lib-terminal.sh
11
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
20 }
21
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
40 '
41
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
54 "
55 }
56
57 hexlen=$(test_oid hexsz)
58 disklen=$(test_oid disklen)
59
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
127 '
128 test_atom head HEAD '*'
129
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
172 '
173 test_atom tag HEAD ' '
174
175 test_expect_success 'Check invalid atoms names are errors' '
176 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
177 '
178
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
184 '
185
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
193 '
194
195 test_expect_success 'Check invalid format specifiers are errors' '
196 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
197 '
198
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)"
203 '
204
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'
213 EOF
214 (
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
223 }
224
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"
230 '
231
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"
237 '
238
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"
241 '
242
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
251 '
252
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)"
259 '
260
261 test_expect_success 'Check format "short" date fields output' '
262 test_date short 2006-07-04 2006-07-04 2006-07-04
263 '
264
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
267 '
268
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"
274 '
275
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"
281 '
282
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"
285 '
286
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"
292 '
293
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"
296 '
297
298 test_expect_success 'Check format "raw" date fields output' '
299 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
300 '
301
302 test_expect_success 'Check format "raw-local" date fields output' '
303 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
304 '
305
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
312 '
313
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
320 '
321
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
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 'Verify ascending sort' '
339 git for-each-ref --format="%(refname)" --sort=refname >actual &&
340 test_cmp expected actual
341 '
342
343
344 cat >expected <<\EOF
345 refs/tags/testtag
346 refs/remotes/origin/master
347 refs/heads/master
348 EOF
349
350 test_expect_success 'Verify descending sort' '
351 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
352 test_cmp expected actual
353 '
354
355 cat >expected <<\EOF
356 refs/tags/testtag
357 refs/tags/testtag-2
358 EOF
359
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
366 '
367
368 cat >expected <<\EOF
369 refs/tags/testtag
370 refs/tags/testtag-2
371 EOF
372
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
379 '
380
381 cat >expected <<\EOF
382 'refs/heads/master'
383 'refs/remotes/origin/master'
384 'refs/tags/testtag'
385 EOF
386
387 test_expect_success 'Quoting style: shell' '
388 git for-each-ref --shell --format="%(refname)" >actual &&
389 test_cmp expected actual
390 '
391
392 test_expect_success 'Quoting style: perl' '
393 git for-each-ref --perl --format="%(refname)" >actual &&
394 test_cmp expected actual
395 '
396
397 test_expect_success 'Quoting style: python' '
398 git for-each-ref --python --format="%(refname)" >actual &&
399 test_cmp expected actual
400 '
401
402 cat >expected <<\EOF
403 "refs/heads/master"
404 "refs/remotes/origin/master"
405 "refs/tags/testtag"
406 EOF
407
408 test_expect_success 'Quoting style: tcl' '
409 git for-each-ref --tcl --format="%(refname)" >actual &&
410 test_cmp expected actual
411 '
412
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
417 "
418 done
419
420 test_expect_success 'setup for upstream:track[short]' '
421 test_commit two
422 '
423
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'
428
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
433 '
434
435 test_atom head push:track '[behind 1]'
436 test_atom head push:trackshort '<'
437
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
441 '
442
443 test_expect_success 'Check that :track[short] works when upstream is invalid' '
444 cat >expected <<-\EOF &&
445 [gone]
446
447 EOF
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
454 '
455
456 test_expect_success 'Check for invalid refname format' '
457 test_must_fail git for-each-ref --format="%(refname:INVALID)"
458 '
459
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>
468 EOF
469 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
470 color_format="%(objectname:short) %(color:green)%(refname:short)"
471 '
472
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
477 '
478
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
482 '
483
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
488 '
489
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
493 '
494
495 cat >expected <<\EOF
496 heads/master
497 tags/master
498 EOF
499
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
510 '
511
512 cat >expected <<\EOF
513 heads/master
514 master
515 EOF
516
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
521 '
522
523 cat >expected <<\EOF
524 heads/ambiguous
525 ambiguous
526 EOF
527
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
534 '
535
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)
541 '
542
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'
554
555 test_expect_success 'an unusual tag with an incomplete line' '
556
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
562
563 '
564
565 test_expect_success 'create tag with subject and body content' '
566 cat >>msg <<-\EOF &&
567 the subject line
568
569 first body line
570 second body line
571 EOF
572 git tag -F msg subject-body
573 '
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
577 '
578 test_atom refs/tags/subject-body contents 'the subject line
579
580 first body line
581 second body line
582 '
583
584 test_expect_success 'create tag with multiline subject' '
585 cat >msg <<-\EOF &&
586 first subject line
587 second subject line
588
589 first body line
590 second body line
591 EOF
592 git tag -F msg multiline
593 '
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
598 '
599 test_atom refs/tags/multiline contents:body 'first body line
600 second body line
601 '
602 test_atom refs/tags/multiline contents:signature ''
603 test_atom refs/tags/multiline contents 'first subject line
604 second subject line
605
606 first body line
607 second body line
608 '
609
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
615
616 body contents
617 EOF
618 git tag -s -F msg signed-long
619 '
620
621 sig='-----BEGIN PGP SIGNATURE-----
622 -----END PGP SIGNATURE-----
623 '
624
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"
632
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"
640
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
646 '
647 test_atom refs/tags/signed-long contents:signature "$sig"
648 test_atom refs/tags/signed-long contents "subject line
649
650 body contents
651 $sig"
652
653 sort >expected <<EOF
654 $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
655 $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
656 EOF
657
658 test_expect_success 'Verify sort with multiple keys' '
659 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
660 refs/tags/bogo refs/tags/master > actual &&
661 test_cmp expected actual
662 '
663
664
665 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
666 test_when_finished "git checkout master" &&
667 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
668 sed -e "s/^\* / /" actual >expect &&
669 git checkout --orphan orphaned-branch &&
670 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
671 test_cmp expect actual
672 '
673
674 cat >trailers <<EOF
675 Reviewed-by: A U Thor <author@example.com>
676 Signed-off-by: A U Thor <author@example.com>
677 [ v2 updated patch description ]
678 Acked-by: A U Thor
679 <author@example.com>
680 EOF
681
682 unfold () {
683 perl -0pe 's/\n\s+/ /g'
684 }
685
686 test_expect_success 'set up trailers for next test' '
687 echo "Some contents" > two &&
688 git add two &&
689 git commit -F - <<-EOF
690 trailers: this commit message has trailers
691
692 Some message contents
693
694 $(cat trailers)
695 EOF
696 '
697
698 test_expect_success '%(trailers:unfold) unfolds trailers' '
699 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
700 {
701 unfold <trailers
702 echo
703 } >expect &&
704 test_cmp expect actual
705 '
706
707 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
708 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
709 {
710 grep -v patch.description <trailers &&
711 echo
712 } >expect &&
713 test_cmp expect actual
714 '
715
716 test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
717 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
718 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
719 test_cmp actual reverse &&
720 {
721 grep -v patch.description <trailers | unfold &&
722 echo
723 } >expect &&
724 test_cmp expect actual
725 '
726
727 test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
728 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
729 {
730 unfold <trailers
731 echo
732 } >expect &&
733 test_cmp expect actual
734 '
735
736 test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
737 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
738 {
739 grep -v patch.description <trailers &&
740 echo
741 } >expect &&
742 test_cmp expect actual
743 '
744
745 test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
746 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
747 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
748 test_cmp actual reverse &&
749 {
750 grep -v patch.description <trailers | unfold &&
751 echo
752 } >expect &&
753 test_cmp expect actual
754 '
755
756 test_expect_success '%(trailers) rejects unknown trailers arguments' '
757 # error message cannot be checked under i18n
758 cat >expect <<-EOF &&
759 fatal: unknown %(trailers) argument: unsupported
760 EOF
761 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
762 test_i18ncmp expect actual
763 '
764
765 test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
766 # error message cannot be checked under i18n
767 cat >expect <<-EOF &&
768 fatal: unknown %(trailers) argument: unsupported
769 EOF
770 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
771 test_i18ncmp expect actual
772 '
773
774 test_expect_success 'basic atom: head contents:trailers' '
775 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
776 sanitize_pgp <actual >actual.clean &&
777 # git for-each-ref ends with a blank line
778 cat >expect <<-EOF &&
779 $(cat trailers)
780
781 EOF
782 test_cmp expect actual.clean
783 '
784
785 test_expect_success 'trailer parsing not fooled by --- line' '
786 git commit --allow-empty -F - <<-\EOF &&
787 this is the subject
788
789 This is the body. The message has a "---" line which would confuse a
790 message+patch parser. But here we know we have only a commit message,
791 so we get it right.
792
793 trailer: wrong
794 ---
795 This is more body.
796
797 trailer: right
798 EOF
799
800 {
801 echo "trailer: right" &&
802 echo
803 } >expect &&
804 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
805 test_cmp expect actual
806 '
807
808 test_expect_success 'Add symbolic ref for the following tests' '
809 git symbolic-ref refs/heads/sym refs/heads/master
810 '
811
812 cat >expected <<EOF
813 refs/heads/master
814 EOF
815
816 test_expect_success 'Verify usage of %(symref) atom' '
817 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
818 test_cmp expected actual
819 '
820
821 cat >expected <<EOF
822 heads/master
823 EOF
824
825 test_expect_success 'Verify usage of %(symref:short) atom' '
826 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
827 test_cmp expected actual
828 '
829
830 cat >expected <<EOF
831 master
832 heads/master
833 EOF
834
835 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
836 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
837 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
838 test_cmp expected actual &&
839
840 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
841 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
842 test_cmp expected actual
843 '
844
845 cat >expected <<EOF
846 refs
847 refs/heads
848 EOF
849
850 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
851 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
852 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
853 test_cmp expected actual
854 '
855
856 test_expect_success ':remotename and :remoteref' '
857 git init remote-tests &&
858 (
859 cd remote-tests &&
860 test_commit initial &&
861 git remote add from fifth.coffee:blub &&
862 git config branch.master.remote from &&
863 git config branch.master.merge refs/heads/stable &&
864 git remote add to southridge.audio:repo &&
865 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
866 git config branch.master.pushRemote to &&
867 for pair in "%(upstream)=refs/remotes/from/stable" \
868 "%(upstream:remotename)=from" \
869 "%(upstream:remoteref)=refs/heads/stable" \
870 "%(push)=refs/remotes/to/pushed/master" \
871 "%(push:remotename)=to" \
872 "%(push:remoteref)=refs/heads/pushed/master"
873 do
874 echo "${pair#*=}" >expect &&
875 git for-each-ref --format="${pair%=*}" \
876 refs/heads/master >actual &&
877 test_cmp expect actual
878 done &&
879 git branch push-simple &&
880 git config branch.push-simple.pushRemote from &&
881 actual="$(git for-each-ref \
882 --format="%(push:remotename),%(push:remoteref)" \
883 refs/heads/push-simple)" &&
884 test from, = "$actual"
885 )
886 '
887
888 test_expect_success 'for-each-ref --ignore-case ignores case' '
889 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
890 test_must_be_empty actual &&
891
892 echo refs/heads/master >expect &&
893 git for-each-ref --format="%(refname)" --ignore-case \
894 refs/heads/MASTER >actual &&
895 test_cmp expect actual
896 '
897
898 test_done