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
'Create sample commit with known timestamp' '
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
30 test_expect_success
'Create upstream config' '
31 git update-ref refs/remotes/origin/master master &&
32 git remote add origin nowhere &&
33 git config branch.master.remote origin &&
34 git config branch.master.merge refs/heads/master
39 head) ref
=refs
/heads
/master
;;
40 tag
) ref
=refs
/tags
/testtag
;;
43 printf '%s\n' "$3" >expected
44 test_expect_
${4:-success} $PREREQ "basic atom: $1 $2" "
45 git for-each-ref --format='%($2)' $ref >actual &&
46 sanitize_pgp <actual >actual.clean &&
47 test_cmp expected actual.clean
51 test_atom
head refname refs
/heads
/master
52 test_atom
head upstream refs
/remotes
/origin
/master
53 test_atom
head objecttype commit
54 test_atom
head objectsize
171
55 test_atom
head objectname
67a36f10722846e891fbada1ba48ed035de75581
56 test_atom
head tree
0e51c00fcb93dffc755546f27593d511e1bdb46f
57 test_atom
head parent
''
58 test_atom
head numparent
0
59 test_atom
head object
''
60 test_atom
head type ''
61 test_atom
head '*objectname' ''
62 test_atom
head '*objecttype' ''
63 test_atom
head author
'A U Thor <author@example.com> 1151939924 +0200'
64 test_atom
head authorname
'A U Thor'
65 test_atom
head authoremail
'<author@example.com>'
66 test_atom
head authordate
'Mon Jul 3 17:18:44 2006 +0200'
67 test_atom
head committer
'C O Mitter <committer@example.com> 1151939923 +0200'
68 test_atom
head committername
'C O Mitter'
69 test_atom
head committeremail
'<committer@example.com>'
70 test_atom
head committerdate
'Mon Jul 3 17:18:43 2006 +0200'
72 test_atom
head tagger
''
73 test_atom
head taggername
''
74 test_atom
head taggeremail
''
75 test_atom
head taggerdate
''
76 test_atom
head creator
'C O Mitter <committer@example.com> 1151939923 +0200'
77 test_atom
head creatordate
'Mon Jul 3 17:18:43 2006 +0200'
78 test_atom
head subject
'Initial'
79 test_atom
head contents
:subject
'Initial'
80 test_atom
head body
''
81 test_atom
head contents
:body
''
82 test_atom
head contents
:signature
''
83 test_atom
head contents
'Initial
86 test_atom tag refname refs
/tags
/testtag
87 test_atom tag upstream
''
88 test_atom tag objecttype tag
89 test_atom tag objectsize
154
90 test_atom tag objectname
98b46b1d36e5b07909de1b3886224e3e81e87322
92 test_atom tag parent
''
93 test_atom tag numparent
''
94 test_atom tag object
'67a36f10722846e891fbada1ba48ed035de75581'
95 test_atom tag
type 'commit'
96 test_atom tag
'*objectname' '67a36f10722846e891fbada1ba48ed035de75581'
97 test_atom tag
'*objecttype' 'commit'
98 test_atom tag author
''
99 test_atom tag authorname
''
100 test_atom tag authoremail
''
101 test_atom tag authordate
''
102 test_atom tag committer
''
103 test_atom tag committername
''
104 test_atom tag committeremail
''
105 test_atom tag committerdate
''
106 test_atom tag tag
'testtag'
107 test_atom tag tagger
'C O Mitter <committer@example.com> 1151939925 +0200'
108 test_atom tag taggername
'C O Mitter'
109 test_atom tag taggeremail
'<committer@example.com>'
110 test_atom tag taggerdate
'Mon Jul 3 17:18:45 2006 +0200'
111 test_atom tag creator
'C O Mitter <committer@example.com> 1151939925 +0200'
112 test_atom tag creatordate
'Mon Jul 3 17:18:45 2006 +0200'
113 test_atom tag subject
'Tagging at 1151939927'
114 test_atom tag contents
:subject
'Tagging at 1151939927'
115 test_atom tag body
''
116 test_atom tag contents
:body
''
117 test_atom tag contents
:signature
''
118 test_atom tag contents
'Tagging at 1151939927
121 test_expect_success
'Check invalid atoms names are errors' '
122 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
125 test_expect_success
'Check format specifiers are ignored in naming date atoms' '
126 git for-each-ref --format="%(authordate)" refs/heads &&
127 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
128 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
129 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
132 test_expect_success
'Check valid format specifiers for date fields' '
133 git for-each-ref --format="%(authordate:default)" refs/heads &&
134 git for-each-ref --format="%(authordate:relative)" refs/heads &&
135 git for-each-ref --format="%(authordate:short)" refs/heads &&
136 git for-each-ref --format="%(authordate:local)" refs/heads &&
137 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
138 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
141 test_expect_success
'Check invalid format specifiers are errors' '
142 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
146 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
147 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
150 test_expect_success
'Check unformatted date fields output' '
151 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
152 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
153 test_cmp expected actual
156 test_expect_success
'Check format "default" formatted date fields output' '
158 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
159 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
160 test_cmp expected actual
163 # Don't know how to do relative check because I can't know when this script
164 # is going to be run and can't fake the current time to git, and hence can't
165 # provide expected output. Instead, I'll just make sure that "relative"
166 # doesn't exit in error
168 #cat >expected <<\EOF
172 test_expect_success
'Check format "relative" date fields output' '
174 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
175 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
179 'refs/heads/master' '2006-07-03' '2006-07-03'
180 'refs/tags/testtag' '2006-07-03'
183 test_expect_success
'Check format "short" date fields output' '
185 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
186 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
187 test_cmp expected actual
191 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
192 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
195 test_expect_success
'Check format "local" date fields output' '
197 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
198 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
199 test_cmp expected actual
203 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
204 'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
207 test_expect_success
'Check format "iso8601" date fields output' '
209 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
210 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
211 test_cmp expected actual
215 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
216 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
219 test_expect_success
'Check format "rfc2822" date fields output' '
221 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
222 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
223 test_cmp expected actual
228 refs
/remotes
/origin
/master
232 test_expect_success
'Verify ascending sort' '
233 git for-each-ref --format="%(refname)" --sort=refname >actual &&
234 test_cmp expected actual
240 refs
/remotes
/origin
/master
244 test_expect_success
'Verify descending sort' '
245 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
246 test_cmp expected actual
251 'refs/remotes/origin/master'
255 test_expect_success
'Quoting style: shell' '
256 git for-each-ref --shell --format="%(refname)" >actual &&
257 test_cmp expected actual
260 test_expect_success
'Quoting style: perl' '
261 git for-each-ref --perl --format="%(refname)" >actual &&
262 test_cmp expected actual
265 test_expect_success
'Quoting style: python' '
266 git for-each-ref --python --format="%(refname)" >actual &&
267 test_cmp expected actual
272 "refs/remotes/origin/master"
276 test_expect_success
'Quoting style: tcl' '
277 git for-each-ref --tcl --format="%(refname)" >actual &&
278 test_cmp expected actual
281 for i
in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
282 test_expect_success
"more than one quoting style: $i" "
283 git for-each-ref $i 2>&1 | (read line &&
285 \"error: more than one quoting style\"*) : happy;;
296 test_expect_success
'Check short refname format' '
297 (git for-each-ref --format="%(refname:short)" refs/heads &&
298 git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
299 test_cmp expected actual
306 test_expect_success
'Check short upstream format' '
307 git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
308 test_cmp expected actual
315 test_expect_success
'Check short objectname format' '
316 git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
317 test_cmp expected actual
320 test_expect_success
'Check for invalid refname format' '
321 test_must_fail git for-each-ref --format="%(refname:INVALID)"
329 test_expect_success
'Check ambiguous head and tag refs (strict)' '
330 git config --bool core.warnambiguousrefs true &&
331 git checkout -b newtag &&
332 echo "Using $datestamp" > one &&
334 git commit -m "Branch" &&
335 setdate_and_increment &&
336 git tag -m "Tagging at $datestamp" master &&
337 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
338 test_cmp expected actual
346 test_expect_success
'Check ambiguous head and tag refs (loose)' '
347 git config --bool core.warnambiguousrefs false &&
348 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
349 test_cmp expected actual
357 test_expect_success
'Check ambiguous head and tag refs II (loose)' '
358 git checkout master &&
359 git tag ambiguous testtag^0 &&
360 git branch ambiguous testtag^0 &&
361 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
362 test_cmp expected actual
365 test_expect_success
'an unusual tag with an incomplete line' '
367 git tag -m "bogo" bogo &&
368 bogo=$(git cat-file tag bogo) &&
369 bogo=$(printf "%s" "$bogo" | git mktag) &&
370 git tag -f bogo "$bogo" &&
371 git for-each-ref --format "%(body)" refs/tags/bogo
375 test_expect_success
'create tag with subject and body content' '
382 git tag -F msg subject-body
384 test_atom refs
/tags
/subject-body subject
'the subject line'
385 test_atom refs
/tags
/subject-body body
'first body line
388 test_atom refs
/tags
/subject-body contents
'the subject line
394 test_expect_success
'create tag with multiline subject' '
402 git tag -F msg multiline
404 test_atom refs
/tags
/multiline subject
'first subject line second subject line'
405 test_atom refs
/tags
/multiline contents
:subject
'first subject line second subject line'
406 test_atom refs
/tags
/multiline body
'first body line
409 test_atom refs
/tags
/multiline contents
:body
'first body line
412 test_atom refs
/tags
/multiline contents
:signature
''
413 test_atom refs
/tags
/multiline contents
'first subject line
420 test_expect_success GPG
'create signed tags' '
421 git tag -s -m "" signed-empty &&
422 git tag -s -m "subject line" signed-short &&
428 git tag -s -F msg signed-long
431 sig
='-----BEGIN PGP SIGNATURE-----
432 -----END PGP SIGNATURE-----
436 test_atom refs
/tags
/signed-empty subject
''
437 test_atom refs
/tags
/signed-empty contents
:subject
''
438 test_atom refs
/tags
/signed-empty body
"$sig"
439 test_atom refs
/tags
/signed-empty contents
:body
''
440 test_atom refs
/tags
/signed-empty contents
:signature
"$sig"
441 test_atom refs
/tags
/signed-empty contents
"$sig"
443 test_atom refs
/tags
/signed-short subject
'subject line'
444 test_atom refs
/tags
/signed-short contents
:subject
'subject line'
445 test_atom refs
/tags
/signed-short body
"$sig"
446 test_atom refs
/tags
/signed-short contents
:body
''
447 test_atom refs
/tags
/signed-short contents
:signature
"$sig"
448 test_atom refs
/tags
/signed-short contents
"subject line
451 test_atom refs
/tags
/signed-long subject
'subject line'
452 test_atom refs
/tags
/signed-long contents
:subject
'subject line'
453 test_atom refs
/tags
/signed-long body
"body contents
455 test_atom refs
/tags
/signed-long contents
:body
'body contents
457 test_atom refs
/tags
/signed-long contents
:signature
"$sig"
458 test_atom refs
/tags
/signed-long contents
"subject line
464 408fe76d02a785a006c2e9c669b7be5589ede96d
<committer@example.com
> refs
/tags
/master
465 90b5ebede4899eda64893bc2a4c8f1d6fb6dfc40
<committer@example.com
> refs
/tags
/bogo
468 test_expect_success
'Verify sort with multiple keys' '
469 git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \
470 refs/tags/bogo refs/tags/master > actual &&
471 test_cmp expected actual