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