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 author 'A U Thor <author@example.com> 1151939924 +0200'
62 test_atom head authorname 'A U Thor'
63 test_atom head authoremail '<author@example.com>'
64 test_atom head authordate 'Mon Jul 3 17:18:44 2006 +0200'
65 test_atom head committer 'C O Mitter <committer@example.com> 1151939923 +0200'
66 test_atom head committername 'C O Mitter'
67 test_atom head committeremail '<committer@example.com>'
68 test_atom head committerdate 'Mon Jul 3 17:18:43 2006 +0200'
70 test_atom head tagger ''
71 test_atom head taggername ''
72 test_atom head taggeremail ''
73 test_atom head taggerdate ''
74 test_atom head creator 'C O Mitter <committer@example.com> 1151939923 +0200'
75 test_atom head creatordate 'Mon Jul 3 17:18:43 2006 +0200'
76 test_atom head subject 'Initial'
77 test_atom head contents:subject 'Initial'
78 test_atom head body ''
79 test_atom head contents:body ''
80 test_atom head contents:signature ''
81 test_atom head contents 'Initial
84 test_atom tag refname refs/tags/testtag
85 test_atom tag upstream ''
86 test_atom tag objecttype tag
87 test_atom tag objectsize 154
88 test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322
90 test_atom tag parent ''
91 test_atom tag numparent ''
92 test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581'
93 test_atom tag type 'commit'
94 test_atom tag author ''
95 test_atom tag authorname ''
96 test_atom tag authoremail ''
97 test_atom tag authordate ''
98 test_atom tag committer ''
99 test_atom tag committername ''
100 test_atom tag committeremail ''
101 test_atom tag committerdate ''
102 test_atom tag tag 'testtag'
103 test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200'
104 test_atom tag taggername 'C O Mitter'
105 test_atom tag taggeremail '<committer@example.com>'
106 test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200'
107 test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200'
108 test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200'
109 test_atom tag subject 'Tagging at 1151939927'
110 test_atom tag contents:subject 'Tagging at 1151939927'
111 test_atom tag body ''
112 test_atom tag contents:body ''
113 test_atom tag contents:signature ''
114 test_atom tag contents 'Tagging at 1151939927
117 test_expect_success 'Check invalid atoms names are errors' '
118 test_must_fail git for-each-ref --format="%(INVALID)" refs/heads
121 test_expect_success 'Check format specifiers are ignored in naming date atoms' '
122 git for-each-ref --format="%(authordate)" refs/heads &&
123 git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads &&
124 git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads &&
125 git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads
128 test_expect_success 'Check valid format specifiers for date fields' '
129 git for-each-ref --format="%(authordate:default)" refs/heads &&
130 git for-each-ref --format="%(authordate:relative)" refs/heads &&
131 git for-each-ref --format="%(authordate:short)" refs/heads &&
132 git for-each-ref --format="%(authordate:local)" refs/heads &&
133 git for-each-ref --format="%(authordate:iso8601)" refs/heads &&
134 git for-each-ref --format="%(authordate:rfc2822)" refs/heads
137 test_expect_success 'Check invalid format specifiers are errors' '
138 test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads
142 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200'
143 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200'
146 test_expect_success 'Check unformatted date fields output' '
147 (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads &&
148 git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual &&
149 test_cmp expected actual
152 test_expect_success 'Check format "default" formatted date fields output' '
154 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
155 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
156 test_cmp expected actual
159 # Don't know how to do relative check because I can't know when this script
160 # is going to be run and can't fake the current time to git, and hence can't
161 # provide expected output. Instead, I'll just make sure that "relative"
162 # doesn't exit in error
164 #cat >expected <<\EOF
168 test_expect_success 'Check format "relative" date fields output' '
170 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
171 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual
175 'refs/heads/master' '2006-07-03' '2006-07-03'
176 'refs/tags/testtag' '2006-07-03'
179 test_expect_success 'Check format "short" date fields output' '
181 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
182 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
183 test_cmp expected actual
187 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006'
188 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006'
191 test_expect_success 'Check format "local" date fields output' '
193 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
194 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
195 test_cmp expected actual
199 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200'
200 'refs/tags/testtag' '2006-07-03 17:18:45 +0200'
203 test_expect_success 'Check format "iso8601" date fields output' '
205 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
206 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
207 test_cmp expected actual
211 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200'
212 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200'
215 test_expect_success 'Check format "rfc2822" date fields output' '
217 (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads &&
218 git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual &&
219 test_cmp expected actual
224 refs/remotes/origin/master
228 test_expect_success 'Verify ascending sort' '
229 git for-each-ref --format="%(refname)" --sort=refname >actual &&
230 test_cmp expected actual
236 refs/remotes/origin/master
240 test_expect_success 'Verify descending sort' '
241 git for-each-ref --format="%(refname)" --sort=-refname >actual &&
242 test_cmp expected actual
247 'refs/remotes/origin/master'
251 test_expect_success 'Quoting style: shell' '
252 git for-each-ref --shell --format="%(refname)" >actual &&
253 test_cmp expected actual
256 test_expect_success 'Quoting style: perl' '
257 git for-each-ref --perl --format="%(refname)" >actual &&
258 test_cmp expected actual
261 test_expect_success 'Quoting style: python' '
262 git for-each-ref --python --format="%(refname)" >actual &&
263 test_cmp expected actual
268 "refs/remotes/origin/master"
272 test_expect_success 'Quoting style: tcl' '
273 git for-each-ref --tcl --format="%(refname)" >actual &&
274 test_cmp expected actual
277 for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do
278 test_expect_success "more than one quoting style: $i" "
279 git for-each-ref $i 2>&1 | (read line &&
281 \"error: more than one quoting style\"*) : happy;;
292 test_expect_success 'Check short refname format' '
293 (git for-each-ref --format="%(refname:short)" refs/heads &&
294 git for-each-ref --format="%(refname:short)" refs/tags) >actual &&
295 test_cmp expected actual
302 test_expect_success 'Check short upstream format' '
303 git for-each-ref --format="%(upstream:short)" refs/heads >actual &&
304 test_cmp expected actual
311 test_expect_success 'Check short objectname format' '
312 git for-each-ref --format="%(objectname:short)" refs/heads >actual &&
313 test_cmp expected actual
316 test_expect_success 'Check for invalid refname format' '
317 test_must_fail git for-each-ref --format="%(refname:INVALID)"
325 test_expect_success 'Check ambiguous head and tag refs (strict)' '
326 git config --bool core.warnambiguousrefs true &&
327 git checkout -b newtag &&
328 echo "Using $datestamp" > one &&
330 git commit -m "Branch" &&
331 setdate_and_increment &&
332 git tag -m "Tagging at $datestamp" master &&
333 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
334 test_cmp expected actual
342 test_expect_success 'Check ambiguous head and tag refs (loose)' '
343 git config --bool core.warnambiguousrefs false &&
344 git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual &&
345 test_cmp expected actual
353 test_expect_success 'Check ambiguous head and tag refs II (loose)' '
354 git checkout master &&
355 git tag ambiguous testtag^0 &&
356 git branch ambiguous testtag^0 &&
357 git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual &&
358 test_cmp expected actual
361 test_expect_success 'an unusual tag with an incomplete line' '
363 git tag -m "bogo" bogo &&
364 bogo=$(git cat-file tag bogo) &&
365 bogo=$(printf "%s" "$bogo" | git mktag) &&
366 git tag -f bogo "$bogo" &&
367 git for-each-ref --format "%(body)" refs/tags/bogo
371 test_expect_success 'create tag with subject and body content' '
378 git tag -F msg subject-body
380 test_atom refs/tags/subject-body subject 'the subject line'
381 test_atom refs/tags/subject-body body 'first body line
384 test_atom refs/tags/subject-body contents 'the subject line
390 test_expect_success 'create tag with multiline subject' '
398 git tag -F msg multiline
400 test_atom refs/tags/multiline subject 'first subject line second subject line'
401 test_atom refs/tags/multiline contents:subject 'first subject line second subject line'
402 test_atom refs/tags/multiline body 'first body line
405 test_atom refs/tags/multiline contents:body 'first body line
408 test_atom refs/tags/multiline contents:signature ''
409 test_atom refs/tags/multiline contents 'first subject line
416 test_expect_success GPG 'create signed tags' '
417 git tag -s -m "" signed-empty &&
418 git tag -s -m "subject line" signed-short &&
424 git tag -s -F msg signed-long
427 sig='-----BEGIN PGP SIGNATURE-----
428 -----END PGP SIGNATURE-----
432 test_atom refs/tags/signed-empty subject ''
433 test_atom refs/tags/signed-empty contents:subject ''
434 test_atom refs/tags/signed-empty body "$sig"
435 test_atom refs/tags/signed-empty contents:body ''
436 test_atom refs/tags/signed-empty contents:signature "$sig"
437 test_atom refs/tags/signed-empty contents "$sig"
439 test_atom refs/tags/signed-short subject 'subject line'
440 test_atom refs/tags/signed-short contents:subject 'subject line'
441 test_atom refs/tags/signed-short body "$sig"
442 test_atom refs/tags/signed-short contents:body ''
443 test_atom refs/tags/signed-short contents:signature "$sig"
444 test_atom refs/tags/signed-short contents "subject line
447 test_atom refs/tags/signed-long subject 'subject line'
448 test_atom refs/tags/signed-long contents:subject 'subject line'
449 test_atom refs/tags/signed-long body "body contents
451 test_atom refs/tags/signed-long contents:body 'body contents
453 test_atom refs/tags/signed-long contents:signature "$sig"
454 test_atom refs/tags/signed-long contents "subject line