]>
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 | |
e2b23972 | 9 | . "$TEST_DIRECTORY"/lib-gpg.sh |
96b2d4fa | 10 | |
db7bae25 JK |
11 | # Mon Jul 3 23:18:43 2006 +0000 |
12 | datestamp=1151968723 | |
96b2d4fa AP |
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 | |
19 | } | |
20 | ||
bc147968 | 21 | test_expect_success setup ' |
96b2d4fa AP |
22 | setdate_and_increment && |
23 | echo "Using $datestamp" > one && | |
24 | git add one && | |
25 | git commit -m "Initial" && | |
26 | setdate_and_increment && | |
bc147968 | 27 | git tag -a -m "Tagging at $datestamp" testtag && |
8cae19d9 JK |
28 | git update-ref refs/remotes/origin/master master && |
29 | git remote add origin nowhere && | |
30 | git config branch.master.remote origin && | |
29bc8850 JK |
31 | git config branch.master.merge refs/heads/master && |
32 | git remote add myfork elsewhere && | |
33 | git config remote.pushdefault myfork && | |
34 | git config push.default current | |
8cae19d9 JK |
35 | ' |
36 | ||
d2bf48d2 JK |
37 | test_atom() { |
38 | case "$1" in | |
39 | head) ref=refs/heads/master ;; | |
40 | tag) ref=refs/tags/testtag ;; | |
01f95825 | 41 | sym) ref=refs/heads/sym ;; |
7140c22c | 42 | *) ref=$1 ;; |
d2bf48d2 JK |
43 | esac |
44 | printf '%s\n' "$3" >expected | |
e2b23972 | 45 | test_expect_${4:-success} $PREREQ "basic atom: $1 $2" " |
d2bf48d2 | 46 | git for-each-ref --format='%($2)' $ref >actual && |
e2b23972 MG |
47 | sanitize_pgp <actual >actual.clean && |
48 | test_cmp expected actual.clean | |
d2bf48d2 JK |
49 | " |
50 | } | |
51 | ||
52 | test_atom head refname refs/heads/master | |
1d094db9 | 53 | test_atom head refname:short master |
17938f17 KN |
54 | test_atom head refname:lstrip=1 heads/master |
55 | test_atom head refname:lstrip=2 master | |
1a0ca5e3 KN |
56 | test_atom head refname:lstrip=-1 master |
57 | test_atom head refname:lstrip=-2 heads/master | |
1a34728e KN |
58 | test_atom head refname:rstrip=1 refs/heads |
59 | test_atom head refname:rstrip=2 refs | |
60 | test_atom head refname:rstrip=-1 refs | |
61 | test_atom head refname:rstrip=-2 refs/heads | |
44a6b6ce JH |
62 | test_atom head refname:strip=1 heads/master |
63 | test_atom head refname:strip=2 master | |
64 | test_atom head refname:strip=-1 master | |
65 | test_atom head refname:strip=-2 heads/master | |
8cae19d9 | 66 | test_atom head upstream refs/remotes/origin/master |
1d094db9 | 67 | test_atom head upstream:short origin/master |
17938f17 | 68 | test_atom head upstream:lstrip=2 origin/master |
1a0ca5e3 | 69 | test_atom head upstream:lstrip=-2 origin/master |
1a34728e KN |
70 | test_atom head upstream:rstrip=2 refs/remotes |
71 | test_atom head upstream:rstrip=-2 refs/remotes | |
44a6b6ce JH |
72 | test_atom head upstream:strip=2 origin/master |
73 | test_atom head upstream:strip=-2 origin/master | |
29bc8850 | 74 | test_atom head push refs/remotes/myfork/master |
1d094db9 | 75 | test_atom head push:short myfork/master |
17938f17 | 76 | test_atom head push:lstrip=1 remotes/myfork/master |
1a0ca5e3 | 77 | test_atom head push:lstrip=-1 master |
1a34728e KN |
78 | test_atom head push:rstrip=1 refs/remotes/myfork |
79 | test_atom head push:rstrip=-1 refs | |
44a6b6ce JH |
80 | test_atom head push:strip=1 remotes/myfork/master |
81 | test_atom head push:strip=-1 master | |
d2bf48d2 JK |
82 | test_atom head objecttype commit |
83 | test_atom head objectsize 171 | |
189a5467 | 84 | test_atom head objectname $(git rev-parse refs/heads/master) |
1d094db9 | 85 | test_atom head objectname:short $(git rev-parse --short refs/heads/master) |
42d0eb05 KN |
86 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) |
87 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) | |
189a5467 | 88 | test_atom head tree $(git rev-parse refs/heads/master^{tree}) |
d2bf48d2 JK |
89 | test_atom head parent '' |
90 | test_atom head numparent 0 | |
91 | test_atom head object '' | |
92 | test_atom head type '' | |
b74cf648 JK |
93 | test_atom head '*objectname' '' |
94 | test_atom head '*objecttype' '' | |
db7bae25 | 95 | test_atom head author 'A U Thor <author@example.com> 1151968724 +0200' |
d2bf48d2 JK |
96 | test_atom head authorname 'A U Thor' |
97 | test_atom head authoremail '<author@example.com>' | |
db7bae25 JK |
98 | test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' |
99 | test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200' | |
d2bf48d2 JK |
100 | test_atom head committername 'C O Mitter' |
101 | test_atom head committeremail '<committer@example.com>' | |
db7bae25 | 102 | test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' |
d2bf48d2 JK |
103 | test_atom head tag '' |
104 | test_atom head tagger '' | |
105 | test_atom head taggername '' | |
106 | test_atom head taggeremail '' | |
107 | test_atom head taggerdate '' | |
db7bae25 JK |
108 | test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200' |
109 | test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' | |
d2bf48d2 | 110 | test_atom head subject 'Initial' |
e2b23972 | 111 | test_atom head contents:subject 'Initial' |
d2bf48d2 | 112 | test_atom head body '' |
e2b23972 MG |
113 | test_atom head contents:body '' |
114 | test_atom head contents:signature '' | |
d2bf48d2 JK |
115 | test_atom head contents 'Initial |
116 | ' | |
7a48b832 | 117 | test_atom head HEAD '*' |
d2bf48d2 JK |
118 | |
119 | test_atom tag refname refs/tags/testtag | |
1d094db9 | 120 | test_atom tag refname:short testtag |
8cae19d9 | 121 | test_atom tag upstream '' |
29bc8850 | 122 | test_atom tag push '' |
d2bf48d2 JK |
123 | test_atom tag objecttype tag |
124 | test_atom tag objectsize 154 | |
189a5467 | 125 | test_atom tag objectname $(git rev-parse refs/tags/testtag) |
1d094db9 | 126 | test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) |
42d0eb05 KN |
127 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) |
128 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) | |
d2bf48d2 JK |
129 | test_atom tag tree '' |
130 | test_atom tag parent '' | |
131 | test_atom tag numparent '' | |
189a5467 | 132 | test_atom tag object $(git rev-parse refs/tags/testtag^0) |
d2bf48d2 | 133 | test_atom tag type 'commit' |
db7bae25 | 134 | test_atom tag '*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463' |
b74cf648 | 135 | test_atom tag '*objecttype' 'commit' |
d2bf48d2 JK |
136 | test_atom tag author '' |
137 | test_atom tag authorname '' | |
138 | test_atom tag authoremail '' | |
139 | test_atom tag authordate '' | |
140 | test_atom tag committer '' | |
141 | test_atom tag committername '' | |
142 | test_atom tag committeremail '' | |
143 | test_atom tag committerdate '' | |
144 | test_atom tag tag 'testtag' | |
db7bae25 | 145 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200' |
d2bf48d2 JK |
146 | test_atom tag taggername 'C O Mitter' |
147 | test_atom tag taggeremail '<committer@example.com>' | |
db7bae25 JK |
148 | test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' |
149 | test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200' | |
150 | test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' | |
151 | test_atom tag subject 'Tagging at 1151968727' | |
152 | test_atom tag contents:subject 'Tagging at 1151968727' | |
d2bf48d2 | 153 | test_atom tag body '' |
e2b23972 MG |
154 | test_atom tag contents:body '' |
155 | test_atom tag contents:signature '' | |
db7bae25 | 156 | test_atom tag contents 'Tagging at 1151968727 |
96b2d4fa | 157 | ' |
7a48b832 | 158 | test_atom tag HEAD ' ' |
96b2d4fa | 159 | |
41ac414e | 160 | test_expect_success 'Check invalid atoms names are errors' ' |
3604e7c5 | 161 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
96b2d4fa AP |
162 | ' |
163 | ||
164 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' | |
3604e7c5 NS |
165 | git for-each-ref --format="%(authordate)" refs/heads && |
166 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && | |
167 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && | |
168 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads | |
96b2d4fa AP |
169 | ' |
170 | ||
171 | test_expect_success 'Check valid format specifiers for date fields' ' | |
3604e7c5 NS |
172 | git for-each-ref --format="%(authordate:default)" refs/heads && |
173 | git for-each-ref --format="%(authordate:relative)" refs/heads && | |
174 | git for-each-ref --format="%(authordate:short)" refs/heads && | |
175 | git for-each-ref --format="%(authordate:local)" refs/heads && | |
176 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && | |
177 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads | |
96b2d4fa AP |
178 | ' |
179 | ||
41ac414e | 180 | test_expect_success 'Check invalid format specifiers are errors' ' |
3604e7c5 | 181 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
96b2d4fa AP |
182 | ' |
183 | ||
42d0eb05 KN |
184 | test_expect_success 'arguments to %(objectname:short=) must be positive integers' ' |
185 | test_must_fail git for-each-ref --format="%(objectname:short=0)" && | |
186 | test_must_fail git for-each-ref --format="%(objectname:short=-1)" && | |
187 | test_must_fail git for-each-ref --format="%(objectname:short=foo)" | |
188 | ' | |
189 | ||
f95cecf4 JK |
190 | test_date () { |
191 | f=$1 && | |
192 | committer_date=$2 && | |
193 | author_date=$3 && | |
194 | tagger_date=$4 && | |
195 | cat >expected <<-EOF && | |
196 | 'refs/heads/master' '$committer_date' '$author_date' | |
197 | 'refs/tags/testtag' '$tagger_date' | |
198 | EOF | |
199 | ( | |
200 | git for-each-ref --shell \ | |
201 | --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \ | |
202 | refs/heads && | |
203 | git for-each-ref --shell \ | |
204 | --format="%(refname) %(taggerdate${f:+:$f})" \ | |
205 | refs/tags | |
206 | ) >actual && | |
207 | test_cmp expected actual | |
208 | } | |
96b2d4fa AP |
209 | |
210 | test_expect_success 'Check unformatted date fields output' ' | |
f95cecf4 | 211 | test_date "" \ |
db7bae25 JK |
212 | "Tue Jul 4 01:18:43 2006 +0200" \ |
213 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
214 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
215 | ' |
216 | ||
217 | test_expect_success 'Check format "default" formatted date fields output' ' | |
f95cecf4 | 218 | test_date default \ |
db7bae25 JK |
219 | "Tue Jul 4 01:18:43 2006 +0200" \ |
220 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
221 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
222 | ' |
223 | ||
99264e93 JK |
224 | test_expect_success 'Check format "default-local" date fields output' ' |
225 | 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 |
226 | ' |
227 | ||
228 | # Don't know how to do relative check because I can't know when this script | |
229 | # is going to be run and can't fake the current time to git, and hence can't | |
230 | # provide expected output. Instead, I'll just make sure that "relative" | |
231 | # doesn't exit in error | |
96b2d4fa AP |
232 | test_expect_success 'Check format "relative" date fields output' ' |
233 | f=relative && | |
234 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
235 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual | |
236 | ' | |
237 | ||
99264e93 JK |
238 | # We just check that this is the same as "relative" for now. |
239 | test_expect_success 'Check format "relative-local" date fields output' ' | |
240 | test_date relative-local \ | |
241 | "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \ | |
242 | "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \ | |
243 | "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)" | |
244 | ' | |
96b2d4fa AP |
245 | |
246 | test_expect_success 'Check format "short" date fields output' ' | |
db7bae25 | 247 | test_date short 2006-07-04 2006-07-04 2006-07-04 |
96b2d4fa AP |
248 | ' |
249 | ||
99264e93 JK |
250 | test_expect_success 'Check format "short-local" date fields output' ' |
251 | test_date short-local 2006-07-03 2006-07-03 2006-07-03 | |
252 | ' | |
96b2d4fa AP |
253 | |
254 | test_expect_success 'Check format "local" date fields output' ' | |
f95cecf4 | 255 | test_date local \ |
db7bae25 JK |
256 | "Mon Jul 3 23:18:43 2006" \ |
257 | "Mon Jul 3 23:18:44 2006" \ | |
258 | "Mon Jul 3 23:18:45 2006" | |
96b2d4fa AP |
259 | ' |
260 | ||
96b2d4fa | 261 | test_expect_success 'Check format "iso8601" date fields output' ' |
f95cecf4 | 262 | test_date iso8601 \ |
db7bae25 JK |
263 | "2006-07-04 01:18:43 +0200" \ |
264 | "2006-07-04 01:18:44 +0200" \ | |
265 | "2006-07-04 01:18:45 +0200" | |
96b2d4fa AP |
266 | ' |
267 | ||
99264e93 JK |
268 | test_expect_success 'Check format "iso8601-local" date fields output' ' |
269 | 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" | |
270 | ' | |
96b2d4fa AP |
271 | |
272 | test_expect_success 'Check format "rfc2822" date fields output' ' | |
f95cecf4 | 273 | test_date rfc2822 \ |
db7bae25 JK |
274 | "Tue, 4 Jul 2006 01:18:43 +0200" \ |
275 | "Tue, 4 Jul 2006 01:18:44 +0200" \ | |
276 | "Tue, 4 Jul 2006 01:18:45 +0200" | |
96b2d4fa AP |
277 | ' |
278 | ||
99264e93 JK |
279 | test_expect_success 'Check format "rfc2822-local" date fields output' ' |
280 | 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" | |
281 | ' | |
282 | ||
f3c1ba50 | 283 | test_expect_success 'Check format "raw" date fields output' ' |
db7bae25 | 284 | test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200" |
f3c1ba50 JK |
285 | ' |
286 | ||
99264e93 JK |
287 | test_expect_success 'Check format "raw-local" date fields output' ' |
288 | test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000" | |
96b2d4fa AP |
289 | ' |
290 | ||
aa1462cc | 291 | test_expect_success 'Check format of strftime date fields' ' |
db7bae25 | 292 | echo "my date is 2006-07-04" >expected && |
aa1462cc JK |
293 | git for-each-ref \ |
294 | --format="%(authordate:format:my date is %Y-%m-%d)" \ | |
295 | refs/heads >actual && | |
296 | test_cmp expected actual | |
297 | ' | |
298 | ||
99264e93 JK |
299 | test_expect_success 'Check format of strftime-local date fields' ' |
300 | echo "my date is 2006-07-03" >expected && | |
301 | git for-each-ref \ | |
302 | --format="%(authordate:format-local:my date is %Y-%m-%d)" \ | |
303 | refs/heads >actual && | |
304 | test_cmp expected actual | |
305 | ' | |
306 | ||
e4f031e3 JK |
307 | test_expect_success 'exercise strftime with odd fields' ' |
308 | echo >expected && | |
309 | git for-each-ref --format="%(authordate:format:)" refs/heads >actual && | |
310 | test_cmp expected actual && | |
311 | long="long format -- $_z40$_z40$_z40$_z40$_z40$_z40$_z40" && | |
312 | echo $long >expected && | |
313 | git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && | |
314 | test_cmp expected actual | |
315 | ' | |
316 | ||
c899a57c LH |
317 | cat >expected <<\EOF |
318 | refs/heads/master | |
8cae19d9 | 319 | refs/remotes/origin/master |
c899a57c LH |
320 | refs/tags/testtag |
321 | EOF | |
322 | ||
323 | test_expect_success 'Verify ascending sort' ' | |
3604e7c5 | 324 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
3af82863 | 325 | test_cmp expected actual |
c899a57c LH |
326 | ' |
327 | ||
328 | ||
329 | cat >expected <<\EOF | |
330 | refs/tags/testtag | |
8cae19d9 | 331 | refs/remotes/origin/master |
c899a57c LH |
332 | refs/heads/master |
333 | EOF | |
334 | ||
335 | test_expect_success 'Verify descending sort' ' | |
3604e7c5 | 336 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
3af82863 | 337 | test_cmp expected actual |
c899a57c LH |
338 | ' |
339 | ||
c9ecf4f1 JS |
340 | cat >expected <<\EOF |
341 | 'refs/heads/master' | |
8cae19d9 | 342 | 'refs/remotes/origin/master' |
c9ecf4f1 JS |
343 | 'refs/tags/testtag' |
344 | EOF | |
345 | ||
346 | test_expect_success 'Quoting style: shell' ' | |
347 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 348 | test_cmp expected actual |
c9ecf4f1 JS |
349 | ' |
350 | ||
351 | test_expect_success 'Quoting style: perl' ' | |
352 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 353 | test_cmp expected actual |
c9ecf4f1 JS |
354 | ' |
355 | ||
356 | test_expect_success 'Quoting style: python' ' | |
357 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 358 | test_cmp expected actual |
c9ecf4f1 JS |
359 | ' |
360 | ||
361 | cat >expected <<\EOF | |
362 | "refs/heads/master" | |
8cae19d9 | 363 | "refs/remotes/origin/master" |
c9ecf4f1 JS |
364 | "refs/tags/testtag" |
365 | EOF | |
366 | ||
367 | test_expect_success 'Quoting style: tcl' ' | |
368 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 369 | test_cmp expected actual |
c9ecf4f1 JS |
370 | ' |
371 | ||
372 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do | |
373 | test_expect_success "more than one quoting style: $i" " | |
374 | git for-each-ref $i 2>&1 | (read line && | |
375 | case \$line in | |
376 | \"error: more than one quoting style\"*) : happy;; | |
377 | *) false | |
378 | esac) | |
379 | " | |
380 | done | |
c899a57c | 381 | |
b28061ce RR |
382 | test_expect_success 'setup for upstream:track[short]' ' |
383 | test_commit two | |
384 | ' | |
385 | ||
1d094db9 JK |
386 | test_atom head upstream:track '[ahead 1]' |
387 | test_atom head upstream:trackshort '>' | |
7743fcca KN |
388 | test_atom head upstream:track,nobracket 'ahead 1' |
389 | test_atom head upstream:nobracket,track 'ahead 1' | |
1d094db9 JK |
390 | test_atom head push:track '[ahead 1]' |
391 | test_atom head push:trackshort '>' | |
b28061ce RR |
392 | |
393 | test_expect_success 'Check that :track[short] cannot be used with other atoms' ' | |
394 | test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && | |
395 | test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null | |
396 | ' | |
397 | ||
b6160d95 RKC |
398 | test_expect_success 'Check that :track[short] works when upstream is invalid' ' |
399 | cat >expected <<-\EOF && | |
ffd921d3 | 400 | [gone] |
b6160d95 RKC |
401 | |
402 | EOF | |
403 | test_when_finished "git config branch.master.merge refs/heads/master" && | |
404 | git config branch.master.merge refs/heads/does-not-exist && | |
405 | git for-each-ref \ | |
406 | --format="%(upstream:track)$LF%(upstream:trackshort)" \ | |
407 | refs/heads >actual && | |
408 | test_cmp expected actual | |
29bc8850 JK |
409 | ' |
410 | ||
7d66f21a BW |
411 | test_expect_success 'Check for invalid refname format' ' |
412 | test_must_fail git for-each-ref --format="%(refname:INVALID)" | |
413 | ' | |
414 | ||
fddb74c9 RR |
415 | get_color () |
416 | { | |
417 | git config --get-color no.such.slot "$1" | |
418 | } | |
419 | ||
420 | cat >expected <<EOF | |
421 | $(git rev-parse --short refs/heads/master) $(get_color green)master$(get_color reset) | |
422 | $(git rev-parse --short refs/remotes/origin/master) $(get_color green)origin/master$(get_color reset) | |
423 | $(git rev-parse --short refs/tags/testtag) $(get_color green)testtag$(get_color reset) | |
424 | $(git rev-parse --short refs/tags/two) $(get_color green)two$(get_color reset) | |
425 | EOF | |
426 | ||
427 | test_expect_success 'Check %(color:...) ' ' | |
db64eb65 | 428 | git for-each-ref --format="%(objectname:short) %(color:green)%(refname:short)" >actual && |
fddb74c9 RR |
429 | test_cmp expected actual |
430 | ' | |
431 | ||
7d66f21a BW |
432 | cat >expected <<\EOF |
433 | heads/master | |
2bb98169 | 434 | tags/master |
7d66f21a BW |
435 | EOF |
436 | ||
2bb98169 BW |
437 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
438 | git config --bool core.warnambiguousrefs true && | |
7d66f21a BW |
439 | git checkout -b newtag && |
440 | echo "Using $datestamp" > one && | |
441 | git add one && | |
442 | git commit -m "Branch" && | |
443 | setdate_and_increment && | |
444 | git tag -m "Tagging at $datestamp" master && | |
445 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
446 | test_cmp expected actual | |
447 | ' | |
448 | ||
2bb98169 BW |
449 | cat >expected <<\EOF |
450 | heads/master | |
451 | master | |
452 | EOF | |
453 | ||
454 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' | |
455 | git config --bool core.warnambiguousrefs false && | |
456 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
457 | test_cmp expected actual | |
458 | ' | |
459 | ||
7d66f21a BW |
460 | cat >expected <<\EOF |
461 | heads/ambiguous | |
462 | ambiguous | |
463 | EOF | |
464 | ||
2bb98169 | 465 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
7d66f21a BW |
466 | git checkout master && |
467 | git tag ambiguous testtag^0 && | |
468 | git branch ambiguous testtag^0 && | |
469 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && | |
470 | test_cmp expected actual | |
471 | ' | |
472 | ||
e276c26b JH |
473 | test_expect_success 'an unusual tag with an incomplete line' ' |
474 | ||
475 | git tag -m "bogo" bogo && | |
476 | bogo=$(git cat-file tag bogo) && | |
477 | bogo=$(printf "%s" "$bogo" | git mktag) && | |
478 | git tag -f bogo "$bogo" && | |
479 | git for-each-ref --format "%(body)" refs/tags/bogo | |
480 | ||
481 | ' | |
482 | ||
7140c22c JK |
483 | test_expect_success 'create tag with subject and body content' ' |
484 | cat >>msg <<-\EOF && | |
485 | the subject line | |
486 | ||
487 | first body line | |
488 | second body line | |
489 | EOF | |
490 | git tag -F msg subject-body | |
491 | ' | |
492 | test_atom refs/tags/subject-body subject 'the subject line' | |
493 | test_atom refs/tags/subject-body body 'first body line | |
494 | second body line | |
495 | ' | |
496 | test_atom refs/tags/subject-body contents 'the subject line | |
497 | ||
498 | first body line | |
499 | second body line | |
500 | ' | |
501 | ||
7f6e275b JK |
502 | test_expect_success 'create tag with multiline subject' ' |
503 | cat >msg <<-\EOF && | |
504 | first subject line | |
505 | second subject line | |
506 | ||
507 | first body line | |
508 | second body line | |
509 | EOF | |
510 | git tag -F msg multiline | |
511 | ' | |
512 | test_atom refs/tags/multiline subject 'first subject line second subject line' | |
e2b23972 | 513 | test_atom refs/tags/multiline contents:subject 'first subject line second subject line' |
7f6e275b JK |
514 | test_atom refs/tags/multiline body 'first body line |
515 | second body line | |
516 | ' | |
e2b23972 MG |
517 | test_atom refs/tags/multiline contents:body 'first body line |
518 | second body line | |
519 | ' | |
520 | test_atom refs/tags/multiline contents:signature '' | |
7f6e275b JK |
521 | test_atom refs/tags/multiline contents 'first subject line |
522 | second subject line | |
523 | ||
524 | first body line | |
525 | second body line | |
526 | ' | |
527 | ||
e2b23972 MG |
528 | test_expect_success GPG 'create signed tags' ' |
529 | git tag -s -m "" signed-empty && | |
530 | git tag -s -m "subject line" signed-short && | |
531 | cat >msg <<-\EOF && | |
532 | subject line | |
533 | ||
534 | body contents | |
535 | EOF | |
536 | git tag -s -F msg signed-long | |
537 | ' | |
538 | ||
539 | sig='-----BEGIN PGP SIGNATURE----- | |
540 | -----END PGP SIGNATURE----- | |
541 | ' | |
542 | ||
543 | PREREQ=GPG | |
544 | test_atom refs/tags/signed-empty subject '' | |
545 | test_atom refs/tags/signed-empty contents:subject '' | |
546 | test_atom refs/tags/signed-empty body "$sig" | |
547 | test_atom refs/tags/signed-empty contents:body '' | |
548 | test_atom refs/tags/signed-empty contents:signature "$sig" | |
549 | test_atom refs/tags/signed-empty contents "$sig" | |
550 | ||
551 | test_atom refs/tags/signed-short subject 'subject line' | |
552 | test_atom refs/tags/signed-short contents:subject 'subject line' | |
553 | test_atom refs/tags/signed-short body "$sig" | |
554 | test_atom refs/tags/signed-short contents:body '' | |
555 | test_atom refs/tags/signed-short contents:signature "$sig" | |
556 | test_atom refs/tags/signed-short contents "subject line | |
557 | $sig" | |
558 | ||
559 | test_atom refs/tags/signed-long subject 'subject line' | |
560 | test_atom refs/tags/signed-long contents:subject 'subject line' | |
561 | test_atom refs/tags/signed-long body "body contents | |
562 | $sig" | |
563 | test_atom refs/tags/signed-long contents:body 'body contents | |
564 | ' | |
565 | test_atom refs/tags/signed-long contents:signature "$sig" | |
566 | test_atom refs/tags/signed-long contents "subject line | |
567 | ||
568 | body contents | |
569 | $sig" | |
570 | ||
189a5467 | 571 | cat >expected <<EOF |
189a5467 | 572 | $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo |
db7bae25 | 573 | $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master |
912072d5 KK |
574 | EOF |
575 | ||
3b51222c | 576 | test_expect_success 'Verify sort with multiple keys' ' |
912072d5 KK |
577 | git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \ |
578 | refs/tags/bogo refs/tags/master > actual && | |
579 | test_cmp expected actual | |
580 | ' | |
84679d47 | 581 | |
01f95825 | 582 | |
84679d47 JH |
583 | test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' |
584 | test_when_finished "git checkout master" && | |
585 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && | |
586 | sed -e "s/^\* / /" actual >expect && | |
f0252ca2 | 587 | git checkout --orphan orphaned-branch && |
84679d47 JH |
588 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
589 | test_cmp expect actual | |
590 | ' | |
591 | ||
b1d31c89 JK |
592 | cat >trailers <<EOF |
593 | Reviewed-by: A U Thor <author@example.com> | |
594 | Signed-off-by: A U Thor <author@example.com> | |
595 | EOF | |
596 | ||
597 | test_expect_success 'basic atom: head contents:trailers' ' | |
598 | echo "Some contents" > two && | |
599 | git add two && | |
600 | git commit -F - <<-EOF && | |
601 | trailers: this commit message has trailers | |
602 | ||
603 | Some message contents | |
604 | ||
605 | $(cat trailers) | |
606 | EOF | |
607 | git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual && | |
608 | sanitize_pgp <actual >actual.clean && | |
609 | # git for-each-ref ends with a blank line | |
610 | cat >expect <<-EOF && | |
611 | $(cat trailers) | |
612 | ||
613 | EOF | |
614 | test_cmp expect actual.clean | |
615 | ' | |
616 | ||
01f95825 KN |
617 | test_expect_success 'Add symbolic ref for the following tests' ' |
618 | git symbolic-ref refs/heads/sym refs/heads/master | |
619 | ' | |
620 | ||
621 | cat >expected <<EOF | |
622 | refs/heads/master | |
623 | EOF | |
624 | ||
625 | test_expect_success 'Verify usage of %(symref) atom' ' | |
626 | git for-each-ref --format="%(symref)" refs/heads/sym >actual && | |
627 | test_cmp expected actual | |
628 | ' | |
629 | ||
630 | cat >expected <<EOF | |
631 | heads/master | |
632 | EOF | |
633 | ||
634 | test_expect_success 'Verify usage of %(symref:short) atom' ' | |
635 | git for-each-ref --format="%(symref:short)" refs/heads/sym >actual && | |
636 | test_cmp expected actual | |
637 | ' | |
638 | ||
a7984101 KN |
639 | cat >expected <<EOF |
640 | master | |
1a0ca5e3 | 641 | heads/master |
a7984101 KN |
642 | EOF |
643 | ||
17938f17 KN |
644 | test_expect_success 'Verify usage of %(symref:lstrip) atom' ' |
645 | git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual && | |
1a0ca5e3 | 646 | git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual && |
44a6b6ce JH |
647 | test_cmp expected actual && |
648 | ||
649 | git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual && | |
650 | git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual && | |
a7984101 KN |
651 | test_cmp expected actual |
652 | ' | |
653 | ||
1a34728e KN |
654 | cat >expected <<EOF |
655 | refs | |
656 | refs/heads | |
657 | EOF | |
658 | ||
659 | test_expect_success 'Verify usage of %(symref:rstrip) atom' ' | |
660 | git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual && | |
661 | git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual && | |
662 | test_cmp expected actual | |
663 | ' | |
664 | ||
96b2d4fa | 665 | test_done |