Fourth batch
[git/raj.git] / t / t6300-for-each-ref.sh
bloba83579fbdf1c202979be589bec71ff2a886a03bf
1 #!/bin/sh
3 # Copyright (c) 2007 Andy Parkins
6 test_description='for-each-ref test'
8 . ./test-lib.sh
9 . "$TEST_DIRECTORY"/lib-gpg.sh
10 . "$TEST_DIRECTORY"/lib-terminal.sh
12 # Mon Jul 3 23:18:43 2006 +0000
13 datestamp=1151968723
14 setdate_and_increment () {
15 GIT_COMMITTER_DATE="$datestamp +0200"
16 datestamp=$(expr "$datestamp" + 1)
17 GIT_AUTHOR_DATE="$datestamp +0200"
18 datestamp=$(expr "$datestamp" + 1)
19 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
22 test_expect_success setup '
23 test_oid_cache <<-EOF &&
24 disklen sha1:138
25 disklen sha256:154
26 EOF
27 setdate_and_increment &&
28 echo "Using $datestamp" > one &&
29 git add one &&
30 git commit -m "Initial" &&
31 setdate_and_increment &&
32 git tag -a -m "Tagging at $datestamp" testtag &&
33 git update-ref refs/remotes/origin/master master &&
34 git remote add origin nowhere &&
35 git config branch.master.remote origin &&
36 git config branch.master.merge refs/heads/master &&
37 git remote add myfork elsewhere &&
38 git config remote.pushdefault myfork &&
39 git config push.default current
42 test_atom() {
43 case "$1" in
44 head) ref=refs/heads/master ;;
45 tag) ref=refs/tags/testtag ;;
46 sym) ref=refs/heads/sym ;;
47 *) ref=$1 ;;
48 esac
49 printf '%s\n' "$3" >expected
50 test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
51 git for-each-ref --format='%($2)' $ref >actual &&
52 sanitize_pgp <actual >actual.clean &&
53 test_cmp expected actual.clean
55 # Automatically test "contents:size" atom after testing "contents"
56 if test "$2" = "contents"
57 then
58 case $(git cat-file -t "$ref") in
59 tag)
60 # We cannot use $3 as it expects sanitize_pgp to run
61 expect=$(git cat-file tag $ref | tail -n +6 | wc -c) ;;
62 tree | blob)
63 expect='' ;;
64 commit)
65 expect=$(printf '%s' "$3" | wc -c) ;;
66 esac
67 # Leave $expect unquoted to lose possible leading whitespaces
68 echo $expect >expected
69 test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" '
70 git for-each-ref --format="%(contents:size)" "$ref" >actual &&
71 test_cmp expected actual
76 hexlen=$(test_oid hexsz)
77 disklen=$(test_oid disklen)
79 test_atom head refname refs/heads/master
80 test_atom head refname: refs/heads/master
81 test_atom head refname:short master
82 test_atom head refname:lstrip=1 heads/master
83 test_atom head refname:lstrip=2 master
84 test_atom head refname:lstrip=-1 master
85 test_atom head refname:lstrip=-2 heads/master
86 test_atom head refname:rstrip=1 refs/heads
87 test_atom head refname:rstrip=2 refs
88 test_atom head refname:rstrip=-1 refs
89 test_atom head refname:rstrip=-2 refs/heads
90 test_atom head refname:strip=1 heads/master
91 test_atom head refname:strip=2 master
92 test_atom head refname:strip=-1 master
93 test_atom head refname:strip=-2 heads/master
94 test_atom head upstream refs/remotes/origin/master
95 test_atom head upstream:short origin/master
96 test_atom head upstream:lstrip=2 origin/master
97 test_atom head upstream:lstrip=-2 origin/master
98 test_atom head upstream:rstrip=2 refs/remotes
99 test_atom head upstream:rstrip=-2 refs/remotes
100 test_atom head upstream:strip=2 origin/master
101 test_atom head upstream:strip=-2 origin/master
102 test_atom head push refs/remotes/myfork/master
103 test_atom head push:short myfork/master
104 test_atom head push:lstrip=1 remotes/myfork/master
105 test_atom head push:lstrip=-1 master
106 test_atom head push:rstrip=1 refs/remotes/myfork
107 test_atom head push:rstrip=-1 refs
108 test_atom head push:strip=1 remotes/myfork/master
109 test_atom head push:strip=-1 master
110 test_atom head objecttype commit
111 test_atom head objectsize $((131 + hexlen))
112 test_atom head objectsize:disk $disklen
113 test_atom head deltabase $ZERO_OID
114 test_atom head objectname $(git rev-parse refs/heads/master)
115 test_atom head objectname:short $(git rev-parse --short refs/heads/master)
116 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
117 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
118 test_atom head tree $(git rev-parse refs/heads/master^{tree})
119 test_atom head parent ''
120 test_atom head numparent 0
121 test_atom head object ''
122 test_atom head type ''
123 test_atom head '*objectname' ''
124 test_atom head '*objecttype' ''
125 test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
126 test_atom head authorname 'A U Thor'
127 test_atom head authoremail '<author@example.com>'
128 test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
129 test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
130 test_atom head committername 'C O Mitter'
131 test_atom head committeremail '<committer@example.com>'
132 test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
133 test_atom head tag ''
134 test_atom head tagger ''
135 test_atom head taggername ''
136 test_atom head taggeremail ''
137 test_atom head taggerdate ''
138 test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
139 test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
140 test_atom head subject 'Initial'
141 test_atom head contents:subject 'Initial'
142 test_atom head body ''
143 test_atom head contents:body ''
144 test_atom head contents:signature ''
145 test_atom head contents 'Initial
147 test_atom head HEAD '*'
149 test_atom tag refname refs/tags/testtag
150 test_atom tag refname:short testtag
151 test_atom tag upstream ''
152 test_atom tag push ''
153 test_atom tag objecttype tag
154 test_atom tag objectsize $((114 + hexlen))
155 test_atom tag objectsize:disk $disklen
156 test_atom tag '*objectsize:disk' $disklen
157 test_atom tag deltabase $ZERO_OID
158 test_atom tag '*deltabase' $ZERO_OID
159 test_atom tag objectname $(git rev-parse refs/tags/testtag)
160 test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
161 test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
162 test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
163 test_atom tag tree ''
164 test_atom tag parent ''
165 test_atom tag numparent ''
166 test_atom tag object $(git rev-parse refs/tags/testtag^0)
167 test_atom tag type 'commit'
168 test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{})
169 test_atom tag '*objecttype' 'commit'
170 test_atom tag author ''
171 test_atom tag authorname ''
172 test_atom tag authoremail ''
173 test_atom tag authordate ''
174 test_atom tag committer ''
175 test_atom tag committername ''
176 test_atom tag committeremail ''
177 test_atom tag committerdate ''
178 test_atom tag tag 'testtag'
179 test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
180 test_atom tag taggername 'C O Mitter'
181 test_atom tag taggeremail '<committer@example.com>'
182 test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
183 test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
184 test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
185 test_atom tag subject 'Tagging at 1151968727'
186 test_atom tag contents:subject 'Tagging at 1151968727'
187 test_atom tag body ''
188 test_atom tag contents:body ''
189 test_atom tag contents:signature ''
190 test_atom tag contents 'Tagging at 1151968727
192 test_atom tag HEAD ' '
194 test_expect_success 'Check invalid atoms names are errors' '
195 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
198 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
199 git for-each-ref --format="%(authordate)" refs/heads &&
200 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
201 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
202 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
205 test_expect_success 'Check valid format specifiers for date fields' '
206 git for-each-ref --format="%(authordate:default)" refs/heads &&
207 git for-each-ref --format="%(authordate:relative)" refs/heads &&
208 git for-each-ref --format="%(authordate:short)" refs/heads &&
209 git for-each-ref --format="%(authordate:local)" refs/heads &&
210 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
211 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
214 test_expect_success 'Check invalid format specifiers are errors' '
215 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
218 test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
219 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
220 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
221 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
224 test_date () {
225 f=$1 &&
226 committer_date=$2 &&
227 author_date=$3 &&
228 tagger_date=$4 &&
229 cat >expected <<-EOF &&
230 'refs/heads/master' '$committer_date' '$author_date'
231 'refs/tags/testtag' '$tagger_date'
234 git for-each-ref --shell \
235 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
236 refs/heads &&
237 git for-each-ref --shell \
238 --format="%(refname) %(taggerdate${f:+:$f})" \
239 refs/tags
240 ) >actual &&
241 test_cmp expected actual
244 test_expect_success 'Check unformatted date fields output' '
245 test_date "" \
246 "Tue Jul 4 01:18:43 2006 +0200" \
247 "Tue Jul 4 01:18:44 2006 +0200" \
248 "Tue Jul 4 01:18:45 2006 +0200"
251 test_expect_success 'Check format "default" formatted date fields output' '
252 test_date default \
253 "Tue Jul 4 01:18:43 2006 +0200" \
254 "Tue Jul 4 01:18:44 2006 +0200" \
255 "Tue Jul 4 01:18:45 2006 +0200"
258 test_expect_success 'Check format "default-local" date fields output' '
259 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"
262 # Don't know how to do relative check because I can't know when this script
263 # is going to be run and can't fake the current time to git, and hence can't
264 # provide expected output. Instead, I'll just make sure that "relative"
265 # doesn't exit in error
266 test_expect_success 'Check format "relative" date fields output' '
267 f=relative &&
268 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
269 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
272 # We just check that this is the same as "relative" for now.
273 test_expect_success 'Check format "relative-local" date fields output' '
274 test_date relative-local \
275 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
276 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
277 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
280 test_expect_success 'Check format "short" date fields output' '
281 test_date short 2006-07-04 2006-07-04 2006-07-04
284 test_expect_success 'Check format "short-local" date fields output' '
285 test_date short-local 2006-07-03 2006-07-03 2006-07-03
288 test_expect_success 'Check format "local" date fields output' '
289 test_date local \
290 "Mon Jul 3 23:18:43 2006" \
291 "Mon Jul 3 23:18:44 2006" \
292 "Mon Jul 3 23:18:45 2006"
295 test_expect_success 'Check format "iso8601" date fields output' '
296 test_date iso8601 \
297 "2006-07-04 01:18:43 +0200" \
298 "2006-07-04 01:18:44 +0200" \
299 "2006-07-04 01:18:45 +0200"
302 test_expect_success 'Check format "iso8601-local" date fields output' '
303 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"
306 test_expect_success 'Check format "rfc2822" date fields output' '
307 test_date rfc2822 \
308 "Tue, 4 Jul 2006 01:18:43 +0200" \
309 "Tue, 4 Jul 2006 01:18:44 +0200" \
310 "Tue, 4 Jul 2006 01:18:45 +0200"
313 test_expect_success 'Check format "rfc2822-local" date fields output' '
314 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"
317 test_expect_success 'Check format "raw" date fields output' '
318 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
321 test_expect_success 'Check format "raw-local" date fields output' '
322 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
325 test_expect_success 'Check format of strftime date fields' '
326 echo "my date is 2006-07-04" >expected &&
327 git for-each-ref \
328 --format="%(authordate:format:my date is %Y-%m-%d)" \
329 refs/heads >actual &&
330 test_cmp expected actual
333 test_expect_success 'Check format of strftime-local date fields' '
334 echo "my date is 2006-07-03" >expected &&
335 git for-each-ref \
336 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
337 refs/heads >actual &&
338 test_cmp expected actual
341 test_expect_success 'exercise strftime with odd fields' '
342 echo >expected &&
343 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
344 test_cmp expected actual &&
345 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
346 echo $long >expected &&
347 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
348 test_cmp expected actual
351 cat >expected <<\EOF
352 refs/heads/master
353 refs/remotes/origin/master
354 refs/tags/testtag
357 test_expect_success 'Verify ascending sort' '
358 git for-each-ref --format="%(refname)" --sort=refname >actual &&
359 test_cmp expected actual
363 cat >expected <<\EOF
364 refs/tags/testtag
365 refs/remotes/origin/master
366 refs/heads/master
369 test_expect_success 'Verify descending sort' '
370 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
371 test_cmp expected actual
374 cat >expected <<\EOF
375 refs/tags/testtag
376 refs/tags/testtag-2
379 test_expect_success 'exercise patterns with prefixes' '
380 git tag testtag-2 &&
381 test_when_finished "git tag -d testtag-2" &&
382 git for-each-ref --format="%(refname)" \
383 refs/tags/testtag refs/tags/testtag-2 >actual &&
384 test_cmp expected actual
387 cat >expected <<\EOF
388 refs/tags/testtag
389 refs/tags/testtag-2
392 test_expect_success 'exercise glob patterns with prefixes' '
393 git tag testtag-2 &&
394 test_when_finished "git tag -d testtag-2" &&
395 git for-each-ref --format="%(refname)" \
396 refs/tags/testtag "refs/tags/testtag-*" >actual &&
397 test_cmp expected actual
400 cat >expected <<\EOF
401 'refs/heads/master'
402 'refs/remotes/origin/master'
403 'refs/tags/testtag'
406 test_expect_success 'Quoting style: shell' '
407 git for-each-ref --shell --format="%(refname)" >actual &&
408 test_cmp expected actual
411 test_expect_success 'Quoting style: perl' '
412 git for-each-ref --perl --format="%(refname)" >actual &&
413 test_cmp expected actual
416 test_expect_success 'Quoting style: python' '
417 git for-each-ref --python --format="%(refname)" >actual &&
418 test_cmp expected actual
421 cat >expected <<\EOF
422 "refs/heads/master"
423 "refs/remotes/origin/master"
424 "refs/tags/testtag"
427 test_expect_success 'Quoting style: tcl' '
428 git for-each-ref --tcl --format="%(refname)" >actual &&
429 test_cmp expected actual
432 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
433 test_expect_success "more than one quoting style: $i" "
434 test_must_fail git for-each-ref $i 2>err &&
435 grep '^error: more than one quoting style' err
437 done
439 test_expect_success 'setup for upstream:track[short]' '
440 test_commit two
443 test_atom head upstream:track '[ahead 1]'
444 test_atom head upstream:trackshort '>'
445 test_atom head upstream:track,nobracket 'ahead 1'
446 test_atom head upstream:nobracket,track 'ahead 1'
448 test_expect_success 'setup for push:track[short]' '
449 test_commit third &&
450 git update-ref refs/remotes/myfork/master master &&
451 git reset master~1
454 test_atom head push:track '[behind 1]'
455 test_atom head push:trackshort '<'
457 test_expect_success 'Check that :track[short] cannot be used with other atoms' '
458 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
459 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
462 test_expect_success 'Check that :track[short] works when upstream is invalid' '
463 cat >expected <<-\EOF &&
464 [gone]
467 test_when_finished "git config branch.master.merge refs/heads/master" &&
468 git config branch.master.merge refs/heads/does-not-exist &&
469 git for-each-ref \
470 --format="%(upstream:track)$LF%(upstream:trackshort)" \
471 refs/heads >actual &&
472 test_cmp expected actual
475 test_expect_success 'Check for invalid refname format' '
476 test_must_fail git for-each-ref --format="%(refname:INVALID)"
479 test_expect_success 'set up color tests' '
480 cat >expected.color <<-EOF &&
481 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
482 $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET>
483 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
484 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
485 $(git rev-parse --short refs/tags/third) <GREEN>third<RESET>
486 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
488 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
489 color_format="%(objectname:short) %(color:green)%(refname:short)"
492 test_expect_success TTY '%(color) shows color with a tty' '
493 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
494 test_decode_color <actual.raw >actual &&
495 test_cmp expected.color actual
498 test_expect_success '%(color) does not show color without tty' '
499 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
500 test_cmp expected.bare actual
503 test_expect_success '--color can override tty check' '
504 git for-each-ref --color --format="$color_format" >actual.raw &&
505 test_decode_color <actual.raw >actual &&
506 test_cmp expected.color actual
509 test_expect_success 'color.ui=always does not override tty check' '
510 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
511 test_cmp expected.bare actual
514 cat >expected <<\EOF
515 heads/master
516 tags/master
519 test_expect_success 'Check ambiguous head and tag refs (strict)' '
520 git config --bool core.warnambiguousrefs true &&
521 git checkout -b newtag &&
522 echo "Using $datestamp" > one &&
523 git add one &&
524 git commit -m "Branch" &&
525 setdate_and_increment &&
526 git tag -m "Tagging at $datestamp" master &&
527 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
528 test_cmp expected actual
531 cat >expected <<\EOF
532 heads/master
533 master
536 test_expect_success 'Check ambiguous head and tag refs (loose)' '
537 git config --bool core.warnambiguousrefs false &&
538 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
539 test_cmp expected actual
542 cat >expected <<\EOF
543 heads/ambiguous
544 ambiguous
547 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
548 git checkout master &&
549 git tag ambiguous testtag^0 &&
550 git branch ambiguous testtag^0 &&
551 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
552 test_cmp expected actual
555 test_expect_success 'create tag without tagger' '
556 git tag -a -m "Broken tag" taggerless &&
557 git tag -f taggerless $(git cat-file tag taggerless |
558 sed -e "/^tagger /d" |
559 git hash-object --stdin -w -t tag)
562 test_atom refs/tags/taggerless type 'commit'
563 test_atom refs/tags/taggerless tag 'taggerless'
564 test_atom refs/tags/taggerless tagger ''
565 test_atom refs/tags/taggerless taggername ''
566 test_atom refs/tags/taggerless taggeremail ''
567 test_atom refs/tags/taggerless taggerdate ''
568 test_atom refs/tags/taggerless committer ''
569 test_atom refs/tags/taggerless committername ''
570 test_atom refs/tags/taggerless committeremail ''
571 test_atom refs/tags/taggerless committerdate ''
572 test_atom refs/tags/taggerless subject 'Broken tag'
574 test_expect_success 'an unusual tag with an incomplete line' '
576 git tag -m "bogo" bogo &&
577 bogo=$(git cat-file tag bogo) &&
578 bogo=$(printf "%s" "$bogo" | git mktag) &&
579 git tag -f bogo "$bogo" &&
580 git for-each-ref --format "%(body)" refs/tags/bogo
584 test_expect_success 'create tag with subject and body content' '
585 cat >>msg <<-\EOF &&
586 the subject line
588 first body line
589 second body line
591 git tag -F msg subject-body
593 test_atom refs/tags/subject-body subject 'the subject line'
594 test_atom refs/tags/subject-body body 'first body line
595 second body line
597 test_atom refs/tags/subject-body contents 'the subject line
599 first body line
600 second body line
603 test_expect_success 'create tag with multiline subject' '
604 cat >msg <<-\EOF &&
605 first subject line
606 second subject line
608 first body line
609 second body line
611 git tag -F msg multiline
613 test_atom refs/tags/multiline subject 'first subject line second subject line'
614 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
615 test_atom refs/tags/multiline body 'first body line
616 second body line
618 test_atom refs/tags/multiline contents:body 'first body line
619 second body line
621 test_atom refs/tags/multiline contents:signature ''
622 test_atom refs/tags/multiline contents 'first subject line
623 second subject line
625 first body line
626 second body line
629 test_expect_success GPG 'create signed tags' '
630 git tag -s -m "" signed-empty &&
631 git tag -s -m "subject line" signed-short &&
632 cat >msg <<-\EOF &&
633 subject line
635 body contents
637 git tag -s -F msg signed-long
640 sig='-----BEGIN PGP SIGNATURE-----
641 -----END PGP SIGNATURE-----
644 PREREQ=GPG
645 test_atom refs/tags/signed-empty subject ''
646 test_atom refs/tags/signed-empty contents:subject ''
647 test_atom refs/tags/signed-empty body "$sig"
648 test_atom refs/tags/signed-empty contents:body ''
649 test_atom refs/tags/signed-empty contents:signature "$sig"
650 test_atom refs/tags/signed-empty contents "$sig"
652 test_atom refs/tags/signed-short subject 'subject line'
653 test_atom refs/tags/signed-short contents:subject 'subject line'
654 test_atom refs/tags/signed-short body "$sig"
655 test_atom refs/tags/signed-short contents:body ''
656 test_atom refs/tags/signed-short contents:signature "$sig"
657 test_atom refs/tags/signed-short contents "subject line
658 $sig"
660 test_atom refs/tags/signed-long subject 'subject line'
661 test_atom refs/tags/signed-long contents:subject 'subject line'
662 test_atom refs/tags/signed-long body "body contents
663 $sig"
664 test_atom refs/tags/signed-long contents:body 'body contents
666 test_atom refs/tags/signed-long contents:signature "$sig"
667 test_atom refs/tags/signed-long contents "subject line
669 body contents
670 $sig"
672 test_expect_success 'set up refs pointing to tree and blob' '
673 git update-ref refs/mytrees/first refs/heads/master^{tree} &&
674 git update-ref refs/myblobs/first refs/heads/master:one
677 test_atom refs/mytrees/first subject ""
678 test_atom refs/mytrees/first contents:subject ""
679 test_atom refs/mytrees/first body ""
680 test_atom refs/mytrees/first contents:body ""
681 test_atom refs/mytrees/first contents:signature ""
682 test_atom refs/mytrees/first contents ""
684 test_atom refs/myblobs/first subject ""
685 test_atom refs/myblobs/first contents:subject ""
686 test_atom refs/myblobs/first body ""
687 test_atom refs/myblobs/first contents:body ""
688 test_atom refs/myblobs/first contents:signature ""
689 test_atom refs/myblobs/first contents ""
691 test_expect_success 'set up multiple-sort tags' '
692 for when in 100000 200000
694 for email in user1 user2
696 for ref in ref1 ref2
698 GIT_COMMITTER_DATE="@$when +0000" \
699 GIT_COMMITTER_EMAIL="$email@example.com" \
700 git tag -m "tag $ref-$when-$email" \
701 multi-$ref-$when-$email || return 1
702 done
703 done
704 done
707 test_expect_success 'Verify sort with multiple keys' '
708 cat >expected <<-\EOF &&
709 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
710 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
711 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
712 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
713 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
714 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
715 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
716 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
718 git for-each-ref \
719 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
720 --sort=-refname \
721 --sort=taggeremail \
722 --sort=taggerdate \
723 "refs/tags/multi-*" >actual &&
724 test_cmp expected actual
727 test_expect_success 'equivalent sorts fall back on refname' '
728 cat >expected <<-\EOF &&
729 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1
730 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2
731 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1
732 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2
733 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1
734 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2
735 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1
736 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2
738 git for-each-ref \
739 --format="%(taggerdate:unix) %(taggeremail) %(refname)" \
740 --sort=taggerdate \
741 "refs/tags/multi-*" >actual &&
742 test_cmp expected actual
745 test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
746 test_when_finished "git checkout master" &&
747 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
748 sed -e "s/^\* / /" actual >expect &&
749 git checkout --orphan orphaned-branch &&
750 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
751 test_cmp expect actual
754 cat >trailers <<EOF
755 Reviewed-by: A U Thor <author@example.com>
756 Signed-off-by: A U Thor <author@example.com>
757 [ v2 updated patch description ]
758 Acked-by: A U Thor
759 <author@example.com>
762 unfold () {
763 perl -0pe 's/\n\s+/ /g'
766 test_expect_success 'set up trailers for next test' '
767 echo "Some contents" > two &&
768 git add two &&
769 git commit -F - <<-EOF
770 trailers: this commit message has trailers
772 Some message contents
774 $(cat trailers)
778 test_expect_success '%(trailers:unfold) unfolds trailers' '
779 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
781 unfold <trailers
782 echo
783 } >expect &&
784 test_cmp expect actual
787 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
788 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
790 grep -v patch.description <trailers &&
791 echo
792 } >expect &&
793 test_cmp expect actual
796 test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
797 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
798 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
799 test_cmp actual reverse &&
801 grep -v patch.description <trailers | unfold &&
802 echo
803 } >expect &&
804 test_cmp expect actual
807 test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
808 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
810 unfold <trailers
811 echo
812 } >expect &&
813 test_cmp expect actual
816 test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
817 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
819 grep -v patch.description <trailers &&
820 echo
821 } >expect &&
822 test_cmp expect actual
825 test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
826 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
827 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
828 test_cmp actual reverse &&
830 grep -v patch.description <trailers | unfold &&
831 echo
832 } >expect &&
833 test_cmp expect actual
836 test_expect_success '%(trailers) rejects unknown trailers arguments' '
837 # error message cannot be checked under i18n
838 cat >expect <<-EOF &&
839 fatal: unknown %(trailers) argument: unsupported
841 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
842 test_i18ncmp expect actual
845 test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
846 # error message cannot be checked under i18n
847 cat >expect <<-EOF &&
848 fatal: unknown %(trailers) argument: unsupported
850 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
851 test_i18ncmp expect actual
854 test_expect_success 'basic atom: head contents:trailers' '
855 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
856 sanitize_pgp <actual >actual.clean &&
857 # git for-each-ref ends with a blank line
858 cat >expect <<-EOF &&
859 $(cat trailers)
862 test_cmp expect actual.clean
865 test_expect_success 'trailer parsing not fooled by --- line' '
866 git commit --allow-empty -F - <<-\EOF &&
867 this is the subject
869 This is the body. The message has a "---" line which would confuse a
870 message+patch parser. But here we know we have only a commit message,
871 so we get it right.
873 trailer: wrong
875 This is more body.
877 trailer: right
881 echo "trailer: right" &&
882 echo
883 } >expect &&
884 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
885 test_cmp expect actual
888 test_expect_success 'Add symbolic ref for the following tests' '
889 git symbolic-ref refs/heads/sym refs/heads/master
892 cat >expected <<EOF
893 refs/heads/master
896 test_expect_success 'Verify usage of %(symref) atom' '
897 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
898 test_cmp expected actual
901 cat >expected <<EOF
902 heads/master
905 test_expect_success 'Verify usage of %(symref:short) atom' '
906 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
907 test_cmp expected actual
910 cat >expected <<EOF
911 master
912 heads/master
915 test_expect_success 'Verify usage of %(symref:lstrip) atom' '
916 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
917 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
918 test_cmp expected actual &&
920 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
921 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
922 test_cmp expected actual
925 cat >expected <<EOF
926 refs
927 refs/heads
930 test_expect_success 'Verify usage of %(symref:rstrip) atom' '
931 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
932 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
933 test_cmp expected actual
936 test_expect_success ':remotename and :remoteref' '
937 git init remote-tests &&
939 cd remote-tests &&
940 test_commit initial &&
941 git remote add from fifth.coffee:blub &&
942 git config branch.master.remote from &&
943 git config branch.master.merge refs/heads/stable &&
944 git remote add to southridge.audio:repo &&
945 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
946 git config branch.master.pushRemote to &&
947 for pair in "%(upstream)=refs/remotes/from/stable" \
948 "%(upstream:remotename)=from" \
949 "%(upstream:remoteref)=refs/heads/stable" \
950 "%(push)=refs/remotes/to/pushed/master" \
951 "%(push:remotename)=to" \
952 "%(push:remoteref)=refs/heads/pushed/master"
954 echo "${pair#*=}" >expect &&
955 git for-each-ref --format="${pair%=*}" \
956 refs/heads/master >actual &&
957 test_cmp expect actual
958 done &&
959 git branch push-simple &&
960 git config branch.push-simple.pushRemote from &&
961 actual="$(git for-each-ref \
962 --format="%(push:remotename),%(push:remoteref)" \
963 refs/heads/push-simple)" &&
964 test from, = "$actual"
968 test_expect_success 'for-each-ref --ignore-case ignores case' '
969 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
970 test_must_be_empty actual &&
972 echo refs/heads/master >expect &&
973 git for-each-ref --format="%(refname)" --ignore-case \
974 refs/heads/MASTER >actual &&
975 test_cmp expect actual
978 test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' '
979 # name refs numerically to avoid case-insensitive filesystem conflicts
980 nr=0 &&
981 for email in a A b B
983 for subject in a A b B
985 GIT_COMMITTER_EMAIL="$email@example.com" \
986 git tag -m "tag $subject" icase-$(printf %02d $nr) &&
987 nr=$((nr+1))||
988 return 1
989 done
990 done &&
991 git for-each-ref --ignore-case \
992 --format="%(taggeremail) %(subject) %(refname)" \
993 --sort=refname \
994 --sort=subject \
995 --sort=taggeremail \
996 refs/tags/icase-* >actual &&
997 cat >expect <<-\EOF &&
998 <a@example.com> tag a refs/tags/icase-00
999 <a@example.com> tag A refs/tags/icase-01
1000 <A@example.com> tag a refs/tags/icase-04
1001 <A@example.com> tag A refs/tags/icase-05
1002 <a@example.com> tag b refs/tags/icase-02
1003 <a@example.com> tag B refs/tags/icase-03
1004 <A@example.com> tag b refs/tags/icase-06
1005 <A@example.com> tag B refs/tags/icase-07
1006 <b@example.com> tag a refs/tags/icase-08
1007 <b@example.com> tag A refs/tags/icase-09
1008 <B@example.com> tag a refs/tags/icase-12
1009 <B@example.com> tag A refs/tags/icase-13
1010 <b@example.com> tag b refs/tags/icase-10
1011 <b@example.com> tag B refs/tags/icase-11
1012 <B@example.com> tag b refs/tags/icase-14
1013 <B@example.com> tag B refs/tags/icase-15
1015 test_cmp expect actual
1018 test_done