]> git.ipfire.org Git - thirdparty/git.git/blob - t/t6300-for-each-ref.sh
Merge branch 'mp/rebase-label-length-limit' into maint-2.42
[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 GNUPGHOME_NOT_USED=$GNUPGHOME
10 . "$TEST_DIRECTORY"/lib-gpg.sh
11 . "$TEST_DIRECTORY"/lib-terminal.sh
12
13 # Mon Jul 3 23:18:43 2006 +0000
14 datestamp=1151968723
15 setdate_and_increment () {
16 GIT_COMMITTER_DATE="$datestamp +0200"
17 datestamp=$(expr "$datestamp" + 1)
18 GIT_AUTHOR_DATE="$datestamp +0200"
19 datestamp=$(expr "$datestamp" + 1)
20 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
21 }
22
23 test_expect_success setup '
24 test_oid_cache <<-EOF &&
25 disklen sha1:138
26 disklen sha256:154
27 EOF
28 setdate_and_increment &&
29 echo "Using $datestamp" > one &&
30 git add one &&
31 git commit -m "Initial" &&
32 git branch -M main &&
33 setdate_and_increment &&
34 git tag -a -m "Tagging at $datestamp" testtag &&
35 git update-ref refs/remotes/origin/main main &&
36 git remote add origin nowhere &&
37 git config branch.main.remote origin &&
38 git config branch.main.merge refs/heads/main &&
39 git remote add myfork elsewhere &&
40 git config remote.pushdefault myfork &&
41 git config push.default current
42 '
43
44 test_atom() {
45 case "$1" in
46 head) ref=refs/heads/main ;;
47 tag) ref=refs/tags/testtag ;;
48 sym) ref=refs/heads/sym ;;
49 *) ref=$1 ;;
50 esac
51 printf '%s\n' "$3" >expected
52 test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
53 git for-each-ref --format='%($2)' $ref >actual &&
54 sanitize_pgp <actual >actual.clean &&
55 test_cmp expected actual.clean
56 "
57 # Automatically test "contents:size" atom after testing "contents"
58 if test "$2" = "contents"
59 then
60 # for commit leg, $3 is changed there
61 expect=$(printf '%s' "$3" | wc -c)
62 test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" '
63 type=$(git cat-file -t "$ref") &&
64 case $type in
65 tag)
66 # We cannot use $3 as it expects sanitize_pgp to run
67 git cat-file tag $ref >out &&
68 expect=$(tail -n +6 out | wc -c) &&
69 rm -f out ;;
70 tree | blob)
71 expect="" ;;
72 commit)
73 : "use the calculated expect" ;;
74 *)
75 BUG "unknown object type" ;;
76 esac &&
77 # Leave $expect unquoted to lose possible leading whitespaces
78 echo $expect >expected &&
79 git for-each-ref --format="%(contents:size)" "$ref" >actual &&
80 test_cmp expected actual
81 '
82 fi
83 }
84
85 hexlen=$(test_oid hexsz)
86 disklen=$(test_oid disklen)
87
88 test_atom head refname refs/heads/main
89 test_atom head refname: refs/heads/main
90 test_atom head refname:short main
91 test_atom head refname:lstrip=1 heads/main
92 test_atom head refname:lstrip=2 main
93 test_atom head refname:lstrip=-1 main
94 test_atom head refname:lstrip=-2 heads/main
95 test_atom head refname:rstrip=1 refs/heads
96 test_atom head refname:rstrip=2 refs
97 test_atom head refname:rstrip=-1 refs
98 test_atom head refname:rstrip=-2 refs/heads
99 test_atom head refname:strip=1 heads/main
100 test_atom head refname:strip=2 main
101 test_atom head refname:strip=-1 main
102 test_atom head refname:strip=-2 heads/main
103 test_atom head upstream refs/remotes/origin/main
104 test_atom head upstream:short origin/main
105 test_atom head upstream:lstrip=2 origin/main
106 test_atom head upstream:lstrip=-2 origin/main
107 test_atom head upstream:rstrip=2 refs/remotes
108 test_atom head upstream:rstrip=-2 refs/remotes
109 test_atom head upstream:strip=2 origin/main
110 test_atom head upstream:strip=-2 origin/main
111 test_atom head push refs/remotes/myfork/main
112 test_atom head push:short myfork/main
113 test_atom head push:lstrip=1 remotes/myfork/main
114 test_atom head push:lstrip=-1 main
115 test_atom head push:rstrip=1 refs/remotes/myfork
116 test_atom head push:rstrip=-1 refs
117 test_atom head push:strip=1 remotes/myfork/main
118 test_atom head push:strip=-1 main
119 test_atom head objecttype commit
120 test_atom head objectsize $((131 + hexlen))
121 test_atom head objectsize:disk $disklen
122 test_atom head deltabase $ZERO_OID
123 test_atom head objectname $(git rev-parse refs/heads/main)
124 test_atom head objectname:short $(git rev-parse --short refs/heads/main)
125 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
126 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
127 test_atom head tree $(git rev-parse refs/heads/main^{tree})
128 test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree})
129 test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree})
130 test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree})
131 test_atom head parent ''
132 test_atom head parent:short ''
133 test_atom head parent:short=1 ''
134 test_atom head parent:short=10 ''
135 test_atom head numparent 0
136 test_atom head object ''
137 test_atom head type ''
138 test_atom head raw "$(git cat-file commit refs/heads/main)
139 "
140 test_atom head '*objectname' ''
141 test_atom head '*objecttype' ''
142 test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
143 test_atom head authorname 'A U Thor'
144 test_atom head authoremail '<author@example.com>'
145 test_atom head authoremail:trim 'author@example.com'
146 test_atom head authoremail:localpart 'author'
147 test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
148 test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
149 test_atom head committername 'C O Mitter'
150 test_atom head committeremail '<committer@example.com>'
151 test_atom head committeremail:trim 'committer@example.com'
152 test_atom head committeremail:localpart 'committer'
153 test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
154 test_atom head tag ''
155 test_atom head tagger ''
156 test_atom head taggername ''
157 test_atom head taggeremail ''
158 test_atom head taggeremail:trim ''
159 test_atom head taggeremail:localpart ''
160 test_atom head taggerdate ''
161 test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
162 test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
163 test_atom head subject 'Initial'
164 test_atom head subject:sanitize 'Initial'
165 test_atom head contents:subject 'Initial'
166 test_atom head body ''
167 test_atom head contents:body ''
168 test_atom head contents:signature ''
169 test_atom head contents 'Initial
170 '
171 test_atom head HEAD '*'
172
173 test_atom tag refname refs/tags/testtag
174 test_atom tag refname:short testtag
175 test_atom tag upstream ''
176 test_atom tag push ''
177 test_atom tag objecttype tag
178 test_atom tag objectsize $((114 + hexlen))
179 test_atom tag objectsize:disk $disklen
180 test_atom tag '*objectsize:disk' $disklen
181 test_atom tag deltabase $ZERO_OID
182 test_atom tag '*deltabase' $ZERO_OID
183 test_atom tag objectname $(git rev-parse refs/tags/testtag)
184 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
185 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main)
186 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main)
187 test_atom tag tree ''
188 test_atom tag tree:short ''
189 test_atom tag tree:short=1 ''
190 test_atom tag tree:short=10 ''
191 test_atom tag parent ''
192 test_atom tag parent:short ''
193 test_atom tag parent:short=1 ''
194 test_atom tag parent:short=10 ''
195 test_atom tag numparent ''
196 test_atom tag object $(git rev-parse refs/tags/testtag^0)
197 test_atom tag type 'commit'
198 test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
199 test_atom tag '*objecttype' 'commit'
200 test_atom tag author ''
201 test_atom tag authorname ''
202 test_atom tag authoremail ''
203 test_atom tag authoremail:trim ''
204 test_atom tag authoremail:localpart ''
205 test_atom tag authordate ''
206 test_atom tag committer ''
207 test_atom tag committername ''
208 test_atom tag committeremail ''
209 test_atom tag committeremail:trim ''
210 test_atom tag committeremail:localpart ''
211 test_atom tag committerdate ''
212 test_atom tag tag 'testtag'
213 test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
214 test_atom tag taggername 'C O Mitter'
215 test_atom tag taggeremail '<committer@example.com>'
216 test_atom tag taggeremail:trim 'committer@example.com'
217 test_atom tag taggeremail:localpart 'committer'
218 test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
219 test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
220 test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
221 test_atom tag subject 'Tagging at 1151968727'
222 test_atom tag subject:sanitize 'Tagging-at-1151968727'
223 test_atom tag contents:subject 'Tagging at 1151968727'
224 test_atom tag body ''
225 test_atom tag contents:body ''
226 test_atom tag contents:signature ''
227 test_atom tag contents 'Tagging at 1151968727
228 '
229 test_atom tag HEAD ' '
230
231 test_expect_success 'basic atom: refs/tags/testtag *raw' '
232 git cat-file commit refs/tags/testtag^{} >expected &&
233 git for-each-ref --format="%(*raw)" refs/tags/testtag >actual &&
234 sanitize_pgp <expected >expected.clean &&
235 echo >>expected.clean &&
236 sanitize_pgp <actual >actual.clean &&
237 test_cmp expected.clean actual.clean
238 '
239
240 test_expect_success 'Check invalid atoms names are errors' '
241 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
242 '
243
244 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
245 git for-each-ref --format="%(authordate)" refs/heads &&
246 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
247 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
248 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
249 '
250
251 test_expect_success 'Check valid format specifiers for date fields' '
252 git for-each-ref --format="%(authordate:default)" refs/heads &&
253 git for-each-ref --format="%(authordate:relative)" refs/heads &&
254 git for-each-ref --format="%(authordate:short)" refs/heads &&
255 git for-each-ref --format="%(authordate:local)" refs/heads &&
256 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
257 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
258 '
259
260 test_expect_success 'Check invalid format specifiers are errors' '
261 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
262 '
263
264 test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
265 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
266 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
267 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
268 '
269
270 test_date () {
271 f=$1 &&
272 committer_date=$2 &&
273 author_date=$3 &&
274 tagger_date=$4 &&
275 cat >expected <<-EOF &&
276 'refs/heads/main' '$committer_date' '$author_date'
277 'refs/tags/testtag' '$tagger_date'
278 EOF
279 (
280 git for-each-ref --shell \
281 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
282 refs/heads &&
283 git for-each-ref --shell \
284 --format="%(refname) %(taggerdate${f:+:$f})" \
285 refs/tags
286 ) >actual &&
287 test_cmp expected actual
288 }
289
290 test_expect_success 'Check unformatted date fields output' '
291 test_date "" \
292 "Tue Jul 4 01:18:43 2006 +0200" \
293 "Tue Jul 4 01:18:44 2006 +0200" \
294 "Tue Jul 4 01:18:45 2006 +0200"
295 '
296
297 test_expect_success 'Check format "default" formatted date fields output' '
298 test_date default \
299 "Tue Jul 4 01:18:43 2006 +0200" \
300 "Tue Jul 4 01:18:44 2006 +0200" \
301 "Tue Jul 4 01:18:45 2006 +0200"
302 '
303
304 test_expect_success 'Check format "default-local" date fields output' '
305 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"
306 '
307
308 # Don't know how to do relative check because I can't know when this script
309 # is going to be run and can't fake the current time to git, and hence can't
310 # provide expected output. Instead, I'll just make sure that "relative"
311 # doesn't exit in error
312 test_expect_success 'Check format "relative" date fields output' '
313 f=relative &&
314 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
315 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
316 '
317
318 # We just check that this is the same as "relative" for now.
319 test_expect_success 'Check format "relative-local" date fields output' '
320 test_date relative-local \
321 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
322 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
323 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
324 '
325
326 test_expect_success 'Check format "short" date fields output' '
327 test_date short 2006-07-04 2006-07-04 2006-07-04
328 '
329
330 test_expect_success 'Check format "short-local" date fields output' '
331 test_date short-local 2006-07-03 2006-07-03 2006-07-03
332 '
333
334 test_expect_success 'Check format "local" date fields output' '
335 test_date local \
336 "Mon Jul 3 23:18:43 2006" \
337 "Mon Jul 3 23:18:44 2006" \
338 "Mon Jul 3 23:18:45 2006"
339 '
340
341 test_expect_success 'Check format "iso8601" date fields output' '
342 test_date iso8601 \
343 "2006-07-04 01:18:43 +0200" \
344 "2006-07-04 01:18:44 +0200" \
345 "2006-07-04 01:18:45 +0200"
346 '
347
348 test_expect_success 'Check format "iso8601-local" date fields output' '
349 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"
350 '
351
352 test_expect_success 'Check format "rfc2822" date fields output' '
353 test_date rfc2822 \
354 "Tue, 4 Jul 2006 01:18:43 +0200" \
355 "Tue, 4 Jul 2006 01:18:44 +0200" \
356 "Tue, 4 Jul 2006 01:18:45 +0200"
357 '
358
359 test_expect_success 'Check format "rfc2822-local" date fields output' '
360 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"
361 '
362
363 test_expect_success 'Check format "raw" date fields output' '
364 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
365 '
366
367 test_expect_success 'Check format "raw-local" date fields output' '
368 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
369 '
370
371 test_expect_success 'Check format of strftime date fields' '
372 echo "my date is 2006-07-04" >expected &&
373 git for-each-ref \
374 --format="%(authordate:format:my date is %Y-%m-%d)" \
375 refs/heads >actual &&
376 test_cmp expected actual
377 '
378
379 test_expect_success 'Check format of strftime-local date fields' '
380 echo "my date is 2006-07-03" >expected &&
381 git for-each-ref \
382 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
383 refs/heads >actual &&
384 test_cmp expected actual
385 '
386
387 test_expect_success 'exercise strftime with odd fields' '
388 echo >expected &&
389 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
390 test_cmp expected actual &&
391 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
392 echo $long >expected &&
393 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
394 test_cmp expected actual
395 '
396
397 cat >expected <<\EOF
398 refs/heads/main
399 refs/remotes/origin/main
400 refs/tags/testtag
401 EOF
402
403 test_expect_success 'Verify ascending sort' '
404 git for-each-ref --format="%(refname)" --sort=refname >actual &&
405 test_cmp expected actual
406 '
407
408
409 cat >expected <<\EOF
410 refs/tags/testtag
411 refs/remotes/origin/main
412 refs/heads/main
413 EOF
414
415 test_expect_success 'Verify descending sort' '
416 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
417 test_cmp expected actual
418 '
419
420 test_expect_success 'Give help even with invalid sort atoms' '
421 test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 &&
422 grep "^usage: git for-each-ref" actual
423 '
424
425 cat >expected <<\EOF
426 refs/tags/testtag
427 refs/tags/testtag-2
428 EOF
429
430 test_expect_success 'exercise patterns with prefixes' '
431 git tag testtag-2 &&
432 test_when_finished "git tag -d testtag-2" &&
433 git for-each-ref --format="%(refname)" \
434 refs/tags/testtag refs/tags/testtag-2 >actual &&
435 test_cmp expected actual
436 '
437
438 cat >expected <<\EOF
439 refs/tags/testtag
440 refs/tags/testtag-2
441 EOF
442
443 test_expect_success 'exercise glob patterns with prefixes' '
444 git tag testtag-2 &&
445 test_when_finished "git tag -d testtag-2" &&
446 git for-each-ref --format="%(refname)" \
447 refs/tags/testtag "refs/tags/testtag-*" >actual &&
448 test_cmp expected actual
449 '
450
451 cat >expected <<\EOF
452 refs/tags/bar
453 refs/tags/baz
454 refs/tags/testtag
455 EOF
456
457 test_expect_success 'exercise patterns with prefix exclusions' '
458 for tag in foo/one foo/two foo/three bar baz
459 do
460 git tag "$tag" || return 1
461 done &&
462 test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
463 git for-each-ref --format="%(refname)" \
464 refs/tags/ --exclude=refs/tags/foo >actual &&
465 test_cmp expected actual
466 '
467
468 cat >expected <<\EOF
469 refs/tags/bar
470 refs/tags/baz
471 refs/tags/foo/one
472 refs/tags/testtag
473 EOF
474
475 test_expect_success 'exercise patterns with pattern exclusions' '
476 for tag in foo/one foo/two foo/three bar baz
477 do
478 git tag "$tag" || return 1
479 done &&
480 test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
481 git for-each-ref --format="%(refname)" \
482 refs/tags/ --exclude="refs/tags/foo/t*" >actual &&
483 test_cmp expected actual
484 '
485
486 cat >expected <<\EOF
487 'refs/heads/main'
488 'refs/remotes/origin/main'
489 'refs/tags/testtag'
490 EOF
491
492 test_expect_success 'Quoting style: shell' '
493 git for-each-ref --shell --format="%(refname)" >actual &&
494 test_cmp expected actual
495 '
496
497 test_expect_success 'Quoting style: perl' '
498 git for-each-ref --perl --format="%(refname)" >actual &&
499 test_cmp expected actual
500 '
501
502 test_expect_success 'Quoting style: python' '
503 git for-each-ref --python --format="%(refname)" >actual &&
504 test_cmp expected actual
505 '
506
507 cat >expected <<\EOF
508 "refs/heads/main"
509 "refs/remotes/origin/main"
510 "refs/tags/testtag"
511 EOF
512
513 test_expect_success 'Quoting style: tcl' '
514 git for-each-ref --tcl --format="%(refname)" >actual &&
515 test_cmp expected actual
516 '
517
518 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
519 test_expect_success "more than one quoting style: $i" "
520 test_must_fail git for-each-ref $i 2>err &&
521 grep '^error: more than one quoting style' err
522 "
523 done
524
525 test_expect_success 'setup for upstream:track[short]' '
526 test_commit two
527 '
528
529 test_atom head upstream:track '[ahead 1]'
530 test_atom head upstream:trackshort '>'
531 test_atom head upstream:track,nobracket 'ahead 1'
532 test_atom head upstream:nobracket,track 'ahead 1'
533
534 test_expect_success 'setup for push:track[short]' '
535 test_commit third &&
536 git update-ref refs/remotes/myfork/main main &&
537 git reset main~1
538 '
539
540 test_atom head push:track '[behind 1]'
541 test_atom head push:trackshort '<'
542
543 test_expect_success 'Check that :track[short] cannot be used with other atoms' '
544 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
545 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
546 '
547
548 test_expect_success 'Check that :track[short] works when upstream is invalid' '
549 cat >expected <<-\EOF &&
550 [gone]
551
552 EOF
553 test_when_finished "git config branch.main.merge refs/heads/main" &&
554 git config branch.main.merge refs/heads/does-not-exist &&
555 git for-each-ref \
556 --format="%(upstream:track)$LF%(upstream:trackshort)" \
557 refs/heads >actual &&
558 test_cmp expected actual
559 '
560
561 test_expect_success 'Check for invalid refname format' '
562 test_must_fail git for-each-ref --format="%(refname:INVALID)"
563 '
564
565 test_expect_success 'set up color tests' '
566 cat >expected.color <<-EOF &&
567 $(git rev-parse --short refs/heads/main) <GREEN>main<RESET>
568 $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET>
569 $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET>
570 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
571 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
572 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
573 EOF
574 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
575 color_format="%(objectname:short) %(color:green)%(refname:short)"
576 '
577
578 test_expect_success TTY '%(color) shows color with a tty' '
579 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
580 test_decode_color <actual.raw >actual &&
581 test_cmp expected.color actual
582 '
583
584 test_expect_success '%(color) does not show color without tty' '
585 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
586 test_cmp expected.bare actual
587 '
588
589 test_expect_success '--color can override tty check' '
590 git for-each-ref --color --format="$color_format" >actual.raw &&
591 test_decode_color <actual.raw >actual &&
592 test_cmp expected.color actual
593 '
594
595 test_expect_success 'color.ui=always does not override tty check' '
596 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
597 test_cmp expected.bare actual
598 '
599
600 test_expect_success 'setup for describe atom tests' '
601 git init -b master describe-repo &&
602 (
603 cd describe-repo &&
604
605 test_commit --no-tag one &&
606 git tag tagone &&
607
608 test_commit --no-tag two &&
609 git tag -a -m "tag two" tagtwo
610 )
611 '
612
613 test_expect_success 'describe atom vs git describe' '
614 (
615 cd describe-repo &&
616
617 git for-each-ref --format="%(objectname)" \
618 refs/tags/ >obj &&
619 while read hash
620 do
621 if desc=$(git describe $hash)
622 then
623 : >expect-contains-good
624 else
625 : >expect-contains-bad
626 fi &&
627 echo "$hash $desc" || return 1
628 done <obj >expect &&
629 test_path_exists expect-contains-good &&
630 test_path_exists expect-contains-bad &&
631
632 git for-each-ref --format="%(objectname) %(describe)" \
633 refs/tags/ >actual 2>err &&
634 test_cmp expect actual &&
635 test_must_be_empty err
636 )
637 '
638
639 test_expect_success 'describe:tags vs describe --tags' '
640 (
641 cd describe-repo &&
642 git describe --tags >expect &&
643 git for-each-ref --format="%(describe:tags)" \
644 refs/heads/master >actual &&
645 test_cmp expect actual
646 )
647 '
648
649 test_expect_success 'describe:abbrev=... vs describe --abbrev=...' '
650 (
651 cd describe-repo &&
652
653 # Case 1: We have commits between HEAD and the most
654 # recent tag reachable from it
655 test_commit --no-tag file &&
656 git describe --abbrev=14 >expect &&
657 git for-each-ref --format="%(describe:abbrev=14)" \
658 refs/heads/master >actual &&
659 test_cmp expect actual &&
660
661 # Make sure the hash used is atleast 14 digits long
662 sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
663 test 15 -le $(wc -c <hexpart) &&
664
665 # Case 2: We have a tag at HEAD, describe directly gives
666 # the name of the tag
667 git tag -a -m tagged tagname &&
668 git describe --abbrev=14 >expect &&
669 git for-each-ref --format="%(describe:abbrev=14)" \
670 refs/heads/master >actual &&
671 test_cmp expect actual &&
672 test tagname = $(cat actual)
673 )
674 '
675
676 test_expect_success 'describe:match=... vs describe --match ...' '
677 (
678 cd describe-repo &&
679 git tag -a -m "tag foo" tag-foo &&
680 git describe --match "*-foo" >expect &&
681 git for-each-ref --format="%(describe:match="*-foo")" \
682 refs/heads/master >actual &&
683 test_cmp expect actual
684 )
685 '
686
687 test_expect_success 'describe:exclude:... vs describe --exclude ...' '
688 (
689 cd describe-repo &&
690 git tag -a -m "tag bar" tag-bar &&
691 git describe --exclude "*-bar" >expect &&
692 git for-each-ref --format="%(describe:exclude="*-bar")" \
693 refs/heads/master >actual &&
694 test_cmp expect actual
695 )
696 '
697
698 test_expect_success 'deref with describe atom' '
699 (
700 cd describe-repo &&
701 cat >expect <<-\EOF &&
702
703 tagname
704 tagname
705 tagname
706
707 tagtwo
708 EOF
709 git for-each-ref --format="%(*describe)" >actual &&
710 test_cmp expect actual
711 )
712 '
713
714 test_expect_success 'err on bad describe atom arg' '
715 (
716 cd describe-repo &&
717
718 # The bad arg is the only arg passed to describe atom
719 cat >expect <<-\EOF &&
720 fatal: unrecognized %(describe) argument: baz
721 EOF
722 test_must_fail git for-each-ref --format="%(describe:baz)" \
723 refs/heads/master 2>actual &&
724 test_cmp expect actual &&
725
726 # The bad arg is in the middle of the option string
727 # passed to the describe atom
728 cat >expect <<-\EOF &&
729 fatal: unrecognized %(describe) argument: qux=1,abbrev=14
730 EOF
731 test_must_fail git for-each-ref \
732 --format="%(describe:tags,qux=1,abbrev=14)" \
733 ref/heads/master 2>actual &&
734 test_cmp expect actual
735 )
736 '
737
738 cat >expected <<\EOF
739 heads/main
740 tags/main
741 EOF
742
743 test_expect_success 'Check ambiguous head and tag refs (strict)' '
744 git config --bool core.warnambiguousrefs true &&
745 git checkout -b newtag &&
746 echo "Using $datestamp" > one &&
747 git add one &&
748 git commit -m "Branch" &&
749 setdate_and_increment &&
750 git tag -m "Tagging at $datestamp" main &&
751 git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
752 test_cmp expected actual
753 '
754
755 cat >expected <<\EOF
756 heads/main
757 main
758 EOF
759
760 test_expect_success 'Check ambiguous head and tag refs (loose)' '
761 git config --bool core.warnambiguousrefs false &&
762 git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
763 test_cmp expected actual
764 '
765
766 cat >expected <<\EOF
767 heads/ambiguous
768 ambiguous
769 EOF
770
771 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
772 git checkout main &&
773 git tag ambiguous testtag^0 &&
774 git branch ambiguous testtag^0 &&
775 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
776 test_cmp expected actual
777 '
778
779 test_expect_success 'create tag without tagger' '
780 git tag -a -m "Broken tag" taggerless &&
781 git tag -f taggerless $(git cat-file tag taggerless |
782 sed -e "/^tagger /d" |
783 git hash-object --literally --stdin -w -t tag)
784 '
785
786 test_atom refs/tags/taggerless type 'commit'
787 test_atom refs/tags/taggerless tag 'taggerless'
788 test_atom refs/tags/taggerless tagger ''
789 test_atom refs/tags/taggerless taggername ''
790 test_atom refs/tags/taggerless taggeremail ''
791 test_atom refs/tags/taggerless taggeremail:trim ''
792 test_atom refs/tags/taggerless taggeremail:localpart ''
793 test_atom refs/tags/taggerless taggerdate ''
794 test_atom refs/tags/taggerless committer ''
795 test_atom refs/tags/taggerless committername ''
796 test_atom refs/tags/taggerless committeremail ''
797 test_atom refs/tags/taggerless committeremail:trim ''
798 test_atom refs/tags/taggerless committeremail:localpart ''
799 test_atom refs/tags/taggerless committerdate ''
800 test_atom refs/tags/taggerless subject 'Broken tag'
801
802 test_expect_success 'an unusual tag with an incomplete line' '
803
804 git tag -m "bogo" bogo &&
805 bogo=$(git cat-file tag bogo) &&
806 bogo=$(printf "%s" "$bogo" | git mktag) &&
807 git tag -f bogo "$bogo" &&
808 git for-each-ref --format "%(body)" refs/tags/bogo
809
810 '
811
812 test_expect_success 'create tag with subject and body content' '
813 cat >>msg <<-\EOF &&
814 the subject line
815
816 first body line
817 second body line
818 EOF
819 git tag -F msg subject-body
820 '
821 test_atom refs/tags/subject-body subject 'the subject line'
822 test_atom refs/tags/subject-body subject:sanitize 'the-subject-line'
823 test_atom refs/tags/subject-body body 'first body line
824 second body line
825 '
826 test_atom refs/tags/subject-body contents 'the subject line
827
828 first body line
829 second body line
830 '
831
832 test_expect_success 'create tag with multiline subject' '
833 cat >msg <<-\EOF &&
834 first subject line
835 second subject line
836
837 first body line
838 second body line
839 EOF
840 git tag -F msg multiline
841 '
842 test_atom refs/tags/multiline subject 'first subject line second subject line'
843 test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line'
844 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
845 test_atom refs/tags/multiline body 'first body line
846 second body line
847 '
848 test_atom refs/tags/multiline contents:body 'first body line
849 second body line
850 '
851 test_atom refs/tags/multiline contents:signature ''
852 test_atom refs/tags/multiline contents 'first subject line
853 second subject line
854
855 first body line
856 second body line
857 '
858
859 test_expect_success GPG 'create signed tags' '
860 git tag -s -m "" signed-empty &&
861 git tag -s -m "subject line" signed-short &&
862 cat >msg <<-\EOF &&
863 subject line
864
865 body contents
866 EOF
867 git tag -s -F msg signed-long
868 '
869
870 sig='-----BEGIN PGP SIGNATURE-----
871 -----END PGP SIGNATURE-----
872 '
873
874 PREREQ=GPG
875 test_atom refs/tags/signed-empty subject ''
876 test_atom refs/tags/signed-empty subject:sanitize ''
877 test_atom refs/tags/signed-empty contents:subject ''
878 test_atom refs/tags/signed-empty body "$sig"
879 test_atom refs/tags/signed-empty contents:body ''
880 test_atom refs/tags/signed-empty contents:signature "$sig"
881 test_atom refs/tags/signed-empty contents "$sig"
882
883 test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' '
884 git cat-file tag refs/tags/signed-empty >expected &&
885 git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual &&
886 sanitize_pgp <expected >expected.clean &&
887 echo >>expected.clean &&
888 sanitize_pgp <actual >actual.clean &&
889 test_cmp expected.clean actual.clean
890 '
891
892 test_atom refs/tags/signed-short subject 'subject line'
893 test_atom refs/tags/signed-short subject:sanitize 'subject-line'
894 test_atom refs/tags/signed-short contents:subject 'subject line'
895 test_atom refs/tags/signed-short body "$sig"
896 test_atom refs/tags/signed-short contents:body ''
897 test_atom refs/tags/signed-short contents:signature "$sig"
898 test_atom refs/tags/signed-short contents "subject line
899 $sig"
900
901 test_expect_success GPG 'basic atom: refs/tags/signed-short raw' '
902 git cat-file tag refs/tags/signed-short >expected &&
903 git for-each-ref --format="%(raw)" refs/tags/signed-short >actual &&
904 sanitize_pgp <expected >expected.clean &&
905 echo >>expected.clean &&
906 sanitize_pgp <actual >actual.clean &&
907 test_cmp expected.clean actual.clean
908 '
909
910 test_atom refs/tags/signed-long subject 'subject line'
911 test_atom refs/tags/signed-long subject:sanitize 'subject-line'
912 test_atom refs/tags/signed-long contents:subject 'subject line'
913 test_atom refs/tags/signed-long body "body contents
914 $sig"
915 test_atom refs/tags/signed-long contents:body 'body contents
916 '
917 test_atom refs/tags/signed-long contents:signature "$sig"
918 test_atom refs/tags/signed-long contents "subject line
919
920 body contents
921 $sig"
922
923 test_expect_success GPG 'basic atom: refs/tags/signed-long raw' '
924 git cat-file tag refs/tags/signed-long >expected &&
925 git for-each-ref --format="%(raw)" refs/tags/signed-long >actual &&
926 sanitize_pgp <expected >expected.clean &&
927 echo >>expected.clean &&
928 sanitize_pgp <actual >actual.clean &&
929 test_cmp expected.clean actual.clean
930 '
931
932 test_expect_success 'set up refs pointing to tree and blob' '
933 git update-ref refs/mytrees/first refs/heads/main^{tree} &&
934 git update-ref refs/myblobs/first refs/heads/main:one
935 '
936
937 test_atom refs/mytrees/first subject ""
938 test_atom refs/mytrees/first contents:subject ""
939 test_atom refs/mytrees/first body ""
940 test_atom refs/mytrees/first contents:body ""
941 test_atom refs/mytrees/first contents:signature ""
942 test_atom refs/mytrees/first contents ""
943
944 test_expect_success 'basic atom: refs/mytrees/first raw' '
945 git cat-file tree refs/mytrees/first >expected &&
946 echo >>expected &&
947 git for-each-ref --format="%(raw)" refs/mytrees/first >actual &&
948 test_cmp expected actual &&
949 git cat-file -s refs/mytrees/first >expected &&
950 git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual &&
951 test_cmp expected actual
952 '
953
954 test_atom refs/myblobs/first subject ""
955 test_atom refs/myblobs/first contents:subject ""
956 test_atom refs/myblobs/first body ""
957 test_atom refs/myblobs/first contents:body ""
958 test_atom refs/myblobs/first contents:signature ""
959 test_atom refs/myblobs/first contents ""
960
961 test_expect_success 'basic atom: refs/myblobs/first raw' '
962 git cat-file blob refs/myblobs/first >expected &&
963 echo >>expected &&
964 git for-each-ref --format="%(raw)" refs/myblobs/first >actual &&
965 test_cmp expected actual &&
966 git cat-file -s refs/myblobs/first >expected &&
967 git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual &&
968 test_cmp expected actual
969 '
970
971 test_expect_success 'set up refs pointing to binary blob' '
972 printf "a\0b\0c" >blob1 &&
973 printf "a\0c\0b" >blob2 &&
974 printf "\0a\0b\0c" >blob3 &&
975 printf "abc" >blob4 &&
976 printf "\0 \0 \0 " >blob5 &&
977 printf "\0 \0a\0 " >blob6 &&
978 printf " " >blob7 &&
979 >blob8 &&
980 obj=$(git hash-object -w blob1) &&
981 git update-ref refs/myblobs/blob1 "$obj" &&
982 obj=$(git hash-object -w blob2) &&
983 git update-ref refs/myblobs/blob2 "$obj" &&
984 obj=$(git hash-object -w blob3) &&
985 git update-ref refs/myblobs/blob3 "$obj" &&
986 obj=$(git hash-object -w blob4) &&
987 git update-ref refs/myblobs/blob4 "$obj" &&
988 obj=$(git hash-object -w blob5) &&
989 git update-ref refs/myblobs/blob5 "$obj" &&
990 obj=$(git hash-object -w blob6) &&
991 git update-ref refs/myblobs/blob6 "$obj" &&
992 obj=$(git hash-object -w blob7) &&
993 git update-ref refs/myblobs/blob7 "$obj" &&
994 obj=$(git hash-object -w blob8) &&
995 git update-ref refs/myblobs/blob8 "$obj"
996 '
997
998 test_expect_success 'Verify sorts with raw' '
999 cat >expected <<-EOF &&
1000 refs/myblobs/blob8
1001 refs/myblobs/blob5
1002 refs/myblobs/blob6
1003 refs/myblobs/blob3
1004 refs/myblobs/blob7
1005 refs/mytrees/first
1006 refs/myblobs/first
1007 refs/myblobs/blob1
1008 refs/myblobs/blob2
1009 refs/myblobs/blob4
1010 refs/heads/main
1011 EOF
1012 git for-each-ref --format="%(refname)" --sort=raw \
1013 refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
1014 test_cmp expected actual
1015 '
1016
1017 test_expect_success 'Verify sorts with raw:size' '
1018 cat >expected <<-EOF &&
1019 refs/myblobs/blob8
1020 refs/myblobs/first
1021 refs/myblobs/blob7
1022 refs/heads/main
1023 refs/myblobs/blob4
1024 refs/myblobs/blob1
1025 refs/myblobs/blob2
1026 refs/myblobs/blob3
1027 refs/myblobs/blob5
1028 refs/myblobs/blob6
1029 refs/mytrees/first
1030 EOF
1031 git for-each-ref --format="%(refname)" --sort=raw:size \
1032 refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
1033 test_cmp expected actual
1034 '
1035
1036 test_expect_success 'validate raw atom with %(if:equals)' '
1037 cat >expected <<-EOF &&
1038 not equals
1039 not equals
1040 not equals
1041 not equals
1042 not equals
1043 not equals
1044 refs/myblobs/blob4
1045 not equals
1046 not equals
1047 not equals
1048 not equals
1049 not equals
1050 EOF
1051 git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \
1052 refs/myblobs/ refs/heads/ >actual &&
1053 test_cmp expected actual
1054 '
1055
1056 test_expect_success 'validate raw atom with %(if:notequals)' '
1057 cat >expected <<-EOF &&
1058 refs/heads/ambiguous
1059 refs/heads/main
1060 refs/heads/newtag
1061 refs/myblobs/blob1
1062 refs/myblobs/blob2
1063 refs/myblobs/blob3
1064 equals
1065 refs/myblobs/blob5
1066 refs/myblobs/blob6
1067 refs/myblobs/blob7
1068 refs/myblobs/blob8
1069 refs/myblobs/first
1070 EOF
1071 git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \
1072 refs/myblobs/ refs/heads/ >actual &&
1073 test_cmp expected actual
1074 '
1075
1076 test_expect_success 'empty raw refs with %(if)' '
1077 cat >expected <<-EOF &&
1078 refs/myblobs/blob1 not empty
1079 refs/myblobs/blob2 not empty
1080 refs/myblobs/blob3 not empty
1081 refs/myblobs/blob4 not empty
1082 refs/myblobs/blob5 not empty
1083 refs/myblobs/blob6 not empty
1084 refs/myblobs/blob7 empty
1085 refs/myblobs/blob8 empty
1086 refs/myblobs/first not empty
1087 EOF
1088 git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \
1089 refs/myblobs/ >actual &&
1090 test_cmp expected actual
1091 '
1092
1093 test_expect_success '%(raw) with --python must fail' '
1094 test_must_fail git for-each-ref --format="%(raw)" --python
1095 '
1096
1097 test_expect_success '%(raw) with --tcl must fail' '
1098 test_must_fail git for-each-ref --format="%(raw)" --tcl
1099 '
1100
1101 test_expect_success '%(raw) with --perl' '
1102 git for-each-ref --format="\$name= %(raw);
1103 print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual &&
1104 cmp blob1 actual &&
1105 git for-each-ref --format="\$name= %(raw);
1106 print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual &&
1107 cmp blob3 actual &&
1108 git for-each-ref --format="\$name= %(raw);
1109 print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual &&
1110 cmp blob8 actual &&
1111 git for-each-ref --format="\$name= %(raw);
1112 print \"\$name\"" refs/myblobs/first --perl | perl >actual &&
1113 cmp one actual &&
1114 git cat-file tree refs/mytrees/first > expected &&
1115 git for-each-ref --format="\$name= %(raw);
1116 print \"\$name\"" refs/mytrees/first --perl | perl >actual &&
1117 cmp expected actual
1118 '
1119
1120 test_expect_success '%(raw) with --shell must fail' '
1121 test_must_fail git for-each-ref --format="%(raw)" --shell
1122 '
1123
1124 test_expect_success '%(raw) with --shell and --sort=raw must fail' '
1125 test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell
1126 '
1127
1128 test_expect_success '%(raw:size) with --shell' '
1129 git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect &&
1130 git for-each-ref --format="%(raw:size)" --shell >actual &&
1131 test_cmp expect actual
1132 '
1133
1134 test_expect_success 'for-each-ref --format compare with cat-file --batch' '
1135 git rev-parse refs/mytrees/first | git cat-file --batch >expected &&
1136 git for-each-ref --format="%(objectname) %(objecttype) %(objectsize)
1137 %(raw)" refs/mytrees/first >actual &&
1138 test_cmp expected actual
1139 '
1140
1141 test_expect_success 'set up multiple-sort tags' '
1142 for when in 100000 200000
1143 do
1144 for email in user1 user2
1145 do
1146 for ref in ref1 ref2
1147 do
1148 GIT_COMMITTER_DATE="@$when +0000" \
1149 GIT_COMMITTER_EMAIL="$email@example.com" \
1150 git tag -m "tag $ref-$when-$email" \
1151 multi-$ref-$when-$email || return 1
1152 done
1153 done
1154 done
1155 '
1156
1157 test_expect_success 'Verify sort with multiple keys' '
1158 cat >expected <<-\EOF &&
1159 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1160 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1161 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1162 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1163 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1164 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1165 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1166 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1167 EOF
1168 git for-each-ref \
1169 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1170 --sort=-refname \
1171 --sort=taggeremail \
1172 --sort=taggerdate \
1173 "refs/tags/multi-*" >actual &&
1174 test_cmp expected actual
1175 '
1176
1177 test_expect_success 'equivalent sorts fall back on refname' '
1178 cat >expected <<-\EOF &&
1179 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1180 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1181 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1182 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1183 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1184 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1185 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1186 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1187 EOF
1188 git for-each-ref \
1189 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1190 --sort=taggerdate \
1191 "refs/tags/multi-*" >actual &&
1192 test_cmp expected actual
1193 '
1194
1195 test_expect_success '--no-sort cancels the previous sort keys' '
1196 cat >expected <<-\EOF &&
1197 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1198 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1199 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1200 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1201 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1202 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1203 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1204 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1205 EOF
1206 git for-each-ref \
1207 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1208 --sort=-refname \
1209 --sort=taggeremail \
1210 --no-sort \
1211 --sort=taggerdate \
1212 "refs/tags/multi-*" >actual &&
1213 test_cmp expected actual
1214 '
1215
1216 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
1217 test_when_finished "git checkout main" &&
1218 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
1219 sed -e "s/^\* / /" actual >expect &&
1220 git checkout --orphan orphaned-branch &&
1221 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
1222 test_cmp expect actual
1223 '
1224
1225 cat >trailers <<EOF
1226 Reviewed-by: A U Thor <author@example.com>
1227 Signed-off-by: A U Thor <author@example.com>
1228 [ v2 updated patch description ]
1229 Acked-by: A U Thor
1230 <author@example.com>
1231 EOF
1232
1233 unfold () {
1234 perl -0pe 's/\n\s+/ /g'
1235 }
1236
1237 test_expect_success 'set up trailers for next test' '
1238 echo "Some contents" > two &&
1239 git add two &&
1240 git commit -F - <<-EOF
1241 trailers: this commit message has trailers
1242
1243 Some message contents
1244
1245 $(cat trailers)
1246 EOF
1247 '
1248
1249 test_trailer_option () {
1250 title=$1 option=$2
1251 cat >expect
1252 test_expect_success "$title" '
1253 git for-each-ref --format="%($option)" refs/heads/main >actual &&
1254 test_cmp expect actual &&
1255 git for-each-ref --format="%(contents:$option)" refs/heads/main >actual &&
1256 test_cmp expect actual
1257 '
1258 }
1259
1260 test_trailer_option '%(trailers:unfold) unfolds trailers' \
1261 'trailers:unfold' <<-EOF
1262 $(unfold <trailers)
1263
1264 EOF
1265
1266 test_trailer_option '%(trailers:only) shows only "key: value" trailers' \
1267 'trailers:only' <<-EOF
1268 $(grep -v patch.description <trailers)
1269
1270 EOF
1271
1272 test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \
1273 'trailers:only=no,only=true' <<-EOF
1274 $(grep -v patch.description <trailers)
1275
1276 EOF
1277
1278 test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \
1279 'trailers:only=yes' <<-EOF
1280 $(grep -v patch.description <trailers)
1281
1282 EOF
1283
1284 test_trailer_option '%(trailers:only=no) shows all trailers' \
1285 'trailers:only=no' <<-EOF
1286 $(cat trailers)
1287
1288 EOF
1289
1290 test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \
1291 'trailers:only,unfold' <<-EOF
1292 $(grep -v patch.description <trailers | unfold)
1293
1294 EOF
1295
1296 test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \
1297 'trailers:unfold,only' <<-EOF
1298 $(grep -v patch.description <trailers | unfold)
1299
1300 EOF
1301
1302 test_trailer_option '%(trailers:key=foo) shows that trailer' \
1303 'trailers:key=Signed-off-by' <<-EOF
1304 Signed-off-by: A U Thor <author@example.com>
1305
1306 EOF
1307
1308 test_trailer_option '%(trailers:key=foo) is case insensitive' \
1309 'trailers:key=SiGned-oFf-bY' <<-EOF
1310 Signed-off-by: A U Thor <author@example.com>
1311
1312 EOF
1313
1314 test_trailer_option '%(trailers:key=foo:) trailing colon also works' \
1315 'trailers:key=Signed-off-by:' <<-EOF
1316 Signed-off-by: A U Thor <author@example.com>
1317
1318 EOF
1319
1320 test_trailer_option '%(trailers:key=foo) multiple keys' \
1321 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF
1322 Reviewed-by: A U Thor <author@example.com>
1323 Signed-off-by: A U Thor <author@example.com>
1324
1325 EOF
1326
1327 test_trailer_option '%(trailers:key=nonexistent) becomes empty' \
1328 'trailers:key=Shined-off-by:' <<-EOF
1329
1330 EOF
1331
1332 test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \
1333 'trailers:key=Acked-by' <<-EOF
1334 $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by)
1335
1336 EOF
1337
1338 test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \
1339 'trailers:key=Signed-Off-by,unfold' <<-EOF
1340 $(unfold <trailers | grep Signed-off-by)
1341
1342 EOF
1343
1344 test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \
1345 'trailers:key=Signed-off-by,only=no' <<-EOF
1346 Signed-off-by: A U Thor <author@example.com>
1347 $(grep patch.description <trailers)
1348
1349 EOF
1350
1351 test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \
1352 'trailers:key=Signed-off-by,valueonly' <<-EOF
1353 A U Thor <author@example.com>
1354
1355 EOF
1356
1357 test_trailer_option '%(trailers:separator) changes separator' \
1358 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1359 Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com>
1360 EOF
1361
1362 test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \
1363 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1364 Reviewed-by,A U Thor <author@example.com>
1365 Signed-off-by,A U Thor <author@example.com>
1366
1367 EOF
1368
1369 test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \
1370 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1371 Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com>
1372 EOF
1373
1374 test_failing_trailer_option () {
1375 title=$1 option=$2
1376 cat >expect
1377 test_expect_success "$title" '
1378 # error message cannot be checked under i18n
1379 test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual &&
1380 test_cmp expect actual &&
1381 test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual &&
1382 test_cmp expect actual
1383 '
1384 }
1385
1386 test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \
1387 'trailers:unsupported' <<-\EOF
1388 fatal: unknown %(trailers) argument: unsupported
1389 EOF
1390
1391 test_failing_trailer_option '%(trailers:key) without value is error' \
1392 'trailers:key' <<-\EOF
1393 fatal: expected %(trailers:key=<value>)
1394 EOF
1395
1396 test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
1397 cat >expect <<-EOF &&
1398 fatal: unrecognized %(contents) argument: trailersonly
1399 EOF
1400 test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
1401 test_cmp expect actual
1402 '
1403
1404 test_expect_success 'basic atom: head contents:trailers' '
1405 git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual &&
1406 sanitize_pgp <actual >actual.clean &&
1407 # git for-each-ref ends with a blank line
1408 cat >expect <<-EOF &&
1409 $(cat trailers)
1410
1411 EOF
1412 test_cmp expect actual.clean
1413 '
1414
1415 test_expect_success 'basic atom: rest must fail' '
1416 test_must_fail git for-each-ref --format="%(rest)" refs/heads/main
1417 '
1418
1419 test_expect_success 'HEAD atom does not take arguments' '
1420 test_must_fail git for-each-ref --format="%(HEAD:foo)" 2>err &&
1421 echo "fatal: %(HEAD) does not take arguments" >expect &&
1422 test_cmp expect err
1423 '
1424
1425 test_expect_success 'subject atom rejects unknown arguments' '
1426 test_must_fail git for-each-ref --format="%(subject:foo)" 2>err &&
1427 echo "fatal: unrecognized %(subject) argument: foo" >expect &&
1428 test_cmp expect err
1429 '
1430
1431 test_expect_success 'refname atom rejects unknown arguments' '
1432 test_must_fail git for-each-ref --format="%(refname:foo)" 2>err &&
1433 echo "fatal: unrecognized %(refname) argument: foo" >expect &&
1434 test_cmp expect err
1435 '
1436
1437 test_expect_success 'trailer parsing not fooled by --- line' '
1438 git commit --allow-empty -F - <<-\EOF &&
1439 this is the subject
1440
1441 This is the body. The message has a "---" line which would confuse a
1442 message+patch parser. But here we know we have only a commit message,
1443 so we get it right.
1444
1445 trailer: wrong
1446 ---
1447 This is more body.
1448
1449 trailer: right
1450 EOF
1451
1452 {
1453 echo "trailer: right" &&
1454 echo
1455 } >expect &&
1456 git for-each-ref --format="%(trailers)" refs/heads/main >actual &&
1457 test_cmp expect actual
1458 '
1459
1460 test_expect_success 'Add symbolic ref for the following tests' '
1461 git symbolic-ref refs/heads/sym refs/heads/main
1462 '
1463
1464 cat >expected <<EOF
1465 refs/heads/main
1466 EOF
1467
1468 test_expect_success 'Verify usage of %(symref) atom' '
1469 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
1470 test_cmp expected actual
1471 '
1472
1473 cat >expected <<EOF
1474 heads/main
1475 EOF
1476
1477 test_expect_success 'Verify usage of %(symref:short) atom' '
1478 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
1479 test_cmp expected actual
1480 '
1481
1482 cat >expected <<EOF
1483 main
1484 heads/main
1485 EOF
1486
1487 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
1488 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
1489 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
1490 test_cmp expected actual &&
1491
1492 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
1493 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
1494 test_cmp expected actual
1495 '
1496
1497 cat >expected <<EOF
1498 refs
1499 refs/heads
1500 EOF
1501
1502 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
1503 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
1504 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
1505 test_cmp expected actual
1506 '
1507
1508 test_expect_success ':remotename and :remoteref' '
1509 git init remote-tests &&
1510 (
1511 cd remote-tests &&
1512 test_commit initial &&
1513 git branch -M main &&
1514 git remote add from fifth.coffee:blub &&
1515 git config branch.main.remote from &&
1516 git config branch.main.merge refs/heads/stable &&
1517 git remote add to southridge.audio:repo &&
1518 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
1519 git config branch.main.pushRemote to &&
1520 for pair in "%(upstream)=refs/remotes/from/stable" \
1521 "%(upstream:remotename)=from" \
1522 "%(upstream:remoteref)=refs/heads/stable" \
1523 "%(push)=refs/remotes/to/pushed/main" \
1524 "%(push:remotename)=to" \
1525 "%(push:remoteref)=refs/heads/pushed/main"
1526 do
1527 echo "${pair#*=}" >expect &&
1528 git for-each-ref --format="${pair%=*}" \
1529 refs/heads/main >actual &&
1530 test_cmp expect actual || exit 1
1531 done &&
1532 git branch push-simple &&
1533 git config branch.push-simple.pushRemote from &&
1534 actual="$(git for-each-ref \
1535 --format="%(push:remotename),%(push:remoteref)" \
1536 refs/heads/push-simple)" &&
1537 test from, = "$actual"
1538 )
1539 '
1540
1541 test_expect_success 'for-each-ref --ignore-case ignores case' '
1542 git for-each-ref --format="%(refname)" refs/heads/MAIN >actual &&
1543 test_must_be_empty actual &&
1544
1545 echo refs/heads/main >expect &&
1546 git for-each-ref --format="%(refname)" --ignore-case \
1547 refs/heads/MAIN >actual &&
1548 test_cmp expect actual
1549 '
1550
1551 test_expect_success 'for-each-ref --omit-empty works' '
1552 git for-each-ref --format="%(refname)" >actual &&
1553 test_line_count -gt 1 actual &&
1554 git for-each-ref --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual &&
1555 echo refs/heads/main >expect &&
1556 test_cmp expect actual
1557 '
1558
1559 test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
1560 # name refs numerically to avoid case-insensitive filesystem conflicts
1561 nr=0 &&
1562 for email in a A b B
1563 do
1564 for subject in a A b B
1565 do
1566 GIT_COMMITTER_EMAIL="$email@example.com" \
1567 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
1568 nr=$((nr+1))||
1569 return 1
1570 done
1571 done &&
1572 git for-each-ref --ignore-case \
1573 --format="%(taggeremail) %(subject) %(refname)" \
1574 --sort=refname \
1575 --sort=subject \
1576 --sort=taggeremail \
1577 refs/tags/icase-* >actual &&
1578 cat >expect <<-\EOF &&
1579 <a@example.com> tag a refs/tags/icase-00
1580 <a@example.com> tag A refs/tags/icase-01
1581 <A@example.com> tag a refs/tags/icase-04
1582 <A@example.com> tag A refs/tags/icase-05
1583 <a@example.com> tag b refs/tags/icase-02
1584 <a@example.com> tag B refs/tags/icase-03
1585 <A@example.com> tag b refs/tags/icase-06
1586 <A@example.com> tag B refs/tags/icase-07
1587 <b@example.com> tag a refs/tags/icase-08
1588 <b@example.com> tag A refs/tags/icase-09
1589 <B@example.com> tag a refs/tags/icase-12
1590 <B@example.com> tag A refs/tags/icase-13
1591 <b@example.com> tag b refs/tags/icase-10
1592 <b@example.com> tag B refs/tags/icase-11
1593 <B@example.com> tag b refs/tags/icase-14
1594 <B@example.com> tag B refs/tags/icase-15
1595 EOF
1596 test_cmp expect actual
1597 '
1598
1599 test_expect_success 'for-each-ref reports broken tags' '
1600 git tag -m "good tag" broken-tag-good HEAD &&
1601 git cat-file tag broken-tag-good >good &&
1602 sed s/commit/blob/ <good >bad &&
1603 bad=$(git hash-object -w -t tag bad) &&
1604 git update-ref refs/tags/broken-tag-bad $bad &&
1605 test_must_fail git for-each-ref --format="%(*objectname)" \
1606 refs/tags/broken-tag-*
1607 '
1608
1609 test_expect_success 'set up tag with signature and no blank lines' '
1610 git tag -F - fake-sig-no-blanks <<-\EOF
1611 this is the subject
1612 -----BEGIN PGP SIGNATURE-----
1613 not a real signature, but we just care about the
1614 subject/body parsing. It is important here that
1615 there are no blank lines in the signature.
1616 -----END PGP SIGNATURE-----
1617 EOF
1618 '
1619
1620 test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject'
1621 test_atom refs/tags/fake-sig-no-blanks contents:body ''
1622 test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig"
1623
1624 test_expect_success 'set up tag with CRLF signature' '
1625 append_cr <<-\EOF |
1626 this is the subject
1627 -----BEGIN PGP SIGNATURE-----
1628
1629 not a real signature, but we just care about
1630 the subject/body parsing. It is important here
1631 that there is a blank line separating this
1632 from the signature header.
1633 -----END PGP SIGNATURE-----
1634 EOF
1635 git tag -F - --cleanup=verbatim fake-sig-crlf
1636 '
1637
1638 test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject'
1639 test_atom refs/tags/fake-sig-crlf contents:body ''
1640
1641 # CRLF is retained in the signature, so we have to pass our expected value
1642 # through append_cr. But test_atom requires a shell string, which means command
1643 # substitution, and the shell will strip trailing newlines from the output of
1644 # the substitution. Hack around it by adding and then removing a dummy line.
1645 sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)"
1646 sig_crlf=${sig_crlf%dummy}
1647 test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf"
1648
1649 test_expect_success 'git for-each-ref --stdin: empty' '
1650 >in &&
1651 git for-each-ref --format="%(refname)" --stdin <in >actual &&
1652 git for-each-ref --format="%(refname)" >expect &&
1653 test_cmp expect actual
1654 '
1655
1656 test_expect_success 'git for-each-ref --stdin: fails if extra args' '
1657 >in &&
1658 test_must_fail git for-each-ref --format="%(refname)" \
1659 --stdin refs/heads/extra <in 2>err &&
1660 grep "unknown arguments supplied with --stdin" err
1661 '
1662
1663 test_expect_success 'git for-each-ref --stdin: matches' '
1664 cat >in <<-EOF &&
1665 refs/tags/multi*
1666 refs/heads/amb*
1667 EOF
1668
1669 cat >expect <<-EOF &&
1670 refs/heads/ambiguous
1671 refs/tags/multi-ref1-100000-user1
1672 refs/tags/multi-ref1-100000-user2
1673 refs/tags/multi-ref1-200000-user1
1674 refs/tags/multi-ref1-200000-user2
1675 refs/tags/multi-ref2-100000-user1
1676 refs/tags/multi-ref2-100000-user2
1677 refs/tags/multi-ref2-200000-user1
1678 refs/tags/multi-ref2-200000-user2
1679 refs/tags/multiline
1680 EOF
1681
1682 git for-each-ref --format="%(refname)" --stdin <in >actual &&
1683 test_cmp expect actual
1684 '
1685
1686 test_expect_success 'git for-each-ref with non-existing refs' '
1687 cat >in <<-EOF &&
1688 refs/heads/this-ref-does-not-exist
1689 refs/tags/bogus
1690 EOF
1691
1692 git for-each-ref --format="%(refname)" --stdin <in >actual &&
1693 test_must_be_empty actual &&
1694
1695 xargs git for-each-ref --format="%(refname)" <in >actual &&
1696 test_must_be_empty actual
1697 '
1698
1699 GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
1700 TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
1701
1702 test_expect_success GPG 'setup for signature atom using gpg' '
1703 git checkout -b signed &&
1704
1705 test_when_finished "test_unconfig commit.gpgSign" &&
1706
1707 echo "1" >file &&
1708 git add file &&
1709 test_tick &&
1710 git commit -S -m "file: 1" &&
1711 git tag first-signed &&
1712
1713 echo "2" >file &&
1714 test_tick &&
1715 git commit -a -m "file: 2" &&
1716 git tag second-unsigned &&
1717
1718 git config commit.gpgSign 1 &&
1719 echo "3" >file &&
1720 test_tick &&
1721 git commit -a --no-gpg-sign -m "file: 3" &&
1722 git tag third-unsigned &&
1723
1724 test_tick &&
1725 git rebase -f HEAD^^ && git tag second-signed HEAD^ &&
1726 git tag third-signed &&
1727
1728 echo "4" >file &&
1729 test_tick &&
1730 git commit -a -SB7227189 -m "file: 4" &&
1731 git tag fourth-signed &&
1732
1733 echo "5" >file &&
1734 test_tick &&
1735 git commit -a --no-gpg-sign -m "file: 5" &&
1736 git tag fifth-unsigned &&
1737
1738 echo "6" >file &&
1739 test_tick &&
1740 git commit -a --no-gpg-sign -m "file: 6" &&
1741
1742 test_tick &&
1743 git rebase -f HEAD^^ &&
1744 git tag fifth-signed HEAD^ &&
1745 git tag sixth-signed &&
1746
1747 echo "7" >file &&
1748 test_tick &&
1749 git commit -a --no-gpg-sign -m "file: 7" &&
1750 git tag seventh-unsigned
1751 '
1752
1753 test_expect_success GPGSSH 'setup for signature atom using ssh' '
1754 test_when_finished "test_unconfig gpg.format user.signingkey" &&
1755
1756 test_config gpg.format ssh &&
1757 test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
1758 echo "8" >file &&
1759 test_tick &&
1760 git add file &&
1761 git commit -S -m "file: 8" &&
1762 git tag eighth-signed-ssh
1763 '
1764
1765 test_expect_success GPG2 'bare signature atom' '
1766 git verify-commit first-signed 2>out.raw &&
1767 grep -Ev "checking the trustdb|PGP trust model" out.raw >out &&
1768 head -3 out >expect &&
1769 tail -1 out >>expect &&
1770 echo >>expect &&
1771 git for-each-ref refs/tags/first-signed \
1772 --format="%(signature)" >actual &&
1773 test_cmp expect actual
1774 '
1775
1776 test_expect_success GPG 'show good signature with custom format' '
1777 git verify-commit first-signed &&
1778 cat >expect <<-\EOF &&
1779 G
1780 13B6F51ECDDE430D
1781 C O Mitter <committer@example.com>
1782 73D758744BE721698EC54E8713B6F51ECDDE430D
1783 73D758744BE721698EC54E8713B6F51ECDDE430D
1784 EOF
1785 git for-each-ref refs/tags/first-signed \
1786 --format="$GRADE_FORMAT" >actual &&
1787 test_cmp expect actual
1788 '
1789 test_expect_success GPGSSH 'show good signature with custom format
1790 with ssh' '
1791 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
1792 FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") &&
1793 cat >expect.tmpl <<-\EOF &&
1794 G
1795 FINGERPRINT
1796 principal with number 1
1797 FINGERPRINT
1798
1799 EOF
1800 sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect &&
1801 git for-each-ref refs/tags/eighth-signed-ssh \
1802 --format="$GRADE_FORMAT" >actual &&
1803 test_cmp expect actual
1804 '
1805
1806 test_expect_success GPG 'signature atom with grade option and bad signature' '
1807 git cat-file commit third-signed >raw &&
1808 sed -e "s/^file: 3/file: 3 forged/" raw >forged1 &&
1809 FORGED1=$(git hash-object -w -t commit forged1) &&
1810 git update-ref refs/tags/third-signed "$FORGED1" &&
1811 test_must_fail git verify-commit "$FORGED1" &&
1812
1813 cat >expect <<-\EOF &&
1814 B
1815 13B6F51ECDDE430D
1816 C O Mitter <committer@example.com>
1817
1818
1819 EOF
1820 git for-each-ref refs/tags/third-signed \
1821 --format="$GRADE_FORMAT" >actual &&
1822 test_cmp expect actual
1823 '
1824
1825 test_expect_success GPG 'show untrusted signature with custom format' '
1826 cat >expect <<-\EOF &&
1827 U
1828 65A0EEA02E30CAD7
1829 Eris Discordia <discord@example.net>
1830 F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
1831 D4BE22311AD3131E5EDA29A461092E85B7227189
1832 EOF
1833 git for-each-ref refs/tags/fourth-signed \
1834 --format="$GRADE_FORMAT" >actual &&
1835 test_cmp expect actual
1836 '
1837
1838 test_expect_success GPG 'show untrusted signature with undefined trust level' '
1839 cat >expect <<-\EOF &&
1840 undefined
1841 65A0EEA02E30CAD7
1842 Eris Discordia <discord@example.net>
1843 F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
1844 D4BE22311AD3131E5EDA29A461092E85B7227189
1845 EOF
1846 git for-each-ref refs/tags/fourth-signed \
1847 --format="$TRUSTLEVEL_FORMAT" >actual &&
1848 test_cmp expect actual
1849 '
1850
1851 test_expect_success GPG 'show untrusted signature with ultimate trust level' '
1852 cat >expect <<-\EOF &&
1853 ultimate
1854 13B6F51ECDDE430D
1855 C O Mitter <committer@example.com>
1856 73D758744BE721698EC54E8713B6F51ECDDE430D
1857 73D758744BE721698EC54E8713B6F51ECDDE430D
1858 EOF
1859 git for-each-ref refs/tags/sixth-signed \
1860 --format="$TRUSTLEVEL_FORMAT" >actual &&
1861 test_cmp expect actual
1862 '
1863
1864 test_expect_success GPG 'show unknown signature with custom format' '
1865 cat >expect <<-\EOF &&
1866 E
1867 13B6F51ECDDE430D
1868
1869
1870
1871 EOF
1872 GNUPGHOME="$GNUPGHOME_NOT_USED" git for-each-ref \
1873 refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual &&
1874 test_cmp expect actual
1875 '
1876
1877 test_expect_success GPG 'show lack of signature with custom format' '
1878 cat >expect <<-\EOF &&
1879 N
1880
1881
1882
1883
1884 EOF
1885 git for-each-ref refs/tags/seventh-unsigned \
1886 --format="$GRADE_FORMAT" >actual &&
1887 test_cmp expect actual
1888 '
1889
1890 test_done