]>
Commit | Line | Data |
---|---|---|
96b2d4fa AP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2007 Andy Parkins | |
4 | # | |
5 | ||
6 | test_description='for-each-ref test' | |
7 | ||
8 | . ./test-lib.sh | |
9 | ||
10 | # Mon Jul 3 15:18:43 2006 +0000 | |
11 | datestamp=1151939923 | |
12 | setdate_and_increment () { | |
13 | GIT_COMMITTER_DATE="$datestamp +0200" | |
14 | datestamp=$(expr "$datestamp" + 1) | |
15 | GIT_AUTHOR_DATE="$datestamp +0200" | |
16 | datestamp=$(expr "$datestamp" + 1) | |
17 | export GIT_COMMITTER_DATE GIT_AUTHOR_DATE | |
18 | } | |
19 | ||
20 | test_expect_success 'Create sample commit with known timestamp' ' | |
21 | setdate_and_increment && | |
22 | echo "Using $datestamp" > one && | |
23 | git add one && | |
24 | git commit -m "Initial" && | |
25 | setdate_and_increment && | |
26 | git tag -a -m "Tagging at $datestamp" testtag | |
27 | ' | |
28 | ||
8cae19d9 JK |
29 | test_expect_success 'Create upstream config' ' |
30 | git update-ref refs/remotes/origin/master master && | |
31 | git remote add origin nowhere && | |
32 | git config branch.master.remote origin && | |
33 | git config branch.master.merge refs/heads/master | |
34 | ' | |
35 | ||
d2bf48d2 JK |
36 | test_atom() { |
37 | case "$1" in | |
38 | head) ref=refs/heads/master ;; | |
39 | tag) ref=refs/tags/testtag ;; | |
40 | esac | |
41 | printf '%s\n' "$3" >expected | |
42 | test_expect_${4:-success} "basic atom: $1 $2" " | |
43 | git for-each-ref --format='%($2)' $ref >actual && | |
44 | test_cmp expected actual | |
45 | " | |
46 | } | |
47 | ||
48 | test_atom head refname refs/heads/master | |
8cae19d9 | 49 | test_atom head upstream refs/remotes/origin/master |
d2bf48d2 JK |
50 | test_atom head objecttype commit |
51 | test_atom head objectsize 171 | |
52 | test_atom head objectname 67a36f10722846e891fbada1ba48ed035de75581 | |
53 | test_atom head tree 0e51c00fcb93dffc755546f27593d511e1bdb46f | |
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' | |
66 | test_atom head tag '' | |
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 body '' | |
75 | test_atom head contents 'Initial | |
76 | ' | |
77 | ||
78 | test_atom tag refname refs/tags/testtag | |
8cae19d9 | 79 | test_atom tag upstream '' |
d2bf48d2 JK |
80 | test_atom tag objecttype tag |
81 | test_atom tag objectsize 154 | |
82 | test_atom tag objectname 98b46b1d36e5b07909de1b3886224e3e81e87322 | |
83 | test_atom tag tree '' | |
84 | test_atom tag parent '' | |
85 | test_atom tag numparent '' | |
86 | test_atom tag object '67a36f10722846e891fbada1ba48ed035de75581' | |
87 | test_atom tag type 'commit' | |
88 | test_atom tag author '' | |
89 | test_atom tag authorname '' | |
90 | test_atom tag authoremail '' | |
91 | test_atom tag authordate '' | |
92 | test_atom tag committer '' | |
93 | test_atom tag committername '' | |
94 | test_atom tag committeremail '' | |
95 | test_atom tag committerdate '' | |
96 | test_atom tag tag 'testtag' | |
97 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151939925 +0200' | |
98 | test_atom tag taggername 'C O Mitter' | |
99 | test_atom tag taggeremail '<committer@example.com>' | |
100 | test_atom tag taggerdate 'Mon Jul 3 17:18:45 2006 +0200' | |
101 | test_atom tag creator 'C O Mitter <committer@example.com> 1151939925 +0200' | |
102 | test_atom tag creatordate 'Mon Jul 3 17:18:45 2006 +0200' | |
103 | test_atom tag subject 'Tagging at 1151939927' | |
104 | test_atom tag body '' | |
105 | test_atom tag contents 'Tagging at 1151939927 | |
96b2d4fa AP |
106 | ' |
107 | ||
41ac414e | 108 | test_expect_success 'Check invalid atoms names are errors' ' |
3604e7c5 | 109 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
96b2d4fa AP |
110 | ' |
111 | ||
112 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' | |
3604e7c5 NS |
113 | git for-each-ref --format="%(authordate)" refs/heads && |
114 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && | |
115 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && | |
116 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads | |
96b2d4fa AP |
117 | ' |
118 | ||
119 | test_expect_success 'Check valid format specifiers for date fields' ' | |
3604e7c5 NS |
120 | git for-each-ref --format="%(authordate:default)" refs/heads && |
121 | git for-each-ref --format="%(authordate:relative)" refs/heads && | |
122 | git for-each-ref --format="%(authordate:short)" refs/heads && | |
123 | git for-each-ref --format="%(authordate:local)" refs/heads && | |
124 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && | |
125 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads | |
96b2d4fa AP |
126 | ' |
127 | ||
41ac414e | 128 | test_expect_success 'Check invalid format specifiers are errors' ' |
3604e7c5 | 129 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
96b2d4fa AP |
130 | ' |
131 | ||
132 | cat >expected <<\EOF | |
133 | 'refs/heads/master' 'Mon Jul 3 17:18:43 2006 +0200' 'Mon Jul 3 17:18:44 2006 +0200' | |
134 | 'refs/tags/testtag' 'Mon Jul 3 17:18:45 2006 +0200' | |
135 | EOF | |
136 | ||
137 | test_expect_success 'Check unformatted date fields output' ' | |
138 | (git for-each-ref --shell --format="%(refname) %(committerdate) %(authordate)" refs/heads && | |
139 | git for-each-ref --shell --format="%(refname) %(taggerdate)" refs/tags) >actual && | |
3af82863 | 140 | test_cmp expected actual |
96b2d4fa AP |
141 | ' |
142 | ||
143 | test_expect_success 'Check format "default" formatted date fields output' ' | |
144 | f=default && | |
145 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
146 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && | |
3af82863 | 147 | test_cmp expected actual |
96b2d4fa AP |
148 | ' |
149 | ||
150 | # Don't know how to do relative check because I can't know when this script | |
151 | # is going to be run and can't fake the current time to git, and hence can't | |
152 | # provide expected output. Instead, I'll just make sure that "relative" | |
153 | # doesn't exit in error | |
154 | # | |
155 | #cat >expected <<\EOF | |
156 | # | |
157 | #EOF | |
158 | # | |
159 | test_expect_success 'Check format "relative" date fields output' ' | |
160 | f=relative && | |
161 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
162 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual | |
163 | ' | |
164 | ||
165 | cat >expected <<\EOF | |
166 | 'refs/heads/master' '2006-07-03' '2006-07-03' | |
167 | 'refs/tags/testtag' '2006-07-03' | |
168 | EOF | |
169 | ||
170 | test_expect_success 'Check format "short" date fields output' ' | |
171 | f=short && | |
172 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
173 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && | |
3af82863 | 174 | test_cmp expected actual |
96b2d4fa AP |
175 | ' |
176 | ||
177 | cat >expected <<\EOF | |
178 | 'refs/heads/master' 'Mon Jul 3 15:18:43 2006' 'Mon Jul 3 15:18:44 2006' | |
179 | 'refs/tags/testtag' 'Mon Jul 3 15:18:45 2006' | |
180 | EOF | |
181 | ||
182 | test_expect_success 'Check format "local" date fields output' ' | |
183 | f=local && | |
184 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
185 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && | |
3af82863 | 186 | test_cmp expected actual |
96b2d4fa AP |
187 | ' |
188 | ||
189 | cat >expected <<\EOF | |
190 | 'refs/heads/master' '2006-07-03 17:18:43 +0200' '2006-07-03 17:18:44 +0200' | |
191 | 'refs/tags/testtag' '2006-07-03 17:18:45 +0200' | |
192 | EOF | |
193 | ||
194 | test_expect_success 'Check format "iso8601" date fields output' ' | |
195 | f=iso8601 && | |
196 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
197 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && | |
3af82863 | 198 | test_cmp expected actual |
96b2d4fa AP |
199 | ' |
200 | ||
201 | cat >expected <<\EOF | |
202 | 'refs/heads/master' 'Mon, 3 Jul 2006 17:18:43 +0200' 'Mon, 3 Jul 2006 17:18:44 +0200' | |
203 | 'refs/tags/testtag' 'Mon, 3 Jul 2006 17:18:45 +0200' | |
204 | EOF | |
205 | ||
206 | test_expect_success 'Check format "rfc2822" date fields output' ' | |
207 | f=rfc2822 && | |
208 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
209 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual && | |
3af82863 | 210 | test_cmp expected actual |
96b2d4fa AP |
211 | ' |
212 | ||
c899a57c LH |
213 | cat >expected <<\EOF |
214 | refs/heads/master | |
8cae19d9 | 215 | refs/remotes/origin/master |
c899a57c LH |
216 | refs/tags/testtag |
217 | EOF | |
218 | ||
219 | test_expect_success 'Verify ascending sort' ' | |
3604e7c5 | 220 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
3af82863 | 221 | test_cmp expected actual |
c899a57c LH |
222 | ' |
223 | ||
224 | ||
225 | cat >expected <<\EOF | |
226 | refs/tags/testtag | |
8cae19d9 | 227 | refs/remotes/origin/master |
c899a57c LH |
228 | refs/heads/master |
229 | EOF | |
230 | ||
231 | test_expect_success 'Verify descending sort' ' | |
3604e7c5 | 232 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
3af82863 | 233 | test_cmp expected actual |
c899a57c LH |
234 | ' |
235 | ||
c9ecf4f1 JS |
236 | cat >expected <<\EOF |
237 | 'refs/heads/master' | |
8cae19d9 | 238 | 'refs/remotes/origin/master' |
c9ecf4f1 JS |
239 | 'refs/tags/testtag' |
240 | EOF | |
241 | ||
242 | test_expect_success 'Quoting style: shell' ' | |
243 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 244 | test_cmp expected actual |
c9ecf4f1 JS |
245 | ' |
246 | ||
247 | test_expect_success 'Quoting style: perl' ' | |
248 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 249 | test_cmp expected actual |
c9ecf4f1 JS |
250 | ' |
251 | ||
252 | test_expect_success 'Quoting style: python' ' | |
253 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 254 | test_cmp expected actual |
c9ecf4f1 JS |
255 | ' |
256 | ||
257 | cat >expected <<\EOF | |
258 | "refs/heads/master" | |
8cae19d9 | 259 | "refs/remotes/origin/master" |
c9ecf4f1 JS |
260 | "refs/tags/testtag" |
261 | EOF | |
262 | ||
263 | test_expect_success 'Quoting style: tcl' ' | |
264 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 265 | test_cmp expected actual |
c9ecf4f1 JS |
266 | ' |
267 | ||
268 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do | |
269 | test_expect_success "more than one quoting style: $i" " | |
270 | git for-each-ref $i 2>&1 | (read line && | |
271 | case \$line in | |
272 | \"error: more than one quoting style\"*) : happy;; | |
273 | *) false | |
274 | esac) | |
275 | " | |
276 | done | |
c899a57c | 277 | |
7d66f21a BW |
278 | cat >expected <<\EOF |
279 | master | |
280 | testtag | |
281 | EOF | |
282 | ||
283 | test_expect_success 'Check short refname format' ' | |
284 | (git for-each-ref --format="%(refname:short)" refs/heads && | |
285 | git for-each-ref --format="%(refname:short)" refs/tags) >actual && | |
286 | test_cmp expected actual | |
287 | ' | |
288 | ||
8cae19d9 JK |
289 | cat >expected <<EOF |
290 | origin/master | |
291 | EOF | |
292 | ||
293 | test_expect_success 'Check short upstream format' ' | |
294 | git for-each-ref --format="%(upstream:short)" refs/heads >actual && | |
295 | test_cmp expected actual | |
296 | ' | |
297 | ||
67687fea MG |
298 | cat >expected <<EOF |
299 | 67a36f1 | |
300 | EOF | |
301 | ||
302 | test_expect_success 'Check short objectname format' ' | |
303 | git for-each-ref --format="%(objectname:short)" refs/heads >actual && | |
304 | test_cmp expected actual | |
305 | ' | |
306 | ||
7d66f21a BW |
307 | test_expect_success 'Check for invalid refname format' ' |
308 | test_must_fail git for-each-ref --format="%(refname:INVALID)" | |
309 | ' | |
310 | ||
311 | cat >expected <<\EOF | |
312 | heads/master | |
2bb98169 | 313 | tags/master |
7d66f21a BW |
314 | EOF |
315 | ||
2bb98169 BW |
316 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
317 | git config --bool core.warnambiguousrefs true && | |
7d66f21a BW |
318 | git checkout -b newtag && |
319 | echo "Using $datestamp" > one && | |
320 | git add one && | |
321 | git commit -m "Branch" && | |
322 | setdate_and_increment && | |
323 | git tag -m "Tagging at $datestamp" master && | |
324 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
325 | test_cmp expected actual | |
326 | ' | |
327 | ||
2bb98169 BW |
328 | cat >expected <<\EOF |
329 | heads/master | |
330 | master | |
331 | EOF | |
332 | ||
333 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' | |
334 | git config --bool core.warnambiguousrefs false && | |
335 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
336 | test_cmp expected actual | |
337 | ' | |
338 | ||
7d66f21a BW |
339 | cat >expected <<\EOF |
340 | heads/ambiguous | |
341 | ambiguous | |
342 | EOF | |
343 | ||
2bb98169 | 344 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
7d66f21a BW |
345 | git checkout master && |
346 | git tag ambiguous testtag^0 && | |
347 | git branch ambiguous testtag^0 && | |
348 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && | |
349 | test_cmp expected actual | |
350 | ' | |
351 | ||
e276c26b JH |
352 | test_expect_success 'an unusual tag with an incomplete line' ' |
353 | ||
354 | git tag -m "bogo" bogo && | |
355 | bogo=$(git cat-file tag bogo) && | |
356 | bogo=$(printf "%s" "$bogo" | git mktag) && | |
357 | git tag -f bogo "$bogo" && | |
358 | git for-each-ref --format "%(body)" refs/tags/bogo | |
359 | ||
360 | ' | |
361 | ||
96b2d4fa | 362 | test_done |