3 # Copyright (c) 2007 Andy Parkins
6 test_description
='for-each-ref test'
9 .
"$TEST_DIRECTORY"/lib-gpg.sh
11 # Mon Jul 3 15:18:43 2006 +0000
13 setdate_and_increment
() {
14 GIT_COMMITTER_DATE
="$datestamp +0200"
15 datestamp
=$
(expr "$datestamp" + 1)
16 GIT_AUTHOR_DATE
="$datestamp +0200"
17 datestamp
=$
(expr "$datestamp" + 1)
18 export GIT_COMMITTER_DATE GIT_AUTHOR_DATE
21 test_expect_success setup
'
22 setdate_and_increment &&
23 echo "Using $datestamp" > one &&
25 git commit -m "Initial" &&
26 setdate_and_increment &&
27 git tag -a -m "Tagging at $datestamp" testtag &&
28 git update-ref refs/remotes/origin/master master &&
29 git remote add origin nowhere &&
30 git config branch.master.remote origin &&
31 git config branch.master.merge refs/heads/master
36 head) ref
=refs
/heads
/master
;;
37 tag
) ref
=refs
/tags
/testtag
;;
40 printf '%s\n' "$3" >expected
41 test_expect_
${4:-success} $PREREQ "basic atom: $1 $2" "
42 git for-each-ref --format='%($2)' $ref >actual &&
43 sanitize_pgp <actual >actual.clean &&
44 test_cmp expected actual.clean
48 test_atom
head refname refs
/heads
/master
49 test_atom
head upstream refs
/remotes
/origin
/master
50 test_atom
head objecttype commit
51 test_atom
head objectsize
171
52 test_atom
head objectname $
(git rev-parse refs
/heads
/master
)
53 test_atom
head tree $
(git rev-parse refs
/heads
/master^
{tree
})
54 test_atom
head parent
''
55 test_atom
head numparent
0
56 test_atom
head object
''
57 test_atom
head type ''
58 test_atom
head author
'A U Thor <author@example.com> 1151939924 +0200'
59 test_atom
head authorname
'A U Thor'
60 test_atom
head authoremail
'<author@example.com>'
61 test_atom
head authordate
'Mon Jul 3 17:18:44 2006 +0200'
62 test_atom
head committer
'C O Mitter <committer@example.com> 1151939923 +0200'
63 test_atom
head committername
'C O Mitter'
64 test_atom
head committeremail
'<committer@example.com>'
65 test_atom
head committerdate
'Mon Jul 3 17:18:43 2006 +0200'
67 test_atom
head tagger
''
68 test_atom
head taggername
''
69 test_atom
head taggeremail
''
70 test_atom
head taggerdate
''
71 test_atom
head creator
'C O Mitter <committer@example.com> 1151939923 +0200'
72 test_atom
head creatordate
'Mon Jul 3 17:18:43 2006 +0200'
73 test_atom
head subject
'Initial'
74 test_atom
head contents
:subject
'Initial'
75 test_atom
head body
''
76 test_atom
head contents
:body
''
77 test_atom
head contents
:signature
''
78 test_atom
head contents
'Initial
81 test_atom tag refname refs
/tags
/testtag
82 test_atom tag upstream
''
83 test_atom tag objecttype tag
84 test_atom tag objectsize
154
85 test_atom tag objectname $
(git rev-parse refs
/tags
/testtag
)
87 test_atom tag parent
''
88 test_atom tag numparent
''
89 test_atom tag object $
(git rev-parse refs
/tags
/testtag^
0)
90 test_atom tag
type 'commit'
91 test_atom tag author
''
92 test_atom tag authorname
''
93 test_atom tag authoremail
''
94 test_atom tag authordate
''
95 test_atom tag committer
''
96 test_atom tag committername
''
97 test_atom tag committeremail
''
98 test_atom tag committerdate
''
99 test_atom tag tag
'testtag'
100 test_atom tag tagger
'C O Mitter <committer@example.com> 1151939925 +0200'
101 test_atom tag taggername
'C O Mitter'
102 test_atom tag taggeremail
'<committer@example.com>'
103 test_atom tag taggerdate
'Mon Jul 3 17:18:45 2006 +0200'
104 test_atom tag creator
'C O Mitter <committer@example.com> 1151939925 +0200'
105 test_atom tag creatordate
'Mon Jul 3 17:18:45 2006 +0200'
106 test_atom tag subject
'Tagging at 1151939927'
107 test_atom tag contents
:subject
'Tagging at 1151939927'
108 test_atom tag body
''
109 test_atom tag contents
:body
''
110 test_atom tag contents
:signature
''
111 test_atom tag contents
'Tagging at 1151939927
114 test_expect_success
'Check invalid atoms names are errors' '
115 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
118 test_expect_success
'Check format specifiers are ignored in naming date atoms' '
119 git for-each-ref --format="%(authordate)" refs/heads &&
120 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
121 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
122 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
125 test_expect_success
'Check valid format specifiers for date fields' '
126 git for-each-ref --format="%(authordate:default)" refs/heads &&
127 git for-each-ref --format="%(authordate:relative)" refs/heads &&
128 git for-each-ref --format="%(authordate:short)" refs/heads &&
129 git for-each-ref --format="%(authordate:local)" refs/heads &&
130 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
131 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
134 test_expect_success
'Check invalid format specifiers are errors' '
135 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
139 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
140 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
143 test_expect_success
'Check unformatted date fields output' '
144 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
145 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
146 test_cmp expected actual
149 test_expect_success
'Check format "default" formatted date fields output' '
151 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
152 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
153 test_cmp expected actual
156 # Don't know how to do relative check because I can't know when this script
157 # is going to be run and can't fake the current time to git, and hence can't
158 # provide expected output. Instead, I'll just make sure that "relative"
159 # doesn't exit in error
161 #cat >expected <<\EOF
165 test_expect_success
'Check format "relative" date fields output' '
167 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
168 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
172 'refs/heads/master' '2006-07-03' '2006-07-03'
173 'refs/tags/testtag' '2006-07-03'
176 test_expect_success
'Check format "short" date fields output' '
178 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
179 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
180 test_cmp expected actual
184 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
185 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
188 test_expect_success
'Check format "local" date fields output' '
190 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
191 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
192 test_cmp expected actual
196 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
197 'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
200 test_expect_success
'Check format "iso8601" date fields output' '
202 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
203 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
204 test_cmp expected actual
208 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
209 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
212 test_expect_success
'Check format "rfc2822" date fields output' '
214 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
215 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
216 test_cmp expected actual
221 refs
/remotes
/origin
/master
225 test_expect_success
'Verify ascending sort' '
226 git for-each-ref --format="%(refname)" --sort=refname >actual &&
227 test_cmp expected actual
233 refs
/remotes
/origin
/master
237 test_expect_success
'Verify descending sort' '
238 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
239 test_cmp expected actual
244 'refs/remotes/origin/master'
248 test_expect_success
'Quoting style: shell' '
249 git for-each-ref --shell --format="%(refname)" >actual &&
250 test_cmp expected actual
253 test_expect_success
'Quoting style: perl' '
254 git for-each-ref --perl --format="%(refname)" >actual &&
255 test_cmp expected actual
258 test_expect_success
'Quoting style: python' '
259 git for-each-ref --python --format="%(refname)" >actual &&
260 test_cmp expected actual
265 "refs/remotes/origin/master"
269 test_expect_success
'Quoting style: tcl' '
270 git for-each-ref --tcl --format="%(refname)" >actual &&
271 test_cmp expected actual
274 for i
in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
275 test_expect_success
"more than one quoting style: $i" "
276 git for-each-ref $i 2>&1 | (read line &&
278 \"error: more than one quoting style\"*) : happy;;
289 test_expect_success
'Check short refname format' '
290 (git for-each-ref --format="%(refname:short)" refs/heads &&
291 git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
292 test_cmp expected actual
299 test_expect_success
'Check short upstream format' '
300 git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
301 test_cmp expected actual
305 $(git rev-parse --short HEAD)
308 test_expect_success
'Check short objectname format' '
309 git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
310 test_cmp expected actual
313 test_expect_success
'Check for invalid refname format' '
314 test_must_fail git for-each-ref --format="%(refname:INVALID)"
322 test_expect_success
'Check ambiguous head and tag refs (strict)' '
323 git config --bool core.warnambiguousrefs true &&
324 git checkout -b newtag &&
325 echo "Using $datestamp" > one &&
327 git commit -m "Branch" &&
328 setdate_and_increment &&
329 git tag -m "Tagging at $datestamp" master &&
330 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
331 test_cmp expected actual
339 test_expect_success
'Check ambiguous head and tag refs (loose)' '
340 git config --bool core.warnambiguousrefs false &&
341 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
342 test_cmp expected actual
350 test_expect_success
'Check ambiguous head and tag refs II (loose)' '
351 git checkout master &&
352 git tag ambiguous testtag^0 &&
353 git branch ambiguous testtag^0 &&
354 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
355 test_cmp expected actual
358 test_expect_success
'an unusual tag with an incomplete line' '
360 git tag -m "bogo" bogo &&
361 bogo=$(git cat-file tag bogo) &&
362 bogo=$(printf "%s" "$bogo" | git mktag) &&
363 git tag -f bogo "$bogo" &&
364 git for-each-ref --format "%(body)" refs/tags/bogo
368 test_expect_success
'create tag with subject and body content' '
375 git tag -F msg subject-body
377 test_atom refs
/tags
/subject-body subject
'the subject line'
378 test_atom refs
/tags
/subject-body body
'first body line
381 test_atom refs
/tags
/subject-body contents
'the subject line
387 test_expect_success
'create tag with multiline subject' '
395 git tag -F msg multiline
397 test_atom refs
/tags
/multiline subject
'first subject line second subject line'
398 test_atom refs
/tags
/multiline contents
:subject
'first subject line second subject line'
399 test_atom refs
/tags
/multiline body
'first body line
402 test_atom refs
/tags
/multiline contents
:body
'first body line
405 test_atom refs
/tags
/multiline contents
:signature
''
406 test_atom refs
/tags
/multiline contents
'first subject line
413 test_expect_success GPG
'create signed tags' '
414 git tag -s -m "" signed-empty &&
415 git tag -s -m "subject line" signed-short &&
421 git tag -s -F msg signed-long
424 sig
='-----BEGIN PGP SIGNATURE-----
425 -----END PGP SIGNATURE-----
429 test_atom refs
/tags
/signed-empty subject
''
430 test_atom refs
/tags
/signed-empty contents
:subject
''
431 test_atom refs
/tags
/signed-empty body
"$sig"
432 test_atom refs
/tags
/signed-empty contents
:body
''
433 test_atom refs
/tags
/signed-empty contents
:signature
"$sig"
434 test_atom refs
/tags
/signed-empty contents
"$sig"
436 test_atom refs
/tags
/signed-short subject
'subject line'
437 test_atom refs
/tags
/signed-short contents
:subject
'subject line'
438 test_atom refs
/tags
/signed-short body
"$sig"
439 test_atom refs
/tags
/signed-short contents
:body
''
440 test_atom refs
/tags
/signed-short contents
:signature
"$sig"
441 test_atom refs
/tags
/signed-short contents
"subject line
444 test_atom refs
/tags
/signed-long subject
'subject line'
445 test_atom refs
/tags
/signed-long contents
:subject
'subject line'
446 test_atom refs
/tags
/signed-long body
"body contents
448 test_atom refs
/tags
/signed-long contents
:body
'body contents
450 test_atom refs
/tags
/signed-long contents
:signature
"$sig"
451 test_atom refs
/tags
/signed-long contents
"subject line
457 $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master
458 $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo
461 test_expect_success
'Verify sort with multiple keys' '
462 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
463 refs/tags/bogo refs/tags/master > actual &&
464 test_cmp expected actual