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