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