3 # Copyright (c) 2007 Andy Parkins
6 test_description
='for-each-ref test'
8 TEST_PASSES_SANITIZE_LEAK
=true
10 GNUPGHOME_NOT_USED
=$GNUPGHOME
11 .
"$TEST_DIRECTORY"/lib-gpg.sh
12 .
"$TEST_DIRECTORY"/lib-terminal.sh
14 # Mon Jul 3 23:18:43 2006 +0000
16 setdate_and_increment
() {
17 GIT_COMMITTER_DATE
="$datestamp +0200"
18 datestamp
=$
(expr "$datestamp" + 1)
19 GIT_AUTHOR_DATE
="$datestamp +0200"
20 datestamp
=$
(expr "$datestamp" + 1)
21 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
24 test_object_file_size
() {
25 oid
=$
(git rev-parse
"$1")
26 path
=".git/objects/$(test_oid_to_path $oid)"
27 test_file_size
"$path"
30 test_expect_success setup
'
32 cat >.mailmap <<-EOF &&
33 A Thor <athor@example.com> A U Thor <author@example.com>
34 C Mitter <cmitter@example.com> C O Mitter <committer@example.com>
37 setdate_and_increment &&
38 echo "Using $datestamp" > one &&
40 git commit -m "Initial" &&
42 setdate_and_increment &&
43 git tag -a -m "Tagging at $datestamp" testtag &&
44 git update-ref refs/remotes/origin/main main &&
45 git remote add origin nowhere &&
46 git config branch.main.remote origin &&
47 git config branch.main.merge refs/heads/main &&
48 git remote add myfork elsewhere &&
49 git config remote.pushdefault myfork &&
50 git config push.default current
55 head) ref
=refs
/heads
/main
;;
56 tag
) ref
=refs
/tags
/testtag
;;
57 sym
) ref
=refs
/heads
/sym
;;
61 test_do
=test_expect_
${4:-success}
63 printf '%s\n' "$3" >expected
64 $test_do $PREREQ "basic atom: $ref $format" '
65 git for-each-ref --format="%($format)" "$ref" >actual &&
66 sanitize_pgp <actual >actual.clean &&
67 test_cmp expected actual.clean
70 # Automatically test "contents:size" atom after testing "contents"
71 if test "$format" = "contents"
73 # for commit leg, $3 is changed there
74 expect
=$
(printf '%s' "$3" |
wc -c)
75 $test_do $PREREQ "basic atom: $ref contents:size" '
76 type=$(git cat-file -t "$ref") &&
79 # We cannot use $3 as it expects sanitize_pgp to run
80 git cat-file tag $ref >out &&
81 expect=$(tail -n +6 out | wc -c) &&
86 : "use the calculated expect" ;;
88 BUG "unknown object type" ;;
90 # Leave $expect unquoted to lose possible leading whitespaces
91 echo $expect >expected &&
92 git for-each-ref --format="%(contents:size)" "$ref" >actual &&
93 test_cmp expected actual
98 hexlen
=$
(test_oid hexsz
)
100 test_atom
head refname refs
/heads
/main
101 test_atom
head refname
: refs
/heads
/main
102 test_atom
head refname
:short main
103 test_atom
head refname
:lstrip
=1 heads
/main
104 test_atom
head refname
:lstrip
=2 main
105 test_atom
head refname
:lstrip
=-1 main
106 test_atom
head refname
:lstrip
=-2 heads
/main
107 test_atom
head refname
:rstrip
=1 refs
/heads
108 test_atom
head refname
:rstrip
=2 refs
109 test_atom
head refname
:rstrip
=-1 refs
110 test_atom
head refname
:rstrip
=-2 refs
/heads
111 test_atom
head refname
:strip
=1 heads
/main
112 test_atom
head refname
:strip
=2 main
113 test_atom
head refname
:strip
=-1 main
114 test_atom
head refname
:strip
=-2 heads
/main
115 test_atom
head upstream refs
/remotes
/origin
/main
116 test_atom
head upstream
:short origin
/main
117 test_atom
head upstream
:lstrip
=2 origin
/main
118 test_atom
head upstream
:lstrip
=-2 origin
/main
119 test_atom
head upstream
:rstrip
=2 refs
/remotes
120 test_atom
head upstream
:rstrip
=-2 refs
/remotes
121 test_atom
head upstream
:strip
=2 origin
/main
122 test_atom
head upstream
:strip
=-2 origin
/main
123 test_atom
head push refs
/remotes
/myfork
/main
124 test_atom
head push
:short myfork
/main
125 test_atom
head push
:lstrip
=1 remotes
/myfork
/main
126 test_atom
head push
:lstrip
=-1 main
127 test_atom
head push
:rstrip
=1 refs
/remotes
/myfork
128 test_atom
head push
:rstrip
=-1 refs
129 test_atom
head push
:strip
=1 remotes
/myfork
/main
130 test_atom
head push
:strip
=-1 main
131 test_atom
head objecttype commit
132 test_atom
head objectsize $
((131 + hexlen
))
133 test_atom
head objectsize
:disk $
(test_object_file_size refs
/heads
/main
)
134 test_atom
head deltabase
$ZERO_OID
135 test_atom
head objectname $
(git rev-parse refs
/heads
/main
)
136 test_atom
head objectname
:short $
(git rev-parse
--short refs
/heads
/main
)
137 test_atom
head objectname
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/main
)
138 test_atom
head objectname
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/main
)
139 test_atom
head tree $
(git rev-parse refs
/heads
/main^
{tree
})
140 test_atom
head tree
:short $
(git rev-parse
--short refs
/heads
/main^
{tree
})
141 test_atom
head tree
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/main^
{tree
})
142 test_atom
head tree
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/main^
{tree
})
143 test_atom
head parent
''
144 test_atom
head parent
:short
''
145 test_atom
head parent
:short
=1 ''
146 test_atom
head parent
:short
=10 ''
147 test_atom
head numparent
0
148 test_atom
head object
''
149 test_atom
head type ''
150 test_atom
head raw
"$(git cat-file commit refs/heads/main)
152 test_atom
head '*objectname' ''
153 test_atom
head '*objecttype' ''
154 test_atom
head author
'A U Thor <author@example.com> 1151968724 +0200'
155 test_atom
head authorname
'A U Thor'
156 test_atom
head authorname
:mailmap
'A Thor'
157 test_atom
head authoremail
'<author@example.com>'
158 test_atom
head authoremail
:trim
'author@example.com'
159 test_atom
head authoremail
:localpart
'author'
160 test_atom
head authoremail
:trim
,localpart
'author'
161 test_atom
head authoremail
:mailmap
'<athor@example.com>'
162 test_atom
head authoremail
:mailmap
,trim
'athor@example.com'
163 test_atom
head authoremail
:trim
,mailmap
'athor@example.com'
164 test_atom
head authoremail
:mailmap
,localpart
'athor'
165 test_atom
head authoremail
:localpart
,mailmap
'athor'
166 test_atom
head authoremail
:mailmap
,trim
,localpart
,mailmap
,trim
'athor'
167 test_atom
head authordate
'Tue Jul 4 01:18:44 2006 +0200'
168 test_atom
head committer
'C O Mitter <committer@example.com> 1151968723 +0200'
169 test_atom
head committername
'C O Mitter'
170 test_atom
head committername
:mailmap
'C Mitter'
171 test_atom
head committeremail
'<committer@example.com>'
172 test_atom
head committeremail
:trim
'committer@example.com'
173 test_atom
head committeremail
:localpart
'committer'
174 test_atom
head committeremail
:localpart
,trim
'committer'
175 test_atom
head committeremail
:mailmap
'<cmitter@example.com>'
176 test_atom
head committeremail
:mailmap
,trim
'cmitter@example.com'
177 test_atom
head committeremail
:trim
,mailmap
'cmitter@example.com'
178 test_atom
head committeremail
:mailmap
,localpart
'cmitter'
179 test_atom
head committeremail
:localpart
,mailmap
'cmitter'
180 test_atom
head committeremail
:trim
,mailmap
,trim
,trim
,localpart
'cmitter'
181 test_atom
head committerdate
'Tue Jul 4 01:18:43 2006 +0200'
182 test_atom
head tag
''
183 test_atom
head tagger
''
184 test_atom
head taggername
''
185 test_atom
head taggeremail
''
186 test_atom
head taggeremail
:trim
''
187 test_atom
head taggeremail
:localpart
''
188 test_atom
head taggerdate
''
189 test_atom
head creator
'C O Mitter <committer@example.com> 1151968723 +0200'
190 test_atom
head creatordate
'Tue Jul 4 01:18:43 2006 +0200'
191 test_atom
head subject
'Initial'
192 test_atom
head subject
:sanitize
'Initial'
193 test_atom
head contents
:subject
'Initial'
194 test_atom
head body
''
195 test_atom
head contents
:body
''
196 test_atom
head contents
:signature
''
197 test_atom
head contents
'Initial
199 test_atom
head HEAD
'*'
201 test_atom tag refname refs
/tags
/testtag
202 test_atom tag refname
:short testtag
203 test_atom tag upstream
''
204 test_atom tag push
''
205 test_atom tag objecttype tag
206 test_atom tag objectsize $
((114 + hexlen
))
207 test_atom tag objectsize
:disk $
(test_object_file_size refs
/tags
/testtag
)
208 test_atom tag
'*objectsize:disk' $
(test_object_file_size refs
/heads
/main
)
209 test_atom tag deltabase
$ZERO_OID
210 test_atom tag
'*deltabase' $ZERO_OID
211 test_atom tag objectname $
(git rev-parse refs
/tags
/testtag
)
212 test_atom tag objectname
:short $
(git rev-parse
--short refs
/tags
/testtag
)
213 test_atom
head objectname
:short
=1 $
(git rev-parse
--short=1 refs
/heads
/main
)
214 test_atom
head objectname
:short
=10 $
(git rev-parse
--short=10 refs
/heads
/main
)
215 test_atom tag tree
''
216 test_atom tag tree
:short
''
217 test_atom tag tree
:short
=1 ''
218 test_atom tag tree
:short
=10 ''
219 test_atom tag parent
''
220 test_atom tag parent
:short
''
221 test_atom tag parent
:short
=1 ''
222 test_atom tag parent
:short
=10 ''
223 test_atom tag numparent
''
224 test_atom tag object $
(git rev-parse refs
/tags
/testtag^
0)
225 test_atom tag
type 'commit'
226 test_atom tag
'*objectname' $
(git rev-parse refs
/tags
/testtag^
{})
227 test_atom tag
'*objecttype' 'commit'
228 test_atom tag author
''
229 test_atom tag authorname
''
230 test_atom tag authorname
:mailmap
''
231 test_atom tag authoremail
''
232 test_atom tag authoremail
:trim
''
233 test_atom tag authoremail
:localpart
''
234 test_atom tag authoremail
:trim
,localpart
''
235 test_atom tag authoremail
:mailmap
''
236 test_atom tag authoremail
:mailmap
,trim
''
237 test_atom tag authoremail
:trim
,mailmap
''
238 test_atom tag authoremail
:mailmap
,localpart
''
239 test_atom tag authoremail
:localpart
,mailmap
''
240 test_atom tag authoremail
:mailmap
,trim
,localpart
,mailmap
,trim
''
241 test_atom tag authordate
''
242 test_atom tag committer
''
243 test_atom tag committername
''
244 test_atom tag committername
:mailmap
''
245 test_atom tag committeremail
''
246 test_atom tag committeremail
:trim
''
247 test_atom tag committeremail
:localpart
''
248 test_atom tag committeremail
:localpart
,trim
''
249 test_atom tag committeremail
:mailmap
''
250 test_atom tag committeremail
:mailmap
,trim
''
251 test_atom tag committeremail
:trim
,mailmap
''
252 test_atom tag committeremail
:mailmap
,localpart
''
253 test_atom tag committeremail
:localpart
,mailmap
''
254 test_atom tag committeremail
:trim
,mailmap
,trim
,trim
,localpart
''
255 test_atom tag committerdate
''
256 test_atom tag tag
'testtag'
257 test_atom tag tagger
'C O Mitter <committer@example.com> 1151968725 +0200'
258 test_atom tag taggername
'C O Mitter'
259 test_atom tag taggername
:mailmap
'C Mitter'
260 test_atom tag taggeremail
'<committer@example.com>'
261 test_atom tag taggeremail
:trim
'committer@example.com'
262 test_atom tag taggeremail
:localpart
'committer'
263 test_atom tag taggeremail
:trim
,localpart
'committer'
264 test_atom tag taggeremail
:mailmap
'<cmitter@example.com>'
265 test_atom tag taggeremail
:mailmap
,trim
'cmitter@example.com'
266 test_atom tag taggeremail
:trim
,mailmap
'cmitter@example.com'
267 test_atom tag taggeremail
:mailmap
,localpart
'cmitter'
268 test_atom tag taggeremail
:localpart
,mailmap
'cmitter'
269 test_atom tag taggeremail
:trim
,mailmap
,trim
,localpart
,localpart
'cmitter'
270 test_atom tag taggerdate
'Tue Jul 4 01:18:45 2006 +0200'
271 test_atom tag creator
'C O Mitter <committer@example.com> 1151968725 +0200'
272 test_atom tag creatordate
'Tue Jul 4 01:18:45 2006 +0200'
273 test_atom tag subject
'Tagging at 1151968727'
274 test_atom tag subject
:sanitize
'Tagging-at-1151968727'
275 test_atom tag contents
:subject
'Tagging at 1151968727'
276 test_atom tag body
''
277 test_atom tag contents
:body
''
278 test_atom tag contents
:signature
''
279 test_atom tag contents
'Tagging at 1151968727
281 test_atom tag HEAD
' '
283 test_expect_success
'basic atom: refs/tags/testtag *raw' '
284 git cat-file commit refs/tags/testtag^{} >expected &&
285 git for-each-ref --format="%(*raw)" refs/tags/testtag >actual &&
286 sanitize_pgp <expected >expected.clean &&
287 echo >>expected.clean &&
288 sanitize_pgp <actual >actual.clean &&
289 test_cmp expected.clean actual.clean
292 test_expect_success
'Check invalid atoms names are errors' '
293 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
296 test_expect_success
'Check format specifiers are ignored in naming date atoms' '
297 git for-each-ref --format="%(authordate)" refs/heads &&
298 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
299 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
300 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
303 test_expect_success
'Check valid format specifiers for date fields' '
304 git for-each-ref --format="%(authordate:default)" refs/heads &&
305 git for-each-ref --format="%(authordate:relative)" refs/heads &&
306 git for-each-ref --format="%(authordate:short)" refs/heads &&
307 git for-each-ref --format="%(authordate:local)" refs/heads &&
308 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
309 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
312 test_expect_success
'Check invalid format specifiers are errors' '
313 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
316 test_expect_success
'arguments to %(objectname:short=) must be positive integers' '
317 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
318 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
319 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
324 head) ref
=refs
/heads
/main
;;
325 tag
) ref
=refs
/tags
/testtag
;;
326 sym
) ref
=refs
/heads
/sym
;;
330 test_do
=test_expect_
${4:-success}
332 printf '%s\n' "$3" >expect
333 $test_do $PREREQ "err basic atom: $ref $format" '
334 test_must_fail git for-each-ref \
335 --format="%($format)" "$ref" 2>error &&
336 test_cmp expect error
340 test_bad_atom
head 'authoremail:foo' \
341 'fatal: unrecognized %(authoremail) argument: foo'
343 test_bad_atom
head 'authoremail:mailmap,trim,bar' \
344 'fatal: unrecognized %(authoremail) argument: bar'
346 test_bad_atom
head 'authoremail:trim,' \
347 'fatal: unrecognized %(authoremail) argument: '
349 test_bad_atom
head 'authoremail:mailmaptrim' \
350 'fatal: unrecognized %(authoremail) argument: trim'
352 test_bad_atom
head 'committeremail: ' \
353 'fatal: unrecognized %(committeremail) argument: '
355 test_bad_atom
head 'committeremail: trim,foo' \
356 'fatal: unrecognized %(committeremail) argument: trim,foo'
358 test_bad_atom
head 'committeremail:mailmap,localpart ' \
359 'fatal: unrecognized %(committeremail) argument: '
361 test_bad_atom
head 'committeremail:trim_localpart' \
362 'fatal: unrecognized %(committeremail) argument: _localpart'
364 test_bad_atom
head 'committeremail:localpart,,,trim' \
365 'fatal: unrecognized %(committeremail) argument: ,,trim'
367 test_bad_atom tag
'taggeremail:mailmap,trim, foo ' \
368 'fatal: unrecognized %(taggeremail) argument: foo '
370 test_bad_atom tag
'taggeremail:trim,localpart,' \
371 'fatal: unrecognized %(taggeremail) argument: '
373 test_bad_atom tag
'taggeremail:mailmap;localpart trim' \
374 'fatal: unrecognized %(taggeremail) argument: ;localpart trim'
376 test_bad_atom tag
'taggeremail:localpart trim' \
377 'fatal: unrecognized %(taggeremail) argument: trim'
379 test_bad_atom tag
'taggeremail:mailmap,mailmap,trim,qux,localpart,trim' \
380 'fatal: unrecognized %(taggeremail) argument: qux,localpart,trim'
387 cat >expected
<<-EOF &&
388 'refs/heads/main' '$committer_date' '$author_date'
389 'refs/tags/testtag' '$tagger_date'
392 git for-each-ref
--shell \
393 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
395 git for-each-ref
--shell \
396 --format="%(refname) %(taggerdate${f:+:$f})" \
399 test_cmp expected actual
402 test_expect_success
'Check unformatted date fields output' '
404 "Tue Jul 4 01:18:43 2006 +0200" \
405 "Tue Jul 4 01:18:44 2006 +0200" \
406 "Tue Jul 4 01:18:45 2006 +0200"
409 test_expect_success
'Check format "default" formatted date fields output' '
411 "Tue Jul 4 01:18:43 2006 +0200" \
412 "Tue Jul 4 01:18:44 2006 +0200" \
413 "Tue Jul 4 01:18:45 2006 +0200"
416 test_expect_success
'Check format "default-local" date fields output' '
417 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"
420 # Don't know how to do relative check because I can't know when this script
421 # is going to be run and can't fake the current time to git, and hence can't
422 # provide expected output. Instead, I'll just make sure that "relative"
423 # doesn't exit in error
424 test_expect_success
'Check format "relative" date fields output' '
426 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
427 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
430 # We just check that this is the same as "relative" for now.
431 test_expect_success
'Check format "relative-local" date fields output' '
432 test_date relative-local \
433 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
434 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
435 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
438 test_expect_success
'Check format "short" date fields output' '
439 test_date short 2006-07-04 2006-07-04 2006-07-04
442 test_expect_success
'Check format "short-local" date fields output' '
443 test_date short-local 2006-07-03 2006-07-03 2006-07-03
446 test_expect_success
'Check format "local" date fields output' '
448 "Mon Jul 3 23:18:43 2006" \
449 "Mon Jul 3 23:18:44 2006" \
450 "Mon Jul 3 23:18:45 2006"
453 test_expect_success
'Check format "iso8601" date fields output' '
455 "2006-07-04 01:18:43 +0200" \
456 "2006-07-04 01:18:44 +0200" \
457 "2006-07-04 01:18:45 +0200"
460 test_expect_success
'Check format "iso8601-local" date fields output' '
461 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"
464 test_expect_success
'Check format "rfc2822" date fields output' '
466 "Tue, 4 Jul 2006 01:18:43 +0200" \
467 "Tue, 4 Jul 2006 01:18:44 +0200" \
468 "Tue, 4 Jul 2006 01:18:45 +0200"
471 test_expect_success
'Check format "rfc2822-local" date fields output' '
472 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"
475 test_expect_success
'Check format "raw" date fields output' '
476 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
479 test_expect_success
'Check format "raw-local" date fields output' '
480 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
483 test_expect_success
'Check format of strftime date fields' '
484 echo "my date is 2006-07-04" >expected &&
486 --format="%(authordate:format:my date is %Y-%m-%d)" \
487 refs/heads >actual &&
488 test_cmp expected actual
491 test_expect_success
'Check format of strftime-local date fields' '
492 echo "my date is 2006-07-03" >expected &&
494 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
495 refs/heads >actual &&
496 test_cmp expected actual
499 test_expect_success
'exercise strftime with odd fields' '
501 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
502 test_cmp expected actual &&
503 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
504 echo $long >expected &&
505 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
506 test_cmp expected actual
511 refs
/remotes
/origin
/main
515 test_expect_success
'Verify ascending sort' '
516 git for-each-ref --format="%(refname)" --sort=refname >actual &&
517 test_cmp expected actual
523 refs
/remotes
/origin
/main
527 test_expect_success
'Verify descending sort' '
528 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
529 test_cmp expected actual
532 test_expect_success
'Give help even with invalid sort atoms' '
533 test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 &&
534 grep "^usage: git for-each-ref" actual
542 test_expect_success
'exercise patterns with prefixes' '
544 test_when_finished "git tag -d testtag-2" &&
545 git for-each-ref --format="%(refname)" \
546 refs/tags/testtag refs/tags/testtag-2 >actual &&
547 test_cmp expected actual
555 test_expect_success
'exercise glob patterns with prefixes' '
557 test_when_finished "git tag -d testtag-2" &&
558 git for-each-ref --format="%(refname)" \
559 refs/tags/testtag "refs/tags/testtag-*" >actual &&
560 test_cmp expected actual
569 test_expect_success
'exercise patterns with prefix exclusions' '
570 for tag in foo/one foo/two foo/three bar baz
572 git tag "$tag" || return 1
574 test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
575 git for-each-ref --format="%(refname)" \
576 refs/tags/ --exclude=refs/tags/foo >actual &&
577 test_cmp expected actual
587 test_expect_success
'exercise patterns with pattern exclusions' '
588 for tag in foo/one foo/two foo/three bar baz
590 git tag "$tag" || return 1
592 test_when_finished "git tag -d foo/one foo/two foo/three bar baz" &&
593 git for-each-ref --format="%(refname)" \
594 refs/tags/ --exclude="refs/tags/foo/t*" >actual &&
595 test_cmp expected actual
600 'refs/remotes/origin/main'
604 test_expect_success
'Quoting style: shell' '
605 git for-each-ref --shell --format="%(refname)" >actual &&
606 test_cmp expected actual
609 test_expect_success
'Quoting style: perl' '
610 git for-each-ref --perl --format="%(refname)" >actual &&
611 test_cmp expected actual
614 test_expect_success
'Quoting style: python' '
615 git for-each-ref --python --format="%(refname)" >actual &&
616 test_cmp expected actual
621 "refs/remotes/origin/main"
625 test_expect_success
'Quoting style: tcl' '
626 git for-each-ref --tcl --format="%(refname)" >actual &&
627 test_cmp expected actual
630 for i
in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
631 test_expect_success
"more than one quoting style: $i" "
632 test_must_fail git for-each-ref $i 2>err &&
633 grep '^error: more than one quoting style' err
637 test_expect_success
'setup for upstream:track[short]' '
641 test_atom
head upstream
:track
'[ahead 1]'
642 test_atom
head upstream
:trackshort
'>'
643 test_atom
head upstream
:track
,nobracket
'ahead 1'
644 test_atom
head upstream
:nobracket
,track
'ahead 1'
646 test_expect_success
'setup for push:track[short]' '
648 git update-ref refs/remotes/myfork/main main &&
652 test_atom
head push
:track
'[behind 1]'
653 test_atom
head push
:trackshort
'<'
655 test_expect_success
'Check that :track[short] cannot be used with other atoms' '
656 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
657 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
660 test_expect_success
'Check that :track[short] works when upstream is invalid' '
661 cat >expected <<-\EOF &&
665 test_when_finished "git config branch.main.merge refs/heads/main" &&
666 git config branch.main.merge refs/heads/does-not-exist &&
668 --format="%(upstream:track)$LF%(upstream:trackshort)" \
669 refs/heads >actual &&
670 test_cmp expected actual
673 test_expect_success
'Check for invalid refname format' '
674 test_must_fail git for-each-ref --format="%(refname:INVALID)"
677 test_expect_success
'set up color tests' '
678 cat >expected.color <<-EOF &&
679 $(git rev-parse --short refs/heads/main) <GREEN>main<RESET>
680 $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET>
681 $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET>
682 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
683 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
684 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
686 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
687 color_format="%(objectname:short) %(color:green)%(refname:short)"
690 test_expect_success TTY
'%(color) shows color with a tty' '
691 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
692 test_decode_color <actual.raw >actual &&
693 test_cmp expected.color actual
696 test_expect_success
'%(color) does not show color without tty' '
697 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
698 test_cmp expected.bare actual
701 test_expect_success
'--color can override tty check' '
702 git for-each-ref --color --format="$color_format" >actual.raw &&
703 test_decode_color <actual.raw >actual &&
704 test_cmp expected.color actual
707 test_expect_success
'color.ui=always does not override tty check' '
708 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
709 test_cmp expected.bare actual
712 test_expect_success
'setup for describe atom tests' '
713 git init -b master describe-repo &&
717 test_commit --no-tag one &&
720 test_commit --no-tag two &&
721 git tag -a -m "tag two" tagtwo
725 test_expect_success
'describe atom vs git describe' '
729 git for-each-ref --format="%(objectname)" \
733 if desc=$(git describe $hash)
735 : >expect-contains-good
737 : >expect-contains-bad
739 echo "$hash $desc" || return 1
741 test_path_exists expect-contains-good &&
742 test_path_exists expect-contains-bad &&
744 git for-each-ref --format="%(objectname) %(describe)" \
745 refs/tags/ >actual 2>err &&
746 test_cmp expect actual &&
747 test_must_be_empty err
751 test_expect_success
'describe:tags vs describe --tags' '
754 git describe --tags >expect &&
755 git for-each-ref --format="%(describe:tags)" \
756 refs/heads/master >actual &&
757 test_cmp expect actual
761 test_expect_success
'describe:abbrev=... vs describe --abbrev=...' '
765 # Case 1: We have commits between HEAD and the most
766 # recent tag reachable from it
767 test_commit --no-tag file &&
768 git describe --abbrev=14 >expect &&
769 git for-each-ref --format="%(describe:abbrev=14)" \
770 refs/heads/master >actual &&
771 test_cmp expect actual &&
773 # Make sure the hash used is atleast 14 digits long
774 sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart &&
775 test 15 -le $(wc -c <hexpart) &&
777 # Case 2: We have a tag at HEAD, describe directly gives
778 # the name of the tag
779 git tag -a -m tagged tagname &&
780 git describe --abbrev=14 >expect &&
781 git for-each-ref --format="%(describe:abbrev=14)" \
782 refs/heads/master >actual &&
783 test_cmp expect actual &&
784 test tagname = $(cat actual)
788 test_expect_success
'describe:match=... vs describe --match ...' '
791 git tag -a -m "tag foo" tag-foo &&
792 git describe --match "*-foo" >expect &&
793 git for-each-ref --format="%(describe:match="*-foo")" \
794 refs/heads/master >actual &&
795 test_cmp expect actual
799 test_expect_success
'describe:exclude:... vs describe --exclude ...' '
802 git tag -a -m "tag bar" tag-bar &&
803 git describe --exclude "*-bar" >expect &&
804 git for-each-ref --format="%(describe:exclude="*-bar")" \
805 refs/heads/master >actual &&
806 test_cmp expect actual
810 test_expect_success
'deref with describe atom' '
813 cat >expect <<-\EOF &&
821 git for-each-ref --format="%(*describe)" >actual &&
822 test_cmp expect actual
826 test_expect_success
'err on bad describe atom arg' '
830 # The bad arg is the only arg passed to describe atom
831 cat >expect <<-\EOF &&
832 fatal: unrecognized %(describe) argument: baz
834 test_must_fail git for-each-ref --format="%(describe:baz)" \
835 refs/heads/master 2>actual &&
836 test_cmp expect actual &&
838 # The bad arg is in the middle of the option string
839 # passed to the describe atom
840 cat >expect <<-\EOF &&
841 fatal: unrecognized %(describe) argument: qux=1,abbrev=14
843 test_must_fail git for-each-ref \
844 --format="%(describe:tags,qux=1,abbrev=14)" \
845 ref/heads/master 2>actual &&
846 test_cmp expect actual
855 test_expect_success
'Check ambiguous head and tag refs (strict)' '
856 git config --bool core.warnambiguousrefs true &&
857 git checkout -b newtag &&
858 echo "Using $datestamp" > one &&
860 git commit -m "Branch" &&
861 setdate_and_increment &&
862 git tag -m "Tagging at $datestamp" main &&
863 git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
864 test_cmp expected actual
872 test_expect_success
'Check ambiguous head and tag refs (loose)' '
873 git config --bool core.warnambiguousrefs false &&
874 git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual &&
875 test_cmp expected actual
883 test_expect_success
'Check ambiguous head and tag refs II (loose)' '
885 git tag ambiguous testtag^0 &&
886 git branch ambiguous testtag^0 &&
887 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
888 test_cmp expected actual
891 test_expect_success
'create tag without tagger' '
892 git tag -a -m "Broken tag" taggerless &&
893 git tag -f taggerless $(git cat-file tag taggerless |
894 sed -e "/^tagger /d" |
895 git hash-object --literally --stdin -w -t tag)
898 test_atom refs
/tags
/taggerless
type 'commit'
899 test_atom refs
/tags
/taggerless tag
'taggerless'
900 test_atom refs
/tags
/taggerless tagger
''
901 test_atom refs
/tags
/taggerless taggername
''
902 test_atom refs
/tags
/taggerless taggeremail
''
903 test_atom refs
/tags
/taggerless taggeremail
:trim
''
904 test_atom refs
/tags
/taggerless taggeremail
:localpart
''
905 test_atom refs
/tags
/taggerless taggerdate
''
906 test_atom refs
/tags
/taggerless committer
''
907 test_atom refs
/tags
/taggerless committername
''
908 test_atom refs
/tags
/taggerless committeremail
''
909 test_atom refs
/tags
/taggerless committeremail
:trim
''
910 test_atom refs
/tags
/taggerless committeremail
:localpart
''
911 test_atom refs
/tags
/taggerless committerdate
''
912 test_atom refs
/tags
/taggerless subject
'Broken tag'
914 test_expect_success
'an unusual tag with an incomplete line' '
916 git tag -m "bogo" bogo &&
917 bogo=$(git cat-file tag bogo) &&
918 bogo=$(printf "%s" "$bogo" | git mktag) &&
919 git tag -f bogo "$bogo" &&
920 git for-each-ref --format "%(body)" refs/tags/bogo
924 test_expect_success
'create tag with subject and body content' '
931 git tag -F msg subject-body
933 test_atom refs
/tags
/subject-body subject
'the subject line'
934 test_atom refs
/tags
/subject-body subject
:sanitize
'the-subject-line'
935 test_atom refs
/tags
/subject-body body
'first body line
938 test_atom refs
/tags
/subject-body contents
'the subject line
944 test_expect_success
'create tag with multiline subject' '
952 git tag -F msg multiline
954 test_atom refs
/tags
/multiline subject
'first subject line second subject line'
955 test_atom refs
/tags
/multiline subject
:sanitize
'first-subject-line-second-subject-line'
956 test_atom refs
/tags
/multiline contents
:subject
'first subject line second subject line'
957 test_atom refs
/tags
/multiline body
'first body line
960 test_atom refs
/tags
/multiline contents
:body
'first body line
963 test_atom refs
/tags
/multiline contents
:signature
''
964 test_atom refs
/tags
/multiline contents
'first subject line
971 test_expect_success GPG
'create signed tags' '
972 git tag -s -m "" signed-empty &&
973 git tag -s -m "subject line" signed-short &&
979 git tag -s -F msg signed-long
982 sig
='-----BEGIN PGP SIGNATURE-----
983 -----END PGP SIGNATURE-----
987 test_atom refs
/tags
/signed-empty subject
''
988 test_atom refs
/tags
/signed-empty subject
:sanitize
''
989 test_atom refs
/tags
/signed-empty contents
:subject
''
990 test_atom refs
/tags
/signed-empty body
"$sig"
991 test_atom refs
/tags
/signed-empty contents
:body
''
992 test_atom refs
/tags
/signed-empty contents
:signature
"$sig"
993 test_atom refs
/tags
/signed-empty contents
"$sig"
995 test_expect_success GPG
'basic atom: refs/tags/signed-empty raw' '
996 git cat-file tag refs/tags/signed-empty >expected &&
997 git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual &&
998 sanitize_pgp <expected >expected.clean &&
999 echo >>expected.clean &&
1000 sanitize_pgp <actual >actual.clean &&
1001 test_cmp expected.clean actual.clean
1004 test_atom refs
/tags
/signed-short subject
'subject line'
1005 test_atom refs
/tags
/signed-short subject
:sanitize
'subject-line'
1006 test_atom refs
/tags
/signed-short contents
:subject
'subject line'
1007 test_atom refs
/tags
/signed-short body
"$sig"
1008 test_atom refs
/tags
/signed-short contents
:body
''
1009 test_atom refs
/tags
/signed-short contents
:signature
"$sig"
1010 test_atom refs
/tags
/signed-short contents
"subject line
1013 test_expect_success GPG
'basic atom: refs/tags/signed-short raw' '
1014 git cat-file tag refs/tags/signed-short >expected &&
1015 git for-each-ref --format="%(raw)" refs/tags/signed-short >actual &&
1016 sanitize_pgp <expected >expected.clean &&
1017 echo >>expected.clean &&
1018 sanitize_pgp <actual >actual.clean &&
1019 test_cmp expected.clean actual.clean
1022 test_atom refs
/tags
/signed-long subject
'subject line'
1023 test_atom refs
/tags
/signed-long subject
:sanitize
'subject-line'
1024 test_atom refs
/tags
/signed-long contents
:subject
'subject line'
1025 test_atom refs
/tags
/signed-long body
"body contents
1027 test_atom refs
/tags
/signed-long contents
:body
'body contents
1029 test_atom refs
/tags
/signed-long contents
:signature
"$sig"
1030 test_atom refs
/tags
/signed-long contents
"subject line
1035 test_expect_success GPG
'basic atom: refs/tags/signed-long raw' '
1036 git cat-file tag refs/tags/signed-long >expected &&
1037 git for-each-ref --format="%(raw)" refs/tags/signed-long >actual &&
1038 sanitize_pgp <expected >expected.clean &&
1039 echo >>expected.clean &&
1040 sanitize_pgp <actual >actual.clean &&
1041 test_cmp expected.clean actual.clean
1044 test_expect_success
'set up refs pointing to tree and blob' '
1045 git update-ref refs/mytrees/first refs/heads/main^{tree} &&
1046 git update-ref refs/myblobs/first refs/heads/main:one
1049 test_atom refs
/mytrees
/first subject
""
1050 test_atom refs
/mytrees
/first contents
:subject
""
1051 test_atom refs
/mytrees
/first body
""
1052 test_atom refs
/mytrees
/first contents
:body
""
1053 test_atom refs
/mytrees
/first contents
:signature
""
1054 test_atom refs
/mytrees
/first contents
""
1056 test_expect_success
'basic atom: refs/mytrees/first raw' '
1057 git cat-file tree refs/mytrees/first >expected &&
1059 git for-each-ref --format="%(raw)" refs/mytrees/first >actual &&
1060 test_cmp expected actual &&
1061 git cat-file -s refs/mytrees/first >expected &&
1062 git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual &&
1063 test_cmp expected actual
1066 test_atom refs
/myblobs
/first subject
""
1067 test_atom refs
/myblobs
/first contents
:subject
""
1068 test_atom refs
/myblobs
/first body
""
1069 test_atom refs
/myblobs
/first contents
:body
""
1070 test_atom refs
/myblobs
/first contents
:signature
""
1071 test_atom refs
/myblobs
/first contents
""
1073 test_expect_success
'basic atom: refs/myblobs/first raw' '
1074 git cat-file blob refs/myblobs/first >expected &&
1076 git for-each-ref --format="%(raw)" refs/myblobs/first >actual &&
1077 test_cmp expected actual &&
1078 git cat-file -s refs/myblobs/first >expected &&
1079 git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual &&
1080 test_cmp expected actual
1083 test_expect_success
'set up refs pointing to binary blob' '
1084 printf "a\0b\0c" >blob1 &&
1085 printf "a\0c\0b" >blob2 &&
1086 printf "\0a\0b\0c" >blob3 &&
1087 printf "abc" >blob4 &&
1088 printf "\0 \0 \0 " >blob5 &&
1089 printf "\0 \0a\0 " >blob6 &&
1090 printf " " >blob7 &&
1092 obj=$(git hash-object -w blob1) &&
1093 git update-ref refs/myblobs/blob1 "$obj" &&
1094 obj=$(git hash-object -w blob2) &&
1095 git update-ref refs/myblobs/blob2 "$obj" &&
1096 obj=$(git hash-object -w blob3) &&
1097 git update-ref refs/myblobs/blob3 "$obj" &&
1098 obj=$(git hash-object -w blob4) &&
1099 git update-ref refs/myblobs/blob4 "$obj" &&
1100 obj=$(git hash-object -w blob5) &&
1101 git update-ref refs/myblobs/blob5 "$obj" &&
1102 obj=$(git hash-object -w blob6) &&
1103 git update-ref refs/myblobs/blob6 "$obj" &&
1104 obj=$(git hash-object -w blob7) &&
1105 git update-ref refs/myblobs/blob7 "$obj" &&
1106 obj=$(git hash-object -w blob8) &&
1107 git update-ref refs/myblobs/blob8 "$obj"
1110 test_expect_success
'Verify sorts with raw' '
1111 cat >expected <<-EOF &&
1124 git for-each-ref --format="%(refname)" --sort=raw \
1125 refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
1126 test_cmp expected actual
1129 test_expect_success
'Verify sorts with raw:size' '
1130 cat >expected <<-EOF &&
1143 git for-each-ref --format="%(refname)" --sort=raw:size \
1144 refs/heads/main refs/myblobs/ refs/mytrees/first >actual &&
1145 test_cmp expected actual
1148 test_expect_success
'validate raw atom with %(if:equals)' '
1149 cat >expected <<-EOF &&
1163 git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \
1164 refs/myblobs/ refs/heads/ >actual &&
1165 test_cmp expected actual
1168 test_expect_success
'validate raw atom with %(if:notequals)' '
1169 cat >expected <<-EOF &&
1170 refs/heads/ambiguous
1183 git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \
1184 refs/myblobs/ refs/heads/ >actual &&
1185 test_cmp expected actual
1188 test_expect_success
'empty raw refs with %(if)' '
1189 cat >expected <<-EOF &&
1190 refs/myblobs/blob1 not empty
1191 refs/myblobs/blob2 not empty
1192 refs/myblobs/blob3 not empty
1193 refs/myblobs/blob4 not empty
1194 refs/myblobs/blob5 not empty
1195 refs/myblobs/blob6 not empty
1196 refs/myblobs/blob7 empty
1197 refs/myblobs/blob8 empty
1198 refs/myblobs/first not empty
1200 git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \
1201 refs/myblobs/ >actual &&
1202 test_cmp expected actual
1205 test_expect_success
'%(raw) with --python must fail' '
1206 test_must_fail git for-each-ref --format="%(raw)" --python
1209 test_expect_success
'%(raw) with --tcl must fail' '
1210 test_must_fail git for-each-ref --format="%(raw)" --tcl
1213 test_expect_success
'%(raw) with --perl' '
1214 git for-each-ref --format="\$name= %(raw);
1215 print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual &&
1217 git for-each-ref --format="\$name= %(raw);
1218 print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual &&
1220 git for-each-ref --format="\$name= %(raw);
1221 print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual &&
1223 git for-each-ref --format="\$name= %(raw);
1224 print \"\$name\"" refs/myblobs/first --perl | perl >actual &&
1226 git cat-file tree refs/mytrees/first > expected &&
1227 git for-each-ref --format="\$name= %(raw);
1228 print \"\$name\"" refs/mytrees/first --perl | perl >actual &&
1232 test_expect_success
'%(raw) with --shell must fail' '
1233 test_must_fail git for-each-ref --format="%(raw)" --shell
1236 test_expect_success
'%(raw) with --shell and --sort=raw must fail' '
1237 test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell
1240 test_expect_success
'%(raw:size) with --shell' '
1241 git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect &&
1242 git for-each-ref --format="%(raw:size)" --shell >actual &&
1243 test_cmp expect actual
1246 test_expect_success
'for-each-ref --format compare with cat-file --batch' '
1247 git rev-parse refs/mytrees/first | git cat-file --batch >expected &&
1248 git for-each-ref --format="%(objectname) %(objecttype) %(objectsize)
1249 %(raw)" refs/mytrees/first >actual &&
1250 test_cmp expected actual
1253 test_expect_success
'verify sorts with contents:size' '
1254 cat >expect <<-\EOF &&
1257 refs/heads/ambiguous
1259 git for-each-ref --format="%(refname)" \
1260 --sort=contents:size refs/heads/ >actual &&
1261 test_cmp expect actual
1264 test_expect_success
'set up multiple-sort tags' '
1265 for when in 100000 200000
1267 for email in user1 user2
1269 for ref in ref1 ref2
1271 GIT_COMMITTER_DATE="@$when +0000" \
1272 GIT_COMMITTER_EMAIL="$email@example.com" \
1273 git tag -m "tag $ref-$when-$email" \
1274 multi-$ref-$when-$email || return 1
1280 test_expect_success
'Verify sort with multiple keys' '
1281 cat >expected <<-\EOF &&
1282 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1283 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1284 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1285 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1286 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1287 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1288 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1289 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1292 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1294 --sort=taggeremail \
1296 "refs/tags/multi-*" >actual &&
1297 test_cmp expected actual
1300 test_expect_success
'equivalent sorts fall back on refname' '
1301 cat >expected <<-\EOF &&
1302 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1303 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1304 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1305 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1306 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1307 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1308 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1309 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1312 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1314 "refs/tags/multi-*" >actual &&
1315 test_cmp expected actual
1318 test_expect_success
'--no-sort cancels the previous sort keys' '
1319 cat >expected <<-\EOF &&
1320 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
1321 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
1322 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
1323 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
1324 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
1325 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
1326 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
1327 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
1330 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
1332 --sort=taggeremail \
1335 "refs/tags/multi-*" >actual &&
1336 test_cmp expected actual
1339 test_expect_success
'--no-sort without subsequent --sort prints expected refs' '
1340 cat >expected <<-\EOF &&
1341 refs/tags/multi-ref1-100000-user1
1342 refs/tags/multi-ref1-100000-user2
1343 refs/tags/multi-ref1-200000-user1
1344 refs/tags/multi-ref1-200000-user2
1345 refs/tags/multi-ref2-100000-user1
1346 refs/tags/multi-ref2-100000-user2
1347 refs/tags/multi-ref2-200000-user1
1348 refs/tags/multi-ref2-200000-user2
1351 # Sort the results with `sort` for a consistent comparison against
1354 --format="%(refname)" \
1356 "refs/tags/multi-*" | sort >actual &&
1357 test_cmp expected actual
1360 test_expect_success
'set up custom date sorting' '
1362 # - Wed Feb 07 2024 21:34:20 +0000
1363 # - Tue Dec 14 1999 00:05:22 +0000
1364 # - Fri Jun 04 2021 11:26:51 +0000
1365 # - Mon Jan 22 2007 16:44:01 GMT+0000
1367 for when in 1707341660 945129922 1622806011 1169484241
1369 GIT_COMMITTER_DATE="@$when +0000" \
1370 GIT_COMMITTER_EMAIL="user@example.com" \
1371 git tag -m "tag $when" custom-dates-$i &&
1372 i=$(($i+1)) || return 1
1376 test_expect_success
'sort by date defaults to full timestamp' '
1377 cat >expected <<-\EOF &&
1378 945129922 refs/tags/custom-dates-2
1379 1169484241 refs/tags/custom-dates-4
1380 1622806011 refs/tags/custom-dates-3
1381 1707341660 refs/tags/custom-dates-1
1385 --format="%(creatordate:unix) %(refname)" \
1386 --sort=creatordate \
1387 "refs/tags/custom-dates-*" >actual &&
1388 test_cmp expected actual
1391 test_expect_success
'sort by custom date format' '
1392 cat >expected <<-\EOF &&
1393 00:05:22 refs/tags/custom-dates-2
1394 11:26:51 refs/tags/custom-dates-3
1395 16:44:01 refs/tags/custom-dates-4
1396 21:34:20 refs/tags/custom-dates-1
1400 --format="%(creatordate:format:%H:%M:%S) %(refname)" \
1401 --sort="creatordate:format:%H:%M:%S" \
1402 "refs/tags/custom-dates-*" >actual &&
1403 test_cmp expected actual
1406 test_expect_success
'do not dereference NULL upon %(HEAD) on unborn branch' '
1407 test_when_finished "git checkout main" &&
1408 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
1409 sed -e "s/^\* / /" actual >expect &&
1410 git checkout --orphan orphaned-branch &&
1411 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
1412 test_cmp expect actual
1416 Reviewed-by: A U Thor <author@example.com>
1417 Signed-off-by: A U Thor <author@example.com>
1418 [ v2 updated patch description ]
1420 <author@example.com>
1424 perl
-0pe 's/\n\s+/ /g'
1427 test_expect_success
'set up trailers for next test' '
1428 echo "Some contents" > two &&
1430 git commit -F - <<-EOF
1431 trailers: this commit message has trailers
1433 Some message contents
1439 test_trailer_option
() {
1442 test_expect_success
"$title" '
1443 git for-each-ref --format="%($option)" refs/heads/main >actual &&
1444 test_cmp expect actual &&
1445 git for-each-ref --format="%(contents:$option)" refs/heads/main >actual &&
1446 test_cmp expect actual
1450 test_trailer_option
'%(trailers:unfold) unfolds trailers' \
1451 'trailers:unfold' <<-EOF
1456 test_trailer_option
'%(trailers:only) shows only "key: value" trailers' \
1457 'trailers:only' <<-EOF
1458 $(grep -v patch.description <trailers)
1462 test_trailer_option
'%(trailers:only=no,only=true) shows only "key: value" trailers' \
1463 'trailers:only=no,only=true' <<-EOF
1464 $(grep -v patch.description <trailers)
1468 test_trailer_option
'%(trailers:only=yes) shows only "key: value" trailers' \
1469 'trailers:only=yes' <<-EOF
1470 $(grep -v patch.description <trailers)
1474 test_trailer_option
'%(trailers:only=no) shows all trailers' \
1475 'trailers:only=no' <<-EOF
1480 test_trailer_option
'%(trailers:only) and %(trailers:unfold) work together' \
1481 'trailers:only,unfold' <<-EOF
1482 $(grep -v patch.description <trailers | unfold)
1486 test_trailer_option
'%(trailers:unfold) and %(trailers:only) work together' \
1487 'trailers:unfold,only' <<-EOF
1488 $(grep -v patch.description <trailers | unfold)
1492 test_trailer_option
'%(trailers:key=foo) shows that trailer' \
1493 'trailers:key=Signed-off-by' <<-EOF
1494 Signed-off-by: A U Thor <author@example.com>
1498 test_trailer_option
'%(trailers:key=foo) is case insensitive' \
1499 'trailers:key=SiGned-oFf-bY' <<-EOF
1500 Signed-off-by: A U Thor <author@example.com>
1504 test_trailer_option
'%(trailers:key=foo:) trailing colon also works' \
1505 'trailers:key=Signed-off-by:' <<-EOF
1506 Signed-off-by: A U Thor <author@example.com>
1510 test_trailer_option
'%(trailers:key=foo) multiple keys' \
1511 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF
1512 Reviewed-by: A U Thor <author@example.com>
1513 Signed-off-by: A U Thor <author@example.com>
1517 test_trailer_option
'%(trailers:key=nonexistent) becomes empty' \
1518 'trailers:key=Shined-off-by:' <<-EOF
1522 test_trailer_option
'%(trailers:key=foo) handles multiple lines even if folded' \
1523 'trailers:key=Acked-by' <<-EOF
1524 $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by)
1528 test_trailer_option
'%(trailers:key=foo,unfold) properly unfolds' \
1529 'trailers:key=Signed-Off-by,unfold' <<-EOF
1530 $(unfold <trailers | grep Signed-off-by)
1534 test_trailer_option
'%(trailers:key=foo,only=no) also includes nontrailer lines' \
1535 'trailers:key=Signed-off-by,only=no' <<-EOF
1536 Signed-off-by: A U Thor <author@example.com>
1537 $(grep patch.description <trailers)
1541 test_trailer_option
'%(trailers:key=foo,valueonly) shows only value' \
1542 'trailers:key=Signed-off-by,valueonly' <<-EOF
1543 A U Thor <author@example.com>
1547 test_trailer_option
'%(trailers:separator) changes separator' \
1548 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1549 Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com>
1552 test_trailer_option
'%(trailers:key_value_separator) changes key-value separator' \
1553 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1554 Reviewed-by,A U Thor <author@example.com>
1555 Signed-off-by,A U Thor <author@example.com>
1559 test_trailer_option
'%(trailers:separator,key_value_separator) changes both separators' \
1560 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF
1561 Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com>
1564 test_expect_success
'multiple %(trailers) use their own options' '
1565 git tag -F - tag-with-trailers <<-\EOF &&
1573 t1="%(trailers:key=one,key_value_separator=W,separator=X)" &&
1574 t2="%(trailers:key=two,key_value_separator=Y,separator=Z)" &&
1575 git for-each-ref --format="$t1%0a$t2" refs/tags/tag-with-trailers >actual &&
1576 cat >expect <<-\EOF &&
1580 test_cmp expect actual
1583 test_failing_trailer_option
() {
1586 test_expect_success
"$title" '
1587 # error message cannot be checked under i18n
1588 test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual &&
1589 test_cmp expect actual &&
1590 test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual &&
1591 test_cmp expect actual
1595 test_failing_trailer_option
'%(trailers) rejects unknown trailers arguments' \
1596 'trailers:unsupported' <<-\EOF
1597 fatal: unknown %(trailers) argument: unsupported
1600 test_failing_trailer_option '%(trailers:key) without value is error' \
1601 'trailers:key' <<-\
EOF
1602 fatal: expected %(trailers:key=<value>)
1605 test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' '
1606 cat >expect <<-EOF &&
1607 fatal: unrecognized %(contents) argument: trailersonly
1609 test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual &&
1610 test_cmp expect actual
1613 test_expect_success 'basic atom: head contents:trailers' '
1614 git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual &&
1615 sanitize_pgp <actual >actual.clean &&
1616 # git for-each-ref ends with a blank line
1617 cat >expect <<-EOF &&
1621 test_cmp expect actual.clean
1624 test_expect_success 'basic atom: rest must fail' '
1625 test_must_fail git for-each-ref --format="%(rest)" refs/heads/main
1628 test_expect_success 'HEAD atom does not take arguments' '
1629 test_must_fail git for-each-ref --format="%(HEAD:foo)" 2>err &&
1630 echo "fatal: %(HEAD) does not take arguments" >expect &&
1634 test_expect_success 'subject atom rejects unknown arguments' '
1635 test_must_fail git for-each-ref --format="%(subject:foo)" 2>err &&
1636 echo "fatal: unrecognized %(subject) argument: foo" >expect &&
1640 test_expect_success 'refname atom rejects unknown arguments' '
1641 test_must_fail git for-each-ref --format="%(refname:foo)" 2>err &&
1642 echo "fatal: unrecognized %(refname) argument: foo" >expect &&
1646 test_expect_success 'trailer parsing not fooled by --- line' '
1647 git commit --allow-empty -F - <<-\EOF &&
1650 This is the body. The message has a "---" line which would confuse a
1651 message+patch parser. But here we know we have only a commit message,
1662 echo "trailer: right" &&
1665 git for-each-ref --format="%(trailers)" refs/heads/main >actual &&
1666 test_cmp expect actual
1669 test_expect_success 'Add symbolic ref for the following tests' '
1670 git symbolic-ref refs/heads/sym refs/heads/main
1677 test_expect_success 'Verify usage of %(symref) atom' '
1678 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
1679 test_cmp expected actual
1686 test_expect_success 'Verify usage of %(symref:short) atom' '
1687 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
1688 test_cmp expected actual
1696 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
1697 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
1698 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
1699 test_cmp expected actual &&
1701 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
1702 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
1703 test_cmp expected actual
1711 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
1712 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
1713 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
1714 test_cmp expected actual
1717 test_expect_success ':remotename and :remoteref' '
1718 git init remote-tests &&
1721 test_commit initial &&
1722 git branch -M main &&
1723 git remote add from fifth.coffee:blub &&
1724 git config branch.main.remote from &&
1725 git config branch.main.merge refs/heads/stable &&
1726 git remote add to southridge.audio:repo &&
1727 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
1728 git config branch.main.pushRemote to &&
1729 for pair in "%(upstream)=refs/remotes/from/stable" \
1730 "%(upstream:remotename)=from" \
1731 "%(upstream:remoteref)=refs/heads/stable" \
1732 "%(push)=refs/remotes/to/pushed/main" \
1733 "%(push:remotename)=to" \
1734 "%(push:remoteref)=refs/heads/pushed/main"
1736 echo "${pair#*=}" >expect &&
1737 git for-each-ref --format="${pair%=*}" \
1738 refs/heads/main >actual &&
1739 test_cmp expect actual || exit 1
1741 git branch push-simple &&
1742 git config branch.push-simple.pushRemote from &&
1743 actual="$(git for-each-ref \
1744 --format="%(push:remotename),%(push:remoteref)" \
1745 refs/heads/push-simple)" &&
1746 test from, = "$actual"
1750 test_expect_success 'for-each-ref --ignore-case ignores case' '
1751 git for-each-ref --format="%(refname)" refs/heads/MAIN >actual &&
1752 test_must_be_empty actual &&
1754 echo refs/heads/main >expect &&
1755 git for-each-ref --format="%(refname)" --ignore-case \
1756 refs/heads/MAIN >actual &&
1757 test_cmp expect actual
1760 test_expect_success 'for-each-ref --omit-empty works' '
1761 git for-each-ref --format="%(refname)" >actual &&
1762 test_line_count -gt 1 actual &&
1763 git for-each-ref --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual &&
1764 echo refs/heads/main >expect &&
1765 test_cmp expect actual
1768 test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
1769 # name refs numerically to avoid case-insensitive filesystem conflicts
1771 for email in a A b B
1773 for subject in a A b B
1775 GIT_COMMITTER_EMAIL="$email@example.com" \
1776 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
1781 git for-each-ref --ignore-case \
1782 --format="%(taggeremail) %(subject) %(refname)" \
1785 --sort=taggeremail \
1786 refs/tags/icase-* >actual &&
1787 cat >expect <<-\
EOF &&
1788 <a@example.com> tag a refs/tags/icase-00
1789 <a@example.com> tag A refs/tags/icase-01
1790 <A@example.com> tag a refs/tags/icase-04
1791 <A@example.com> tag A refs/tags/icase-05
1792 <a@example.com> tag b refs/tags/icase-02
1793 <a@example.com> tag B refs/tags/icase-03
1794 <A@example.com> tag b refs/tags/icase-06
1795 <A@example.com> tag B refs/tags/icase-07
1796 <b@example.com> tag a refs/tags/icase-08
1797 <b@example.com> tag A refs/tags/icase-09
1798 <B@example.com> tag a refs/tags/icase-12
1799 <B@example.com> tag A refs/tags/icase-13
1800 <b@example.com> tag b refs/tags/icase-10
1801 <b@example.com> tag B refs/tags/icase-11
1802 <B@example.com> tag b refs/tags/icase-14
1803 <B@example.com> tag B refs/tags/icase-15
1805 test_cmp expect actual
1808 test_expect_success 'for-each-ref reports broken tags' '
1809 git tag -m "good tag" broken-tag-good HEAD &&
1810 git cat-file tag broken-tag-good >good &&
1811 sed s/commit/blob/ <good >bad &&
1812 bad=$(git hash-object -w -t tag bad) &&
1813 git update-ref refs/tags/broken-tag-bad $bad &&
1814 test_must_fail git for-each-ref --format="%(*objectname)" \
1815 refs/tags/broken-tag-*
1818 test_expect_success 'set up tag with signature and no blank lines' '
1819 git tag -F - fake-sig-no-blanks
<<-\EOF
1821 -----BEGIN PGP SIGNATURE-----
1822 not a real signature, but we just care about the
1823 subject/body parsing. It is important here that
1824 there are no blank lines in the signature.
1825 -----END PGP SIGNATURE-----
1829 test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject'
1830 test_atom refs/tags/fake-sig-no-blanks contents:body ''
1831 test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig"
1833 test_expect_success 'set up tag with CRLF signature' '
1836 -----BEGIN PGP SIGNATURE-----
1838 not a real signature, but we just care about
1839 the subject/body parsing. It is important here
1840 that there is a blank line separating this
1841 from the signature header.
1842 -----END PGP SIGNATURE-----
1844 git tag -F - --cleanup=verbatim fake-sig-crlf
1847 test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject
'
1848 test_atom refs/tags/fake-sig-crlf contents:body ''
1850 # CRLF is retained in the signature, so we have to pass our expected value
1851 # through append_cr. But test_atom requires a shell string, which means command
1852 # substitution, and the shell will strip trailing newlines from the output of
1853 # the substitution. Hack around it by adding and then removing a dummy line.
1854 sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)"
1855 sig_crlf=${sig_crlf%dummy}
1856 test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf"
1858 test_expect_success 'set up tag with signature and trailers
' '
1859 git tag
-F - fake-sig-trailer
<<-\EOF
1865 -----BEGIN PGP SIGNATURE-----
1867 not a real signature, but we just care about the
1868 subject/body/trailer parsing.
1869 -----END PGP SIGNATURE-----
1873 # use "separator=" here to suppress the terminating newline
1874 test_atom refs/tags/fake-sig-trailer trailers:separator= 'My-Trailer: foo'
1876 test_expect_success 'git for-each-ref --stdin: empty' '
1878 git for-each-ref --format="%(refname)" --stdin <in >actual &&
1879 git for-each-ref --format="%(refname)" >expect &&
1880 test_cmp expect actual
1883 test_expect_success 'git for-each-ref --stdin: fails if extra args' '
1885 test_must_fail git for-each-ref --format="%(refname)" \
1886 --stdin refs/heads/extra <in 2>err &&
1887 grep "unknown arguments supplied with --stdin" err
1890 test_expect_success 'git for-each-ref --stdin: matches' '
1896 cat >expect <<-EOF &&
1897 refs/heads/ambiguous
1898 refs/tags/multi-ref1-100000-user1
1899 refs/tags/multi-ref1-100000-user2
1900 refs/tags/multi-ref1-200000-user1
1901 refs/tags/multi-ref1-200000-user2
1902 refs/tags/multi-ref2-100000-user1
1903 refs/tags/multi-ref2-100000-user2
1904 refs/tags/multi-ref2-200000-user1
1905 refs/tags/multi-ref2-200000-user2
1909 git for-each-ref --format="%(refname)" --stdin <in >actual &&
1910 test_cmp expect actual
1913 test_expect_success 'git for-each-ref with non-existing refs' '
1915 refs/heads/this-ref-does-not-exist
1919 git for-each-ref --format="%(refname)" --stdin <in >actual &&
1920 test_must_be_empty actual &&
1922 xargs git for-each-ref --format="%(refname)" <in >actual &&
1923 test_must_be_empty actual
1926 test_expect_success 'git for-each-ref with nested tags' '
1927 git tag -am "Normal tag" nested/base HEAD &&
1928 git tag -am "Nested tag" nested/nest1 refs/tags/nested/base &&
1929 git tag -am "Double nested tag" nested/nest2 refs/tags/nested/nest1 &&
1931 head_oid="$(git rev-parse HEAD)" &&
1932 base_tag_oid="$(git rev-parse refs/tags/nested/base)" &&
1933 nest1_tag_oid="$(git rev-parse refs/tags/nested/nest1)" &&
1934 nest2_tag_oid="$(git rev-parse refs/tags/nested/nest2)" &&
1936 cat >expect <<-EOF &&
1937 refs/tags/nested/base $base_tag_oid tag $head_oid commit
1938 refs/tags/nested/nest1 $nest1_tag_oid tag $head_oid commit
1939 refs/tags/nested/nest2 $nest2_tag_oid tag $head_oid commit
1943 --format="%(refname) %(objectname) %(objecttype) %(*objectname) %(*objecttype)" \
1944 refs/tags/nested/ >actual &&
1945 test_cmp expect actual
1948 test_expect_success 'is-base atom with non-commits' '
1949 git for-each-ref --format="%(is-base:HEAD) %(refname)" >out 2>err &&
1950 grep "(HEAD) refs/heads/main" out &&
1952 test_line_count = 2 err &&
1953 grep "error: object .* is a commit, not a blob" err &&
1954 grep "error: bad tag pointer to" err
1957 GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
1958 TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)"
1960 test_expect_success GPG 'setup for signature atom using gpg' '
1961 git checkout -b signed &&
1963 test_when_finished "test_unconfig commit.gpgSign" &&
1968 git commit -S -m "file: 1" &&
1969 git tag first-signed &&
1973 git commit -a -m "file: 2" &&
1974 git tag second-unsigned &&
1976 git config commit.gpgSign 1 &&
1979 git commit -a --no-gpg-sign -m "file: 3" &&
1980 git tag third-unsigned &&
1983 git rebase -f HEAD^^ && git tag second-signed HEAD^ &&
1984 git tag third-signed &&
1988 git commit -a -SB7227189 -m "file: 4" &&
1989 git tag fourth-signed &&
1993 git commit -a --no-gpg-sign -m "file: 5" &&
1994 git tag fifth-unsigned &&
1998 git commit -a --no-gpg-sign -m "file: 6" &&
2001 git rebase -f HEAD^^ &&
2002 git tag fifth-signed HEAD^ &&
2003 git tag sixth-signed &&
2007 git commit -a --no-gpg-sign -m "file: 7" &&
2008 git tag seventh-unsigned
2011 test_expect_success GPGSSH 'setup for signature atom using ssh' '
2012 test_when_finished "test_unconfig gpg.format user.signingkey" &&
2014 test_config gpg.format ssh &&
2015 test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" &&
2019 git commit -S -m "file: 8" &&
2020 git tag eighth-signed-ssh
2023 test_expect_success GPG2 'bare signature atom' '
2024 git verify-commit first-signed 2>expect &&
2026 git for-each-ref refs/tags/first-signed \
2027 --format="%(signature)" >actual &&
2028 test_cmp expect actual
2031 test_expect_success GPG 'show good signature with custom format' '
2032 git verify-commit first-signed &&
2033 cat >expect <<-\
EOF &&
2036 C O Mitter <committer@example.com>
2037 73D758744BE721698EC54E8713B6F51ECDDE430D
2038 73D758744BE721698EC54E8713B6F51ECDDE430D
2040 git for-each-ref refs/tags/first-signed \
2041 --format="$GRADE_FORMAT" >actual &&
2042 test_cmp expect actual
2044 test_expect_success GPGSSH 'show good signature with custom format with ssh' '
2045 test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" &&
2046 FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") &&
2047 cat >expect.tmpl <<-\EOF &&
2050 principal with number 1
2054 sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect &&
2055 git for-each-ref refs/tags/eighth-signed-ssh \
2056 --format="$GRADE_FORMAT" >actual &&
2057 test_cmp expect actual
2060 test_expect_success GPG 'signature atom with grade option and bad signature' '
2061 git cat-file commit third-signed >raw &&
2062 sed -e "s/^file: 3/file: 3 forged/" raw >forged1 &&
2063 FORGED1=$(git hash-object -w -t commit forged1) &&
2064 git update-ref refs/tags/third-signed "$FORGED1" &&
2065 test_must_fail git verify-commit "$FORGED1" &&
2067 cat >expect <<-\EOF &&
2070 C O Mitter <committer@example.com>
2074 git for-each-ref refs/tags/third-signed \
2075 --format="$GRADE_FORMAT" >actual &&
2076 test_cmp expect actual
2079 test_expect_success GPG 'show untrusted signature with custom format' '
2080 cat >expect <<-\EOF &&
2083 Eris Discordia <discord@example.net>
2084 F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
2085 D4BE22311AD3131E5EDA29A461092E85B7227189
2087 git for-each-ref refs/tags/fourth-signed \
2088 --format="$GRADE_FORMAT" >actual &&
2089 test_cmp expect actual
2092 test_expect_success GPG 'show untrusted signature with undefined trust level' '
2093 cat >expect <<-\EOF &&
2096 Eris Discordia <discord@example.net>
2097 F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7
2098 D4BE22311AD3131E5EDA29A461092E85B7227189
2100 git for-each-ref refs/tags/fourth-signed \
2101 --format="$TRUSTLEVEL_FORMAT" >actual &&
2102 test_cmp expect actual
2105 test_expect_success GPG 'show untrusted signature with ultimate trust level' '
2106 cat >expect <<-\EOF &&
2109 C O Mitter <committer@example.com>
2110 73D758744BE721698EC54E8713B6F51ECDDE430D
2111 73D758744BE721698EC54E8713B6F51ECDDE430D
2113 git for-each-ref refs/tags/sixth-signed \
2114 --format="$TRUSTLEVEL_FORMAT" >actual &&
2115 test_cmp expect actual
2118 test_expect_success GPG 'show unknown signature with custom format' '
2119 cat >expect <<-\EOF &&
2126 GNUPGHOME="$GNUPGHOME_NOT_USED" git for-each-ref \
2127 refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual &&
2128 test_cmp expect actual
2131 test_expect_success GPG 'show lack of signature with custom format' '
2132 cat >expect <<-\EOF &&
2139 git for-each-ref refs/tags/seventh-unsigned \
2140 --format="$GRADE_FORMAT" >actual &&
2141 test_cmp expect actual