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