]> git.ipfire.org Git - thirdparty/git.git/blame - t/t6300-for-each-ref.sh
ref-filter: initialize empty name or email fields
[thirdparty/git.git] / t / t6300-for-each-ref.sh
CommitLineData
96b2d4fa
AP
1#!/bin/sh
2#
3# Copyright (c) 2007 Andy Parkins
4#
5
6test_description='for-each-ref test'
7
8. ./test-lib.sh
e2b23972 9. "$TEST_DIRECTORY"/lib-gpg.sh
11b087ad 10. "$TEST_DIRECTORY"/lib-terminal.sh
96b2d4fa 11
db7bae25
JK
12# Mon Jul 3 23:18:43 2006 +0000
13datestamp=1151968723
96b2d4fa
AP
14setdate_and_increment () {
15 GIT_COMMITTER_DATE="$datestamp +0200"
16 datestamp=$(expr "$datestamp" + 1)
17 GIT_AUTHOR_DATE="$datestamp +0200"
18 datestamp=$(expr "$datestamp" + 1)
19 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
20}
21
bc147968 22test_expect_success setup '
96b2d4fa
AP
23 setdate_and_increment &&
24 echo "Using $datestamp" > one &&
25 git add one &&
26 git commit -m "Initial" &&
27 setdate_and_increment &&
bc147968 28 git tag -a -m "Tagging at $datestamp" testtag &&
8cae19d9
JK
29 git update-ref refs/remotes/origin/master master &&
30 git remote add origin nowhere &&
31 git config branch.master.remote origin &&
29bc8850
JK
32 git config branch.master.merge refs/heads/master &&
33 git remote add myfork elsewhere &&
34 git config remote.pushdefault myfork &&
35 git config push.default current
8cae19d9
JK
36'
37
d2bf48d2
JK
38test_atom() {
39 case "$1" in
40 head) ref=refs/heads/master ;;
41 tag) ref=refs/tags/testtag ;;
01f95825 42 sym) ref=refs/heads/sym ;;
7140c22c 43 *) ref=$1 ;;
d2bf48d2
JK
44 esac
45 printf '%s\n' "$3" >expected
e2b23972 46 test_expect_${4:-success} $PREREQ "basic atom: $1 $2" "
d2bf48d2 47 git for-each-ref --format='%($2)' $ref >actual &&
e2b23972
MG
48 sanitize_pgp <actual >actual.clean &&
49 test_cmp expected actual.clean
d2bf48d2
JK
50 "
51}
52
53test_atom head refname refs/heads/master
bea4dbea 54test_atom head refname: refs/heads/master
1d094db9 55test_atom head refname:short master
17938f17
KN
56test_atom head refname:lstrip=1 heads/master
57test_atom head refname:lstrip=2 master
1a0ca5e3
KN
58test_atom head refname:lstrip=-1 master
59test_atom head refname:lstrip=-2 heads/master
1a34728e
KN
60test_atom head refname:rstrip=1 refs/heads
61test_atom head refname:rstrip=2 refs
62test_atom head refname:rstrip=-1 refs
63test_atom head refname:rstrip=-2 refs/heads
44a6b6ce
JH
64test_atom head refname:strip=1 heads/master
65test_atom head refname:strip=2 master
66test_atom head refname:strip=-1 master
67test_atom head refname:strip=-2 heads/master
8cae19d9 68test_atom head upstream refs/remotes/origin/master
1d094db9 69test_atom head upstream:short origin/master
17938f17 70test_atom head upstream:lstrip=2 origin/master
1a0ca5e3 71test_atom head upstream:lstrip=-2 origin/master
1a34728e
KN
72test_atom head upstream:rstrip=2 refs/remotes
73test_atom head upstream:rstrip=-2 refs/remotes
44a6b6ce
JH
74test_atom head upstream:strip=2 origin/master
75test_atom head upstream:strip=-2 origin/master
29bc8850 76test_atom head push refs/remotes/myfork/master
1d094db9 77test_atom head push:short myfork/master
17938f17 78test_atom head push:lstrip=1 remotes/myfork/master
1a0ca5e3 79test_atom head push:lstrip=-1 master
1a34728e
KN
80test_atom head push:rstrip=1 refs/remotes/myfork
81test_atom head push:rstrip=-1 refs
44a6b6ce
JH
82test_atom head push:strip=1 remotes/myfork/master
83test_atom head push:strip=-1 master
d2bf48d2
JK
84test_atom head objecttype commit
85test_atom head objectsize 171
189a5467 86test_atom head objectname $(git rev-parse refs/heads/master)
1d094db9 87test_atom head objectname:short $(git rev-parse --short refs/heads/master)
42d0eb05
KN
88test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
89test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
189a5467 90test_atom head tree $(git rev-parse refs/heads/master^{tree})
d2bf48d2
JK
91test_atom head parent ''
92test_atom head numparent 0
93test_atom head object ''
94test_atom head type ''
b74cf648
JK
95test_atom head '*objectname' ''
96test_atom head '*objecttype' ''
db7bae25 97test_atom head author 'A U Thor <author@example.com> 1151968724 +0200'
d2bf48d2
JK
98test_atom head authorname 'A U Thor'
99test_atom head authoremail '<author@example.com>'
db7bae25
JK
100test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200'
101test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200'
d2bf48d2
JK
102test_atom head committername 'C O Mitter'
103test_atom head committeremail '<committer@example.com>'
db7bae25 104test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200'
d2bf48d2
JK
105test_atom head tag ''
106test_atom head tagger ''
107test_atom head taggername ''
108test_atom head taggeremail ''
109test_atom head taggerdate ''
db7bae25
JK
110test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200'
111test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200'
d2bf48d2 112test_atom head subject 'Initial'
e2b23972 113test_atom head contents:subject 'Initial'
d2bf48d2 114test_atom head body ''
e2b23972
MG
115test_atom head contents:body ''
116test_atom head contents:signature ''
d2bf48d2
JK
117test_atom head contents 'Initial
118'
7a48b832 119test_atom head HEAD '*'
d2bf48d2
JK
120
121test_atom tag refname refs/tags/testtag
1d094db9 122test_atom tag refname:short testtag
8cae19d9 123test_atom tag upstream ''
29bc8850 124test_atom tag push ''
d2bf48d2
JK
125test_atom tag objecttype tag
126test_atom tag objectsize 154
189a5467 127test_atom tag objectname $(git rev-parse refs/tags/testtag)
1d094db9 128test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag)
42d0eb05
KN
129test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master)
130test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master)
d2bf48d2
JK
131test_atom tag tree ''
132test_atom tag parent ''
133test_atom tag numparent ''
189a5467 134test_atom tag object $(git rev-parse refs/tags/testtag^0)
d2bf48d2 135test_atom tag type 'commit'
db7bae25 136test_atom tag '*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463'
b74cf648 137test_atom tag '*objecttype' 'commit'
d2bf48d2
JK
138test_atom tag author ''
139test_atom tag authorname ''
140test_atom tag authoremail ''
141test_atom tag authordate ''
142test_atom tag committer ''
143test_atom tag committername ''
144test_atom tag committeremail ''
145test_atom tag committerdate ''
146test_atom tag tag 'testtag'
db7bae25 147test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200'
d2bf48d2
JK
148test_atom tag taggername 'C O Mitter'
149test_atom tag taggeremail '<committer@example.com>'
db7bae25
JK
150test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200'
151test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200'
152test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200'
153test_atom tag subject 'Tagging at 1151968727'
154test_atom tag contents:subject 'Tagging at 1151968727'
d2bf48d2 155test_atom tag body ''
e2b23972
MG
156test_atom tag contents:body ''
157test_atom tag contents:signature ''
db7bae25 158test_atom tag contents 'Tagging at 1151968727
96b2d4fa 159'
7a48b832 160test_atom tag HEAD ' '
96b2d4fa 161
41ac414e 162test_expect_success 'Check invalid atoms names are errors' '
3604e7c5 163 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
96b2d4fa
AP
164'
165
166test_expect_success 'Check format specifiers are ignored in naming date atoms' '
3604e7c5
NS
167 git for-each-ref --format="%(authordate)" refs/heads &&
168 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
169 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
170 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
96b2d4fa
AP
171'
172
173test_expect_success 'Check valid format specifiers for date fields' '
3604e7c5
NS
174 git for-each-ref --format="%(authordate:default)" refs/heads &&
175 git for-each-ref --format="%(authordate:relative)" refs/heads &&
176 git for-each-ref --format="%(authordate:short)" refs/heads &&
177 git for-each-ref --format="%(authordate:local)" refs/heads &&
178 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
179 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
96b2d4fa
AP
180'
181
41ac414e 182test_expect_success 'Check invalid format specifiers are errors' '
3604e7c5 183 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
96b2d4fa
AP
184'
185
42d0eb05
KN
186test_expect_success 'arguments to %(objectname:short=) must be positive integers' '
187 test_must_fail git for-each-ref --format="%(objectname:short=0)" &&
188 test_must_fail git for-each-ref --format="%(objectname:short=-1)" &&
189 test_must_fail git for-each-ref --format="%(objectname:short=foo)"
190'
191
f95cecf4
JK
192test_date () {
193 f=$1 &&
194 committer_date=$2 &&
195 author_date=$3 &&
196 tagger_date=$4 &&
197 cat >expected <<-EOF &&
198 'refs/heads/master' '$committer_date' '$author_date'
199 'refs/tags/testtag' '$tagger_date'
200 EOF
201 (
202 git for-each-ref --shell \
203 --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \
204 refs/heads &&
205 git for-each-ref --shell \
206 --format="%(refname) %(taggerdate${f:+:$f})" \
207 refs/tags
208 ) >actual &&
209 test_cmp expected actual
210}
96b2d4fa
AP
211
212test_expect_success 'Check unformatted date fields output' '
f95cecf4 213 test_date "" \
db7bae25
JK
214 "Tue Jul 4 01:18:43 2006 +0200" \
215 "Tue Jul 4 01:18:44 2006 +0200" \
216 "Tue Jul 4 01:18:45 2006 +0200"
96b2d4fa
AP
217'
218
219test_expect_success 'Check format "default" formatted date fields output' '
f95cecf4 220 test_date default \
db7bae25
JK
221 "Tue Jul 4 01:18:43 2006 +0200" \
222 "Tue Jul 4 01:18:44 2006 +0200" \
223 "Tue Jul 4 01:18:45 2006 +0200"
96b2d4fa
AP
224'
225
99264e93
JK
226test_expect_success 'Check format "default-local" date fields output' '
227 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"
96b2d4fa
AP
228'
229
230# Don't know how to do relative check because I can't know when this script
231# is going to be run and can't fake the current time to git, and hence can't
232# provide expected output. Instead, I'll just make sure that "relative"
233# doesn't exit in error
96b2d4fa
AP
234test_expect_success 'Check format "relative" date fields output' '
235 f=relative &&
236 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
237 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
238'
239
99264e93
JK
240# We just check that this is the same as "relative" for now.
241test_expect_success 'Check format "relative-local" date fields output' '
242 test_date relative-local \
243 "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \
244 "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \
245 "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)"
246'
96b2d4fa
AP
247
248test_expect_success 'Check format "short" date fields output' '
db7bae25 249 test_date short 2006-07-04 2006-07-04 2006-07-04
96b2d4fa
AP
250'
251
99264e93
JK
252test_expect_success 'Check format "short-local" date fields output' '
253 test_date short-local 2006-07-03 2006-07-03 2006-07-03
254'
96b2d4fa
AP
255
256test_expect_success 'Check format "local" date fields output' '
f95cecf4 257 test_date local \
db7bae25
JK
258 "Mon Jul 3 23:18:43 2006" \
259 "Mon Jul 3 23:18:44 2006" \
260 "Mon Jul 3 23:18:45 2006"
96b2d4fa
AP
261'
262
96b2d4fa 263test_expect_success 'Check format "iso8601" date fields output' '
f95cecf4 264 test_date iso8601 \
db7bae25
JK
265 "2006-07-04 01:18:43 +0200" \
266 "2006-07-04 01:18:44 +0200" \
267 "2006-07-04 01:18:45 +0200"
96b2d4fa
AP
268'
269
99264e93
JK
270test_expect_success 'Check format "iso8601-local" date fields output' '
271 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"
272'
96b2d4fa
AP
273
274test_expect_success 'Check format "rfc2822" date fields output' '
f95cecf4 275 test_date rfc2822 \
db7bae25
JK
276 "Tue, 4 Jul 2006 01:18:43 +0200" \
277 "Tue, 4 Jul 2006 01:18:44 +0200" \
278 "Tue, 4 Jul 2006 01:18:45 +0200"
96b2d4fa
AP
279'
280
99264e93
JK
281test_expect_success 'Check format "rfc2822-local" date fields output' '
282 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"
283'
284
f3c1ba50 285test_expect_success 'Check format "raw" date fields output' '
db7bae25 286 test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200"
f3c1ba50
JK
287'
288
99264e93
JK
289test_expect_success 'Check format "raw-local" date fields output' '
290 test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000"
96b2d4fa
AP
291'
292
aa1462cc 293test_expect_success 'Check format of strftime date fields' '
db7bae25 294 echo "my date is 2006-07-04" >expected &&
aa1462cc
JK
295 git for-each-ref \
296 --format="%(authordate:format:my date is %Y-%m-%d)" \
297 refs/heads >actual &&
298 test_cmp expected actual
299'
300
99264e93
JK
301test_expect_success 'Check format of strftime-local date fields' '
302 echo "my date is 2006-07-03" >expected &&
303 git for-each-ref \
304 --format="%(authordate:format-local:my date is %Y-%m-%d)" \
305 refs/heads >actual &&
306 test_cmp expected actual
307'
308
e4f031e3
JK
309test_expect_success 'exercise strftime with odd fields' '
310 echo >expected &&
311 git for-each-ref --format="%(authordate:format:)" refs/heads >actual &&
312 test_cmp expected actual &&
8125a58b 313 long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" &&
e4f031e3
JK
314 echo $long >expected &&
315 git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual &&
316 test_cmp expected actual
317'
318
c899a57c
LH
319cat >expected <<\EOF
320refs/heads/master
8cae19d9 321refs/remotes/origin/master
c899a57c
LH
322refs/tags/testtag
323EOF
324
325test_expect_success 'Verify ascending sort' '
3604e7c5 326 git for-each-ref --format="%(refname)" --sort=refname >actual &&
3af82863 327 test_cmp expected actual
c899a57c
LH
328'
329
330
331cat >expected <<\EOF
332refs/tags/testtag
8cae19d9 333refs/remotes/origin/master
c899a57c
LH
334refs/heads/master
335EOF
336
337test_expect_success 'Verify descending sort' '
3604e7c5 338 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
3af82863 339 test_cmp expected actual
c899a57c
LH
340'
341
c9ecf4f1
JS
342cat >expected <<\EOF
343'refs/heads/master'
8cae19d9 344'refs/remotes/origin/master'
c9ecf4f1
JS
345'refs/tags/testtag'
346EOF
347
348test_expect_success 'Quoting style: shell' '
349 git for-each-ref --shell --format="%(refname)" >actual &&
3af82863 350 test_cmp expected actual
c9ecf4f1
JS
351'
352
353test_expect_success 'Quoting style: perl' '
354 git for-each-ref --perl --format="%(refname)" >actual &&
3af82863 355 test_cmp expected actual
c9ecf4f1
JS
356'
357
358test_expect_success 'Quoting style: python' '
359 git for-each-ref --python --format="%(refname)" >actual &&
3af82863 360 test_cmp expected actual
c9ecf4f1
JS
361'
362
363cat >expected <<\EOF
364"refs/heads/master"
8cae19d9 365"refs/remotes/origin/master"
c9ecf4f1
JS
366"refs/tags/testtag"
367EOF
368
369test_expect_success 'Quoting style: tcl' '
370 git for-each-ref --tcl --format="%(refname)" >actual &&
3af82863 371 test_cmp expected actual
c9ecf4f1
JS
372'
373
374for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
375 test_expect_success "more than one quoting style: $i" "
2708ef4a
SG
376 test_must_fail git for-each-ref $i 2>err &&
377 grep '^error: more than one quoting style' err
c9ecf4f1
JS
378 "
379done
c899a57c 380
b28061ce
RR
381test_expect_success 'setup for upstream:track[short]' '
382 test_commit two
383'
384
1d094db9
JK
385test_atom head upstream:track '[ahead 1]'
386test_atom head upstream:trackshort '>'
7743fcca
KN
387test_atom head upstream:track,nobracket 'ahead 1'
388test_atom head upstream:nobracket,track 'ahead 1'
1d094db9
JK
389test_atom head push:track '[ahead 1]'
390test_atom head push:trackshort '>'
b28061ce
RR
391
392test_expect_success 'Check that :track[short] cannot be used with other atoms' '
393 test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null &&
394 test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null
395'
396
b6160d95
RKC
397test_expect_success 'Check that :track[short] works when upstream is invalid' '
398 cat >expected <<-\EOF &&
ffd921d3 399 [gone]
b6160d95
RKC
400
401 EOF
402 test_when_finished "git config branch.master.merge refs/heads/master" &&
403 git config branch.master.merge refs/heads/does-not-exist &&
404 git for-each-ref \
405 --format="%(upstream:track)$LF%(upstream:trackshort)" \
406 refs/heads >actual &&
407 test_cmp expected actual
29bc8850
JK
408'
409
7d66f21a
BW
410test_expect_success 'Check for invalid refname format' '
411 test_must_fail git for-each-ref --format="%(refname:INVALID)"
412'
413
11b087ad
JK
414test_expect_success 'set up color tests' '
415 cat >expected.color <<-EOF &&
416 $(git rev-parse --short refs/heads/master) <GREEN>master<RESET>
417 $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET>
418 $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET>
419 $(git rev-parse --short refs/tags/two) <GREEN>two<RESET>
420 EOF
421 sed "s/<[^>]*>//g" <expected.color >expected.bare &&
422 color_format="%(objectname:short) %(color:green)%(refname:short)"
423'
fddb74c9 424
11b087ad 425test_expect_success TTY '%(color) shows color with a tty' '
e433749d 426 test_terminal git for-each-ref --format="$color_format" >actual.raw &&
097b681b 427 test_decode_color <actual.raw >actual &&
11b087ad
JK
428 test_cmp expected.color actual
429'
430
431test_expect_success '%(color) does not show color without tty' '
432 TERM=vt100 git for-each-ref --format="$color_format" >actual &&
433 test_cmp expected.bare actual
434'
435
0c88bf50
JK
436test_expect_success '--color can override tty check' '
437 git for-each-ref --color --format="$color_format" >actual.raw &&
11b087ad
JK
438 test_decode_color <actual.raw >actual &&
439 test_cmp expected.color actual
fddb74c9
RR
440'
441
b521fd12
JK
442test_expect_success 'color.ui=always does not override tty check' '
443 git -c color.ui=always for-each-ref --format="$color_format" >actual &&
444 test_cmp expected.bare actual
445'
446
7d66f21a
BW
447cat >expected <<\EOF
448heads/master
2bb98169 449tags/master
7d66f21a
BW
450EOF
451
2bb98169
BW
452test_expect_success 'Check ambiguous head and tag refs (strict)' '
453 git config --bool core.warnambiguousrefs true &&
7d66f21a
BW
454 git checkout -b newtag &&
455 echo "Using $datestamp" > one &&
456 git add one &&
457 git commit -m "Branch" &&
458 setdate_and_increment &&
459 git tag -m "Tagging at $datestamp" master &&
460 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
461 test_cmp expected actual
462'
463
2bb98169
BW
464cat >expected <<\EOF
465heads/master
466master
467EOF
468
469test_expect_success 'Check ambiguous head and tag refs (loose)' '
470 git config --bool core.warnambiguousrefs false &&
471 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
472 test_cmp expected actual
473'
474
7d66f21a
BW
475cat >expected <<\EOF
476heads/ambiguous
477ambiguous
478EOF
479
2bb98169 480test_expect_success 'Check ambiguous head and tag refs II (loose)' '
7d66f21a
BW
481 git checkout master &&
482 git tag ambiguous testtag^0 &&
483 git branch ambiguous testtag^0 &&
484 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
485 test_cmp expected actual
486'
487
8b3f33ef
MP
488test_expect_success 'create tag without tagger' '
489 git tag -a -m "Broken tag" taggerless &&
490 git tag -f taggerless $(git cat-file tag taggerless |
491 sed -e "/^tagger /d" |
492 git hash-object --stdin -w -t tag)
493'
494
495test_atom refs/tags/taggerless type 'commit'
496test_atom refs/tags/taggerless tag 'taggerless'
497test_atom refs/tags/taggerless tagger ''
498test_atom refs/tags/taggerless taggername ''
499test_atom refs/tags/taggerless taggeremail ''
500test_atom refs/tags/taggerless taggerdate ''
501test_atom refs/tags/taggerless committer ''
502test_atom refs/tags/taggerless committername ''
503test_atom refs/tags/taggerless committeremail ''
504test_atom refs/tags/taggerless committerdate ''
505test_atom refs/tags/taggerless subject 'Broken tag'
506
e276c26b
JH
507test_expect_success 'an unusual tag with an incomplete line' '
508
509 git tag -m "bogo" bogo &&
510 bogo=$(git cat-file tag bogo) &&
511 bogo=$(printf "%s" "$bogo" | git mktag) &&
512 git tag -f bogo "$bogo" &&
513 git for-each-ref --format "%(body)" refs/tags/bogo
514
515'
516
7140c22c
JK
517test_expect_success 'create tag with subject and body content' '
518 cat >>msg <<-\EOF &&
519 the subject line
520
521 first body line
522 second body line
523 EOF
524 git tag -F msg subject-body
525'
526test_atom refs/tags/subject-body subject 'the subject line'
527test_atom refs/tags/subject-body body 'first body line
528second body line
529'
530test_atom refs/tags/subject-body contents 'the subject line
531
532first body line
533second body line
534'
535
7f6e275b
JK
536test_expect_success 'create tag with multiline subject' '
537 cat >msg <<-\EOF &&
538 first subject line
539 second subject line
540
541 first body line
542 second body line
543 EOF
544 git tag -F msg multiline
545'
546test_atom refs/tags/multiline subject 'first subject line second subject line'
e2b23972 547test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
7f6e275b
JK
548test_atom refs/tags/multiline body 'first body line
549second body line
550'
e2b23972
MG
551test_atom refs/tags/multiline contents:body 'first body line
552second body line
553'
554test_atom refs/tags/multiline contents:signature ''
7f6e275b
JK
555test_atom refs/tags/multiline contents 'first subject line
556second subject line
557
558first body line
559second body line
560'
561
e2b23972
MG
562test_expect_success GPG 'create signed tags' '
563 git tag -s -m "" signed-empty &&
564 git tag -s -m "subject line" signed-short &&
565 cat >msg <<-\EOF &&
566 subject line
567
568 body contents
569 EOF
570 git tag -s -F msg signed-long
571'
572
573sig='-----BEGIN PGP SIGNATURE-----
574-----END PGP SIGNATURE-----
575'
576
577PREREQ=GPG
578test_atom refs/tags/signed-empty subject ''
579test_atom refs/tags/signed-empty contents:subject ''
580test_atom refs/tags/signed-empty body "$sig"
581test_atom refs/tags/signed-empty contents:body ''
582test_atom refs/tags/signed-empty contents:signature "$sig"
583test_atom refs/tags/signed-empty contents "$sig"
584
585test_atom refs/tags/signed-short subject 'subject line'
586test_atom refs/tags/signed-short contents:subject 'subject line'
587test_atom refs/tags/signed-short body "$sig"
588test_atom refs/tags/signed-short contents:body ''
589test_atom refs/tags/signed-short contents:signature "$sig"
590test_atom refs/tags/signed-short contents "subject line
591$sig"
592
593test_atom refs/tags/signed-long subject 'subject line'
594test_atom refs/tags/signed-long contents:subject 'subject line'
595test_atom refs/tags/signed-long body "body contents
596$sig"
597test_atom refs/tags/signed-long contents:body 'body contents
598'
599test_atom refs/tags/signed-long contents:signature "$sig"
600test_atom refs/tags/signed-long contents "subject line
601
602body contents
603$sig"
604
189a5467 605cat >expected <<EOF
189a5467 606$(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
db7bae25 607$(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
912072d5
KK
608EOF
609
3b51222c 610test_expect_success 'Verify sort with multiple keys' '
912072d5
KK
611 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
612 refs/tags/bogo refs/tags/master > actual &&
613 test_cmp expected actual
614'
84679d47 615
01f95825 616
84679d47
JH
617test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' '
618 test_when_finished "git checkout master" &&
619 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
620 sed -e "s/^\* / /" actual >expect &&
f0252ca2 621 git checkout --orphan orphaned-branch &&
84679d47
JH
622 git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual &&
623 test_cmp expect actual
624'
625
b1d31c89
JK
626cat >trailers <<EOF
627Reviewed-by: A U Thor <author@example.com>
628Signed-off-by: A U Thor <author@example.com>
624b44d3
TB
629[ v2 updated patch description ]
630Acked-by: A U Thor
631 <author@example.com>
b1d31c89
JK
632EOF
633
67a20a00
TB
634unfold () {
635 perl -0pe 's/\n\s+/ /g'
636}
624b44d3
TB
637
638test_expect_success 'set up trailers for next test' '
b1d31c89
JK
639 echo "Some contents" > two &&
640 git add two &&
624b44d3 641 git commit -F - <<-EOF
b1d31c89
JK
642 trailers: this commit message has trailers
643
644 Some message contents
645
646 $(cat trailers)
647 EOF
624b44d3
TB
648'
649
67a20a00
TB
650test_expect_success '%(trailers:unfold) unfolds trailers' '
651 git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual &&
652 {
653 unfold <trailers
654 echo
655 } >expect &&
656 test_cmp expect actual
657'
658
659test_expect_success '%(trailers:only) shows only "key: value" trailers' '
660 git for-each-ref --format="%(trailers:only)" refs/heads/master >actual &&
661 {
662 grep -v patch.description <trailers &&
663 echo
664 } >expect &&
665 test_cmp expect actual
666'
667
668test_expect_success '%(trailers:only) and %(trailers:unfold) work together' '
669 git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual &&
670 git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse &&
671 test_cmp actual reverse &&
672 {
673 grep -v patch.description <trailers | unfold &&
674 echo
675 } >expect &&
676 test_cmp expect actual
677'
678
7a5edbdb
TB
679test_expect_success '%(contents:trailers:unfold) unfolds trailers' '
680 git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual &&
681 {
682 unfold <trailers
683 echo
684 } >expect &&
685 test_cmp expect actual
686'
687
688test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' '
689 git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual &&
690 {
691 grep -v patch.description <trailers &&
692 echo
693 } >expect &&
694 test_cmp expect actual
695'
696
697test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' '
698 git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual &&
699 git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse &&
700 test_cmp actual reverse &&
701 {
702 grep -v patch.description <trailers | unfold &&
703 echo
704 } >expect &&
705 test_cmp expect actual
706'
707
67a20a00
TB
708test_expect_success '%(trailers) rejects unknown trailers arguments' '
709 # error message cannot be checked under i18n
710 cat >expect <<-EOF &&
711 fatal: unknown %(trailers) argument: unsupported
712 EOF
713 test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual &&
714 test_i18ncmp expect actual
715'
716
7a5edbdb
TB
717test_expect_success '%(contents:trailers) rejects unknown trailers arguments' '
718 # error message cannot be checked under i18n
719 cat >expect <<-EOF &&
720 fatal: unknown %(trailers) argument: unsupported
721 EOF
722 test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual &&
723 test_i18ncmp expect actual
724'
725
624b44d3 726test_expect_success 'basic atom: head contents:trailers' '
b1d31c89
JK
727 git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual &&
728 sanitize_pgp <actual >actual.clean &&
729 # git for-each-ref ends with a blank line
730 cat >expect <<-EOF &&
731 $(cat trailers)
732
733 EOF
734 test_cmp expect actual.clean
735'
736
e5fba5d5
JK
737test_expect_success 'trailer parsing not fooled by --- line' '
738 git commit --allow-empty -F - <<-\EOF &&
739 this is the subject
740
741 This is the body. The message has a "---" line which would confuse a
742 message+patch parser. But here we know we have only a commit message,
743 so we get it right.
744
745 trailer: wrong
746 ---
747 This is more body.
748
749 trailer: right
750 EOF
751
752 {
753 echo "trailer: right" &&
754 echo
755 } >expect &&
756 git for-each-ref --format="%(trailers)" refs/heads/master >actual &&
757 test_cmp expect actual
758'
759
01f95825
KN
760test_expect_success 'Add symbolic ref for the following tests' '
761 git symbolic-ref refs/heads/sym refs/heads/master
762'
763
764cat >expected <<EOF
765refs/heads/master
766EOF
767
768test_expect_success 'Verify usage of %(symref) atom' '
769 git for-each-ref --format="%(symref)" refs/heads/sym >actual &&
770 test_cmp expected actual
771'
772
773cat >expected <<EOF
774heads/master
775EOF
776
777test_expect_success 'Verify usage of %(symref:short) atom' '
778 git for-each-ref --format="%(symref:short)" refs/heads/sym >actual &&
779 test_cmp expected actual
780'
781
a7984101
KN
782cat >expected <<EOF
783master
1a0ca5e3 784heads/master
a7984101
KN
785EOF
786
17938f17
KN
787test_expect_success 'Verify usage of %(symref:lstrip) atom' '
788 git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual &&
1a0ca5e3 789 git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual &&
44a6b6ce
JH
790 test_cmp expected actual &&
791
792 git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual &&
793 git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual &&
a7984101
KN
794 test_cmp expected actual
795'
796
1a34728e
KN
797cat >expected <<EOF
798refs
799refs/heads
800EOF
801
802test_expect_success 'Verify usage of %(symref:rstrip) atom' '
803 git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual &&
804 git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual &&
805 test_cmp expected actual
806'
807
1b586867
JS
808test_expect_success ':remotename and :remoteref' '
809 git init remote-tests &&
810 (
811 cd remote-tests &&
812 test_commit initial &&
813 git remote add from fifth.coffee:blub &&
814 git config branch.master.remote from &&
815 git config branch.master.merge refs/heads/stable &&
816 git remote add to southridge.audio:repo &&
817 git config remote.to.push "refs/heads/*:refs/heads/pushed/*" &&
818 git config branch.master.pushRemote to &&
819 for pair in "%(upstream)=refs/remotes/from/stable" \
820 "%(upstream:remotename)=from" \
821 "%(upstream:remoteref)=refs/heads/stable" \
822 "%(push)=refs/remotes/to/pushed/master" \
823 "%(push:remotename)=to" \
824 "%(push:remoteref)=refs/heads/pushed/master"
825 do
826 echo "${pair#*=}" >expect &&
827 git for-each-ref --format="${pair%=*}" \
828 refs/heads/master >actual &&
829 test_cmp expect actual
830 done &&
831 git branch push-simple &&
832 git config branch.push-simple.pushRemote from &&
833 actual="$(git for-each-ref \
834 --format="%(push:remotename),%(push:remoteref)" \
835 refs/heads/push-simple)" &&
836 test from, = "$actual"
837 )
838'
839
e674eb25 840test_expect_success 'for-each-ref --ignore-case ignores case' '
ee0f3e22 841 git for-each-ref --format="%(refname)" refs/heads/MASTER >actual &&
d3c6751b 842 test_must_be_empty actual &&
ee0f3e22
JK
843
844 echo refs/heads/master >expect &&
845 git for-each-ref --format="%(refname)" --ignore-case \
846 refs/heads/MASTER >actual &&
847 test_cmp expect actual
848'
849
96b2d4fa 850test_done