]>
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 ' |
1f5f8f3e | 23 | test_oid_cache <<-EOF && |
24 | disklen sha1:138 | |
25 | disklen sha256:154 | |
26 | EOF | |
96b2d4fa AP |
27 | setdate_and_increment && |
28 | echo "Using $datestamp" > one && | |
29 | git add one && | |
30 | git commit -m "Initial" && | |
31 | setdate_and_increment && | |
bc147968 | 32 | git tag -a -m "Tagging at $datestamp" testtag && |
8cae19d9 JK |
33 | git update-ref refs/remotes/origin/master master && |
34 | git remote add origin nowhere && | |
35 | git config branch.master.remote origin && | |
29bc8850 JK |
36 | git config branch.master.merge refs/heads/master && |
37 | git remote add myfork elsewhere && | |
38 | git config remote.pushdefault myfork && | |
39 | git config push.default current | |
8cae19d9 JK |
40 | ' |
41 | ||
d2bf48d2 JK |
42 | test_atom() { |
43 | case "$1" in | |
44 | head) ref=refs/heads/master ;; | |
45 | tag) ref=refs/tags/testtag ;; | |
01f95825 | 46 | sym) ref=refs/heads/sym ;; |
7140c22c | 47 | *) ref=$1 ;; |
d2bf48d2 JK |
48 | esac |
49 | printf '%s\n' "$3" >expected | |
e2b23972 | 50 | test_expect_${4:-success} $PREREQ "basic atom: $1 $2" " |
d2bf48d2 | 51 | git for-each-ref --format='%($2)' $ref >actual && |
e2b23972 MG |
52 | sanitize_pgp <actual >actual.clean && |
53 | test_cmp expected actual.clean | |
d2bf48d2 | 54 | " |
b6839fda CC |
55 | # Automatically test "contents:size" atom after testing "contents" |
56 | if test "$2" = "contents" | |
57 | then | |
58 | case $(git cat-file -t "$ref") in | |
59 | tag) | |
60 | # We cannot use $3 as it expects sanitize_pgp to run | |
61 | expect=$(git cat-file tag $ref | tail -n +6 | wc -c) ;; | |
62 | tree | blob) | |
63 | expect='' ;; | |
64 | commit) | |
65 | expect=$(printf '%s' "$3" | wc -c) ;; | |
66 | esac | |
67 | # Leave $expect unquoted to lose possible leading whitespaces | |
68 | echo $expect >expected | |
3db796c1 | 69 | test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" ' |
b6839fda | 70 | git for-each-ref --format="%(contents:size)" "$ref" >actual && |
3db796c1 | 71 | test_cmp expected actual |
b6839fda CC |
72 | ' |
73 | fi | |
d2bf48d2 JK |
74 | } |
75 | ||
1f5f8f3e | 76 | hexlen=$(test_oid hexsz) |
77 | disklen=$(test_oid disklen) | |
78 | ||
d2bf48d2 | 79 | test_atom head refname refs/heads/master |
bea4dbea | 80 | test_atom head refname: refs/heads/master |
1d094db9 | 81 | test_atom head refname:short master |
17938f17 KN |
82 | test_atom head refname:lstrip=1 heads/master |
83 | test_atom head refname:lstrip=2 master | |
1a0ca5e3 KN |
84 | test_atom head refname:lstrip=-1 master |
85 | test_atom head refname:lstrip=-2 heads/master | |
1a34728e KN |
86 | test_atom head refname:rstrip=1 refs/heads |
87 | test_atom head refname:rstrip=2 refs | |
88 | test_atom head refname:rstrip=-1 refs | |
89 | test_atom head refname:rstrip=-2 refs/heads | |
44a6b6ce JH |
90 | test_atom head refname:strip=1 heads/master |
91 | test_atom head refname:strip=2 master | |
92 | test_atom head refname:strip=-1 master | |
93 | test_atom head refname:strip=-2 heads/master | |
8cae19d9 | 94 | test_atom head upstream refs/remotes/origin/master |
1d094db9 | 95 | test_atom head upstream:short origin/master |
17938f17 | 96 | test_atom head upstream:lstrip=2 origin/master |
1a0ca5e3 | 97 | test_atom head upstream:lstrip=-2 origin/master |
1a34728e KN |
98 | test_atom head upstream:rstrip=2 refs/remotes |
99 | test_atom head upstream:rstrip=-2 refs/remotes | |
44a6b6ce JH |
100 | test_atom head upstream:strip=2 origin/master |
101 | test_atom head upstream:strip=-2 origin/master | |
29bc8850 | 102 | test_atom head push refs/remotes/myfork/master |
1d094db9 | 103 | test_atom head push:short myfork/master |
17938f17 | 104 | test_atom head push:lstrip=1 remotes/myfork/master |
1a0ca5e3 | 105 | test_atom head push:lstrip=-1 master |
1a34728e KN |
106 | test_atom head push:rstrip=1 refs/remotes/myfork |
107 | test_atom head push:rstrip=-1 refs | |
44a6b6ce JH |
108 | test_atom head push:strip=1 remotes/myfork/master |
109 | test_atom head push:strip=-1 master | |
d2bf48d2 | 110 | test_atom head objecttype commit |
1f5f8f3e | 111 | test_atom head objectsize $((131 + hexlen)) |
112 | test_atom head objectsize:disk $disklen | |
113 | test_atom head deltabase $ZERO_OID | |
189a5467 | 114 | test_atom head objectname $(git rev-parse refs/heads/master) |
1d094db9 | 115 | test_atom head objectname:short $(git rev-parse --short refs/heads/master) |
42d0eb05 KN |
116 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) |
117 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) | |
189a5467 | 118 | test_atom head tree $(git rev-parse refs/heads/master^{tree}) |
837adb10 HV |
119 | test_atom head tree:short $(git rev-parse --short refs/heads/master^{tree}) |
120 | test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/master^{tree}) | |
121 | test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/master^{tree}) | |
d2bf48d2 | 122 | test_atom head parent '' |
26bc0aaf HV |
123 | test_atom head parent:short '' |
124 | test_atom head parent:short=1 '' | |
125 | test_atom head parent:short=10 '' | |
d2bf48d2 JK |
126 | test_atom head numparent 0 |
127 | test_atom head object '' | |
128 | test_atom head type '' | |
b74cf648 JK |
129 | test_atom head '*objectname' '' |
130 | test_atom head '*objecttype' '' | |
db7bae25 | 131 | test_atom head author 'A U Thor <author@example.com> 1151968724 +0200' |
d2bf48d2 JK |
132 | test_atom head authorname 'A U Thor' |
133 | test_atom head authoremail '<author@example.com>' | |
b82445dc HV |
134 | test_atom head authoremail:trim 'author@example.com' |
135 | test_atom head authoremail:localpart 'author' | |
db7bae25 JK |
136 | test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' |
137 | test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200' | |
d2bf48d2 JK |
138 | test_atom head committername 'C O Mitter' |
139 | test_atom head committeremail '<committer@example.com>' | |
b82445dc HV |
140 | test_atom head committeremail:trim 'committer@example.com' |
141 | test_atom head committeremail:localpart 'committer' | |
db7bae25 | 142 | test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' |
d2bf48d2 JK |
143 | test_atom head tag '' |
144 | test_atom head tagger '' | |
145 | test_atom head taggername '' | |
146 | test_atom head taggeremail '' | |
b82445dc HV |
147 | test_atom head taggeremail:trim '' |
148 | test_atom head taggeremail:localpart '' | |
d2bf48d2 | 149 | test_atom head taggerdate '' |
db7bae25 JK |
150 | test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200' |
151 | test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' | |
d2bf48d2 | 152 | test_atom head subject 'Initial' |
905f0a4e | 153 | test_atom head subject:sanitize 'Initial' |
e2b23972 | 154 | test_atom head contents:subject 'Initial' |
d2bf48d2 | 155 | test_atom head body '' |
e2b23972 MG |
156 | test_atom head contents:body '' |
157 | test_atom head contents:signature '' | |
d2bf48d2 JK |
158 | test_atom head contents 'Initial |
159 | ' | |
7a48b832 | 160 | test_atom head HEAD '*' |
d2bf48d2 JK |
161 | |
162 | test_atom tag refname refs/tags/testtag | |
1d094db9 | 163 | test_atom tag refname:short testtag |
8cae19d9 | 164 | test_atom tag upstream '' |
29bc8850 | 165 | test_atom tag push '' |
d2bf48d2 | 166 | test_atom tag objecttype tag |
1f5f8f3e | 167 | test_atom tag objectsize $((114 + hexlen)) |
168 | test_atom tag objectsize:disk $disklen | |
169 | test_atom tag '*objectsize:disk' $disklen | |
170 | test_atom tag deltabase $ZERO_OID | |
171 | test_atom tag '*deltabase' $ZERO_OID | |
189a5467 | 172 | test_atom tag objectname $(git rev-parse refs/tags/testtag) |
1d094db9 | 173 | test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) |
42d0eb05 KN |
174 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) |
175 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) | |
d2bf48d2 | 176 | test_atom tag tree '' |
837adb10 HV |
177 | test_atom tag tree:short '' |
178 | test_atom tag tree:short=1 '' | |
179 | test_atom tag tree:short=10 '' | |
d2bf48d2 | 180 | test_atom tag parent '' |
26bc0aaf HV |
181 | test_atom tag parent:short '' |
182 | test_atom tag parent:short=1 '' | |
183 | test_atom tag parent:short=10 '' | |
d2bf48d2 | 184 | test_atom tag numparent '' |
189a5467 | 185 | test_atom tag object $(git rev-parse refs/tags/testtag^0) |
d2bf48d2 | 186 | test_atom tag type 'commit' |
1f5f8f3e | 187 | test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{}) |
b74cf648 | 188 | test_atom tag '*objecttype' 'commit' |
d2bf48d2 JK |
189 | test_atom tag author '' |
190 | test_atom tag authorname '' | |
191 | test_atom tag authoremail '' | |
b82445dc HV |
192 | test_atom tag authoremail:trim '' |
193 | test_atom tag authoremail:localpart '' | |
d2bf48d2 JK |
194 | test_atom tag authordate '' |
195 | test_atom tag committer '' | |
196 | test_atom tag committername '' | |
197 | test_atom tag committeremail '' | |
b82445dc HV |
198 | test_atom tag committeremail:trim '' |
199 | test_atom tag committeremail:localpart '' | |
d2bf48d2 JK |
200 | test_atom tag committerdate '' |
201 | test_atom tag tag 'testtag' | |
db7bae25 | 202 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200' |
d2bf48d2 JK |
203 | test_atom tag taggername 'C O Mitter' |
204 | test_atom tag taggeremail '<committer@example.com>' | |
b82445dc HV |
205 | test_atom tag taggeremail:trim 'committer@example.com' |
206 | test_atom tag taggeremail:localpart 'committer' | |
db7bae25 JK |
207 | test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' |
208 | test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200' | |
209 | test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' | |
210 | test_atom tag subject 'Tagging at 1151968727' | |
905f0a4e | 211 | test_atom tag subject:sanitize 'Tagging-at-1151968727' |
db7bae25 | 212 | test_atom tag contents:subject 'Tagging at 1151968727' |
d2bf48d2 | 213 | test_atom tag body '' |
e2b23972 MG |
214 | test_atom tag contents:body '' |
215 | test_atom tag contents:signature '' | |
db7bae25 | 216 | test_atom tag contents 'Tagging at 1151968727 |
96b2d4fa | 217 | ' |
7a48b832 | 218 | test_atom tag HEAD ' ' |
96b2d4fa | 219 | |
41ac414e | 220 | test_expect_success 'Check invalid atoms names are errors' ' |
3604e7c5 | 221 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
96b2d4fa AP |
222 | ' |
223 | ||
224 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' | |
3604e7c5 NS |
225 | git for-each-ref --format="%(authordate)" refs/heads && |
226 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && | |
227 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && | |
228 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads | |
96b2d4fa AP |
229 | ' |
230 | ||
231 | test_expect_success 'Check valid format specifiers for date fields' ' | |
3604e7c5 NS |
232 | git for-each-ref --format="%(authordate:default)" refs/heads && |
233 | git for-each-ref --format="%(authordate:relative)" refs/heads && | |
234 | git for-each-ref --format="%(authordate:short)" refs/heads && | |
235 | git for-each-ref --format="%(authordate:local)" refs/heads && | |
236 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && | |
237 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads | |
96b2d4fa AP |
238 | ' |
239 | ||
41ac414e | 240 | test_expect_success 'Check invalid format specifiers are errors' ' |
3604e7c5 | 241 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
96b2d4fa AP |
242 | ' |
243 | ||
42d0eb05 KN |
244 | test_expect_success 'arguments to %(objectname:short=) must be positive integers' ' |
245 | test_must_fail git for-each-ref --format="%(objectname:short=0)" && | |
246 | test_must_fail git for-each-ref --format="%(objectname:short=-1)" && | |
247 | test_must_fail git for-each-ref --format="%(objectname:short=foo)" | |
248 | ' | |
249 | ||
f95cecf4 JK |
250 | test_date () { |
251 | f=$1 && | |
252 | committer_date=$2 && | |
253 | author_date=$3 && | |
254 | tagger_date=$4 && | |
255 | cat >expected <<-EOF && | |
256 | 'refs/heads/master' '$committer_date' '$author_date' | |
257 | 'refs/tags/testtag' '$tagger_date' | |
258 | EOF | |
259 | ( | |
260 | git for-each-ref --shell \ | |
261 | --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \ | |
262 | refs/heads && | |
263 | git for-each-ref --shell \ | |
264 | --format="%(refname) %(taggerdate${f:+:$f})" \ | |
265 | refs/tags | |
266 | ) >actual && | |
267 | test_cmp expected actual | |
268 | } | |
96b2d4fa AP |
269 | |
270 | test_expect_success 'Check unformatted date fields output' ' | |
f95cecf4 | 271 | test_date "" \ |
db7bae25 JK |
272 | "Tue Jul 4 01:18:43 2006 +0200" \ |
273 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
274 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
275 | ' |
276 | ||
277 | test_expect_success 'Check format "default" formatted date fields output' ' | |
f95cecf4 | 278 | test_date default \ |
db7bae25 JK |
279 | "Tue Jul 4 01:18:43 2006 +0200" \ |
280 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
281 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
282 | ' |
283 | ||
99264e93 JK |
284 | test_expect_success 'Check format "default-local" date fields output' ' |
285 | 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 |
286 | ' |
287 | ||
288 | # Don't know how to do relative check because I can't know when this script | |
289 | # is going to be run and can't fake the current time to git, and hence can't | |
290 | # provide expected output. Instead, I'll just make sure that "relative" | |
291 | # doesn't exit in error | |
96b2d4fa AP |
292 | test_expect_success 'Check format "relative" date fields output' ' |
293 | f=relative && | |
294 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
295 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual | |
296 | ' | |
297 | ||
99264e93 JK |
298 | # We just check that this is the same as "relative" for now. |
299 | test_expect_success 'Check format "relative-local" date fields output' ' | |
300 | test_date relative-local \ | |
301 | "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \ | |
302 | "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \ | |
303 | "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)" | |
304 | ' | |
96b2d4fa AP |
305 | |
306 | test_expect_success 'Check format "short" date fields output' ' | |
db7bae25 | 307 | test_date short 2006-07-04 2006-07-04 2006-07-04 |
96b2d4fa AP |
308 | ' |
309 | ||
99264e93 JK |
310 | test_expect_success 'Check format "short-local" date fields output' ' |
311 | test_date short-local 2006-07-03 2006-07-03 2006-07-03 | |
312 | ' | |
96b2d4fa AP |
313 | |
314 | test_expect_success 'Check format "local" date fields output' ' | |
f95cecf4 | 315 | test_date local \ |
db7bae25 JK |
316 | "Mon Jul 3 23:18:43 2006" \ |
317 | "Mon Jul 3 23:18:44 2006" \ | |
318 | "Mon Jul 3 23:18:45 2006" | |
96b2d4fa AP |
319 | ' |
320 | ||
96b2d4fa | 321 | test_expect_success 'Check format "iso8601" date fields output' ' |
f95cecf4 | 322 | test_date iso8601 \ |
db7bae25 JK |
323 | "2006-07-04 01:18:43 +0200" \ |
324 | "2006-07-04 01:18:44 +0200" \ | |
325 | "2006-07-04 01:18:45 +0200" | |
96b2d4fa AP |
326 | ' |
327 | ||
99264e93 JK |
328 | test_expect_success 'Check format "iso8601-local" date fields output' ' |
329 | 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" | |
330 | ' | |
96b2d4fa AP |
331 | |
332 | test_expect_success 'Check format "rfc2822" date fields output' ' | |
f95cecf4 | 333 | test_date rfc2822 \ |
db7bae25 JK |
334 | "Tue, 4 Jul 2006 01:18:43 +0200" \ |
335 | "Tue, 4 Jul 2006 01:18:44 +0200" \ | |
336 | "Tue, 4 Jul 2006 01:18:45 +0200" | |
96b2d4fa AP |
337 | ' |
338 | ||
99264e93 JK |
339 | test_expect_success 'Check format "rfc2822-local" date fields output' ' |
340 | 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" | |
341 | ' | |
342 | ||
f3c1ba50 | 343 | test_expect_success 'Check format "raw" date fields output' ' |
db7bae25 | 344 | test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200" |
f3c1ba50 JK |
345 | ' |
346 | ||
99264e93 JK |
347 | test_expect_success 'Check format "raw-local" date fields output' ' |
348 | test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000" | |
96b2d4fa AP |
349 | ' |
350 | ||
aa1462cc | 351 | test_expect_success 'Check format of strftime date fields' ' |
db7bae25 | 352 | echo "my date is 2006-07-04" >expected && |
aa1462cc JK |
353 | git for-each-ref \ |
354 | --format="%(authordate:format:my date is %Y-%m-%d)" \ | |
355 | refs/heads >actual && | |
356 | test_cmp expected actual | |
357 | ' | |
358 | ||
99264e93 JK |
359 | test_expect_success 'Check format of strftime-local date fields' ' |
360 | echo "my date is 2006-07-03" >expected && | |
361 | git for-each-ref \ | |
362 | --format="%(authordate:format-local:my date is %Y-%m-%d)" \ | |
363 | refs/heads >actual && | |
364 | test_cmp expected actual | |
365 | ' | |
366 | ||
e4f031e3 JK |
367 | test_expect_success 'exercise strftime with odd fields' ' |
368 | echo >expected && | |
369 | git for-each-ref --format="%(authordate:format:)" refs/heads >actual && | |
370 | test_cmp expected actual && | |
8125a58b | 371 | long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" && |
e4f031e3 JK |
372 | echo $long >expected && |
373 | git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && | |
374 | test_cmp expected actual | |
375 | ' | |
376 | ||
c899a57c LH |
377 | cat >expected <<\EOF |
378 | refs/heads/master | |
8cae19d9 | 379 | refs/remotes/origin/master |
c899a57c LH |
380 | refs/tags/testtag |
381 | EOF | |
382 | ||
383 | test_expect_success 'Verify ascending sort' ' | |
3604e7c5 | 384 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
3af82863 | 385 | test_cmp expected actual |
c899a57c LH |
386 | ' |
387 | ||
388 | ||
389 | cat >expected <<\EOF | |
390 | refs/tags/testtag | |
8cae19d9 | 391 | refs/remotes/origin/master |
c899a57c LH |
392 | refs/heads/master |
393 | EOF | |
394 | ||
395 | test_expect_success 'Verify descending sort' ' | |
3604e7c5 | 396 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
3af82863 | 397 | test_cmp expected actual |
b31e2680 TB |
398 | ' |
399 | ||
400 | cat >expected <<\EOF | |
401 | refs/tags/testtag | |
402 | refs/tags/testtag-2 | |
403 | EOF | |
404 | ||
405 | test_expect_success 'exercise patterns with prefixes' ' | |
406 | git tag testtag-2 && | |
407 | test_when_finished "git tag -d testtag-2" && | |
408 | git for-each-ref --format="%(refname)" \ | |
409 | refs/tags/testtag refs/tags/testtag-2 >actual && | |
410 | test_cmp expected actual | |
411 | ' | |
412 | ||
413 | cat >expected <<\EOF | |
414 | refs/tags/testtag | |
415 | refs/tags/testtag-2 | |
416 | EOF | |
417 | ||
418 | test_expect_success 'exercise glob patterns with prefixes' ' | |
419 | git tag testtag-2 && | |
420 | test_when_finished "git tag -d testtag-2" && | |
421 | git for-each-ref --format="%(refname)" \ | |
422 | refs/tags/testtag "refs/tags/testtag-*" >actual && | |
423 | test_cmp expected actual | |
c899a57c LH |
424 | ' |
425 | ||
c9ecf4f1 JS |
426 | cat >expected <<\EOF |
427 | 'refs/heads/master' | |
8cae19d9 | 428 | 'refs/remotes/origin/master' |
c9ecf4f1 JS |
429 | 'refs/tags/testtag' |
430 | EOF | |
431 | ||
432 | test_expect_success 'Quoting style: shell' ' | |
433 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 434 | test_cmp expected actual |
c9ecf4f1 JS |
435 | ' |
436 | ||
437 | test_expect_success 'Quoting style: perl' ' | |
438 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 439 | test_cmp expected actual |
c9ecf4f1 JS |
440 | ' |
441 | ||
442 | test_expect_success 'Quoting style: python' ' | |
443 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 444 | test_cmp expected actual |
c9ecf4f1 JS |
445 | ' |
446 | ||
447 | cat >expected <<\EOF | |
448 | "refs/heads/master" | |
8cae19d9 | 449 | "refs/remotes/origin/master" |
c9ecf4f1 JS |
450 | "refs/tags/testtag" |
451 | EOF | |
452 | ||
453 | test_expect_success 'Quoting style: tcl' ' | |
454 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 455 | test_cmp expected actual |
c9ecf4f1 JS |
456 | ' |
457 | ||
458 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do | |
459 | test_expect_success "more than one quoting style: $i" " | |
2708ef4a SG |
460 | test_must_fail git for-each-ref $i 2>err && |
461 | grep '^error: more than one quoting style' err | |
c9ecf4f1 JS |
462 | " |
463 | done | |
c899a57c | 464 | |
b28061ce RR |
465 | test_expect_success 'setup for upstream:track[short]' ' |
466 | test_commit two | |
467 | ' | |
468 | ||
1d094db9 JK |
469 | test_atom head upstream:track '[ahead 1]' |
470 | test_atom head upstream:trackshort '>' | |
7743fcca KN |
471 | test_atom head upstream:track,nobracket 'ahead 1' |
472 | test_atom head upstream:nobracket,track 'ahead 1' | |
c646d093 DR |
473 | |
474 | test_expect_success 'setup for push:track[short]' ' | |
475 | test_commit third && | |
476 | git update-ref refs/remotes/myfork/master master && | |
477 | git reset master~1 | |
478 | ' | |
479 | ||
480 | test_atom head push:track '[behind 1]' | |
481 | test_atom head push:trackshort '<' | |
b28061ce RR |
482 | |
483 | test_expect_success 'Check that :track[short] cannot be used with other atoms' ' | |
484 | test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && | |
485 | test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null | |
486 | ' | |
487 | ||
b6160d95 RKC |
488 | test_expect_success 'Check that :track[short] works when upstream is invalid' ' |
489 | cat >expected <<-\EOF && | |
ffd921d3 | 490 | [gone] |
b6160d95 RKC |
491 | |
492 | EOF | |
493 | test_when_finished "git config branch.master.merge refs/heads/master" && | |
494 | git config branch.master.merge refs/heads/does-not-exist && | |
495 | git for-each-ref \ | |
496 | --format="%(upstream:track)$LF%(upstream:trackshort)" \ | |
497 | refs/heads >actual && | |
498 | test_cmp expected actual | |
29bc8850 JK |
499 | ' |
500 | ||
7d66f21a BW |
501 | test_expect_success 'Check for invalid refname format' ' |
502 | test_must_fail git for-each-ref --format="%(refname:INVALID)" | |
503 | ' | |
504 | ||
11b087ad JK |
505 | test_expect_success 'set up color tests' ' |
506 | cat >expected.color <<-EOF && | |
507 | $(git rev-parse --short refs/heads/master) <GREEN>master<RESET> | |
c646d093 | 508 | $(git rev-parse --short refs/remotes/myfork/master) <GREEN>myfork/master<RESET> |
11b087ad JK |
509 | $(git rev-parse --short refs/remotes/origin/master) <GREEN>origin/master<RESET> |
510 | $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> | |
c646d093 | 511 | $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> |
11b087ad JK |
512 | $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> |
513 | EOF | |
514 | sed "s/<[^>]*>//g" <expected.color >expected.bare && | |
515 | color_format="%(objectname:short) %(color:green)%(refname:short)" | |
516 | ' | |
fddb74c9 | 517 | |
11b087ad | 518 | test_expect_success TTY '%(color) shows color with a tty' ' |
e433749d | 519 | test_terminal git for-each-ref --format="$color_format" >actual.raw && |
097b681b | 520 | test_decode_color <actual.raw >actual && |
11b087ad JK |
521 | test_cmp expected.color actual |
522 | ' | |
523 | ||
524 | test_expect_success '%(color) does not show color without tty' ' | |
525 | TERM=vt100 git for-each-ref --format="$color_format" >actual && | |
526 | test_cmp expected.bare actual | |
527 | ' | |
528 | ||
0c88bf50 JK |
529 | test_expect_success '--color can override tty check' ' |
530 | git for-each-ref --color --format="$color_format" >actual.raw && | |
11b087ad JK |
531 | test_decode_color <actual.raw >actual && |
532 | test_cmp expected.color actual | |
fddb74c9 RR |
533 | ' |
534 | ||
b521fd12 JK |
535 | test_expect_success 'color.ui=always does not override tty check' ' |
536 | git -c color.ui=always for-each-ref --format="$color_format" >actual && | |
537 | test_cmp expected.bare actual | |
538 | ' | |
539 | ||
7d66f21a BW |
540 | cat >expected <<\EOF |
541 | heads/master | |
2bb98169 | 542 | tags/master |
7d66f21a BW |
543 | EOF |
544 | ||
2bb98169 BW |
545 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
546 | git config --bool core.warnambiguousrefs true && | |
7d66f21a BW |
547 | git checkout -b newtag && |
548 | echo "Using $datestamp" > one && | |
549 | git add one && | |
550 | git commit -m "Branch" && | |
551 | setdate_and_increment && | |
552 | git tag -m "Tagging at $datestamp" master && | |
553 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
554 | test_cmp expected actual | |
555 | ' | |
556 | ||
2bb98169 BW |
557 | cat >expected <<\EOF |
558 | heads/master | |
559 | master | |
560 | EOF | |
561 | ||
562 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' | |
563 | git config --bool core.warnambiguousrefs false && | |
564 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
565 | test_cmp expected actual | |
566 | ' | |
567 | ||
7d66f21a BW |
568 | cat >expected <<\EOF |
569 | heads/ambiguous | |
570 | ambiguous | |
571 | EOF | |
572 | ||
2bb98169 | 573 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
7d66f21a BW |
574 | git checkout master && |
575 | git tag ambiguous testtag^0 && | |
576 | git branch ambiguous testtag^0 && | |
577 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && | |
578 | test_cmp expected actual | |
579 | ' | |
580 | ||
8b3f33ef MP |
581 | test_expect_success 'create tag without tagger' ' |
582 | git tag -a -m "Broken tag" taggerless && | |
583 | git tag -f taggerless $(git cat-file tag taggerless | | |
584 | sed -e "/^tagger /d" | | |
585 | git hash-object --stdin -w -t tag) | |
586 | ' | |
587 | ||
588 | test_atom refs/tags/taggerless type 'commit' | |
589 | test_atom refs/tags/taggerless tag 'taggerless' | |
590 | test_atom refs/tags/taggerless tagger '' | |
591 | test_atom refs/tags/taggerless taggername '' | |
592 | test_atom refs/tags/taggerless taggeremail '' | |
b82445dc HV |
593 | test_atom refs/tags/taggerless taggeremail:trim '' |
594 | test_atom refs/tags/taggerless taggeremail:localpart '' | |
8b3f33ef MP |
595 | test_atom refs/tags/taggerless taggerdate '' |
596 | test_atom refs/tags/taggerless committer '' | |
597 | test_atom refs/tags/taggerless committername '' | |
598 | test_atom refs/tags/taggerless committeremail '' | |
b82445dc HV |
599 | test_atom refs/tags/taggerless committeremail:trim '' |
600 | test_atom refs/tags/taggerless committeremail:localpart '' | |
8b3f33ef MP |
601 | test_atom refs/tags/taggerless committerdate '' |
602 | test_atom refs/tags/taggerless subject 'Broken tag' | |
603 | ||
e276c26b JH |
604 | test_expect_success 'an unusual tag with an incomplete line' ' |
605 | ||
606 | git tag -m "bogo" bogo && | |
607 | bogo=$(git cat-file tag bogo) && | |
608 | bogo=$(printf "%s" "$bogo" | git mktag) && | |
609 | git tag -f bogo "$bogo" && | |
610 | git for-each-ref --format "%(body)" refs/tags/bogo | |
611 | ||
612 | ' | |
613 | ||
7140c22c JK |
614 | test_expect_success 'create tag with subject and body content' ' |
615 | cat >>msg <<-\EOF && | |
616 | the subject line | |
617 | ||
618 | first body line | |
619 | second body line | |
620 | EOF | |
621 | git tag -F msg subject-body | |
622 | ' | |
623 | test_atom refs/tags/subject-body subject 'the subject line' | |
905f0a4e | 624 | test_atom refs/tags/subject-body subject:sanitize 'the-subject-line' |
7140c22c JK |
625 | test_atom refs/tags/subject-body body 'first body line |
626 | second body line | |
627 | ' | |
628 | test_atom refs/tags/subject-body contents 'the subject line | |
629 | ||
630 | first body line | |
631 | second body line | |
632 | ' | |
633 | ||
7f6e275b JK |
634 | test_expect_success 'create tag with multiline subject' ' |
635 | cat >msg <<-\EOF && | |
636 | first subject line | |
637 | second subject line | |
638 | ||
639 | first body line | |
640 | second body line | |
641 | EOF | |
642 | git tag -F msg multiline | |
643 | ' | |
644 | test_atom refs/tags/multiline subject 'first subject line second subject line' | |
905f0a4e | 645 | test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line' |
e2b23972 | 646 | test_atom refs/tags/multiline contents:subject 'first subject line second subject line' |
7f6e275b JK |
647 | test_atom refs/tags/multiline body 'first body line |
648 | second body line | |
649 | ' | |
e2b23972 MG |
650 | test_atom refs/tags/multiline contents:body 'first body line |
651 | second body line | |
652 | ' | |
653 | test_atom refs/tags/multiline contents:signature '' | |
7f6e275b JK |
654 | test_atom refs/tags/multiline contents 'first subject line |
655 | second subject line | |
656 | ||
657 | first body line | |
658 | second body line | |
659 | ' | |
660 | ||
e2b23972 MG |
661 | test_expect_success GPG 'create signed tags' ' |
662 | git tag -s -m "" signed-empty && | |
663 | git tag -s -m "subject line" signed-short && | |
664 | cat >msg <<-\EOF && | |
665 | subject line | |
666 | ||
667 | body contents | |
668 | EOF | |
669 | git tag -s -F msg signed-long | |
670 | ' | |
671 | ||
672 | sig='-----BEGIN PGP SIGNATURE----- | |
673 | -----END PGP SIGNATURE----- | |
674 | ' | |
675 | ||
676 | PREREQ=GPG | |
677 | test_atom refs/tags/signed-empty subject '' | |
905f0a4e | 678 | test_atom refs/tags/signed-empty subject:sanitize '' |
e2b23972 MG |
679 | test_atom refs/tags/signed-empty contents:subject '' |
680 | test_atom refs/tags/signed-empty body "$sig" | |
681 | test_atom refs/tags/signed-empty contents:body '' | |
682 | test_atom refs/tags/signed-empty contents:signature "$sig" | |
683 | test_atom refs/tags/signed-empty contents "$sig" | |
684 | ||
685 | test_atom refs/tags/signed-short subject 'subject line' | |
905f0a4e | 686 | test_atom refs/tags/signed-short subject:sanitize 'subject-line' |
e2b23972 MG |
687 | test_atom refs/tags/signed-short contents:subject 'subject line' |
688 | test_atom refs/tags/signed-short body "$sig" | |
689 | test_atom refs/tags/signed-short contents:body '' | |
690 | test_atom refs/tags/signed-short contents:signature "$sig" | |
691 | test_atom refs/tags/signed-short contents "subject line | |
692 | $sig" | |
693 | ||
694 | test_atom refs/tags/signed-long subject 'subject line' | |
905f0a4e | 695 | test_atom refs/tags/signed-long subject:sanitize 'subject-line' |
e2b23972 MG |
696 | test_atom refs/tags/signed-long contents:subject 'subject line' |
697 | test_atom refs/tags/signed-long body "body contents | |
698 | $sig" | |
699 | test_atom refs/tags/signed-long contents:body 'body contents | |
700 | ' | |
701 | test_atom refs/tags/signed-long contents:signature "$sig" | |
702 | test_atom refs/tags/signed-long contents "subject line | |
703 | ||
704 | body contents | |
705 | $sig" | |
706 | ||
6e2ef8eb CC |
707 | test_expect_success 'set up refs pointing to tree and blob' ' |
708 | git update-ref refs/mytrees/first refs/heads/master^{tree} && | |
709 | git update-ref refs/myblobs/first refs/heads/master:one | |
710 | ' | |
711 | ||
712 | test_atom refs/mytrees/first subject "" | |
713 | test_atom refs/mytrees/first contents:subject "" | |
714 | test_atom refs/mytrees/first body "" | |
715 | test_atom refs/mytrees/first contents:body "" | |
716 | test_atom refs/mytrees/first contents:signature "" | |
717 | test_atom refs/mytrees/first contents "" | |
718 | ||
719 | test_atom refs/myblobs/first subject "" | |
720 | test_atom refs/myblobs/first contents:subject "" | |
721 | test_atom refs/myblobs/first body "" | |
722 | test_atom refs/myblobs/first contents:body "" | |
723 | test_atom refs/myblobs/first contents:signature "" | |
724 | test_atom refs/myblobs/first contents "" | |
725 | ||
7c5045fc JK |
726 | test_expect_success 'set up multiple-sort tags' ' |
727 | for when in 100000 200000 | |
728 | do | |
729 | for email in user1 user2 | |
730 | do | |
731 | for ref in ref1 ref2 | |
732 | do | |
733 | GIT_COMMITTER_DATE="@$when +0000" \ | |
734 | GIT_COMMITTER_EMAIL="$email@example.com" \ | |
735 | git tag -m "tag $ref-$when-$email" \ | |
736 | multi-$ref-$when-$email || return 1 | |
737 | done | |
738 | done | |
739 | done | |
740 | ' | |
912072d5 | 741 | |
3b51222c | 742 | test_expect_success 'Verify sort with multiple keys' ' |
7c5045fc JK |
743 | cat >expected <<-\EOF && |
744 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
745 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
746 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
747 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
748 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
749 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
750 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
751 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
752 | EOF | |
753 | git for-each-ref \ | |
754 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
755 | --sort=-refname \ | |
756 | --sort=taggeremail \ | |
757 | --sort=taggerdate \ | |
758 | "refs/tags/multi-*" >actual && | |
912072d5 KK |
759 | test_cmp expected actual |
760 | ' | |
84679d47 | 761 | |
7c5045fc JK |
762 | test_expect_success 'equivalent sorts fall back on refname' ' |
763 | cat >expected <<-\EOF && | |
764 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
765 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
766 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
767 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
768 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
769 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
770 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
771 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
772 | EOF | |
773 | git for-each-ref \ | |
774 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
775 | --sort=taggerdate \ | |
776 | "refs/tags/multi-*" >actual && | |
777 | test_cmp expected actual | |
778 | ' | |
01f95825 | 779 | |
84679d47 JH |
780 | test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' |
781 | test_when_finished "git checkout master" && | |
782 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && | |
783 | sed -e "s/^\* / /" actual >expect && | |
f0252ca2 | 784 | git checkout --orphan orphaned-branch && |
84679d47 JH |
785 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
786 | test_cmp expect actual | |
787 | ' | |
788 | ||
b1d31c89 JK |
789 | cat >trailers <<EOF |
790 | Reviewed-by: A U Thor <author@example.com> | |
791 | Signed-off-by: A U Thor <author@example.com> | |
624b44d3 TB |
792 | [ v2 updated patch description ] |
793 | Acked-by: A U Thor | |
794 | <author@example.com> | |
b1d31c89 JK |
795 | EOF |
796 | ||
67a20a00 TB |
797 | unfold () { |
798 | perl -0pe 's/\n\s+/ /g' | |
799 | } | |
624b44d3 TB |
800 | |
801 | test_expect_success 'set up trailers for next test' ' | |
b1d31c89 JK |
802 | echo "Some contents" > two && |
803 | git add two && | |
624b44d3 | 804 | git commit -F - <<-EOF |
b1d31c89 JK |
805 | trailers: this commit message has trailers |
806 | ||
807 | Some message contents | |
808 | ||
809 | $(cat trailers) | |
810 | EOF | |
624b44d3 TB |
811 | ' |
812 | ||
67a20a00 TB |
813 | test_expect_success '%(trailers:unfold) unfolds trailers' ' |
814 | git for-each-ref --format="%(trailers:unfold)" refs/heads/master >actual && | |
815 | { | |
816 | unfold <trailers | |
817 | echo | |
818 | } >expect && | |
819 | test_cmp expect actual | |
820 | ' | |
821 | ||
822 | test_expect_success '%(trailers:only) shows only "key: value" trailers' ' | |
823 | git for-each-ref --format="%(trailers:only)" refs/heads/master >actual && | |
824 | { | |
825 | grep -v patch.description <trailers && | |
826 | echo | |
827 | } >expect && | |
828 | test_cmp expect actual | |
829 | ' | |
830 | ||
831 | test_expect_success '%(trailers:only) and %(trailers:unfold) work together' ' | |
832 | git for-each-ref --format="%(trailers:only,unfold)" refs/heads/master >actual && | |
833 | git for-each-ref --format="%(trailers:unfold,only)" refs/heads/master >reverse && | |
834 | test_cmp actual reverse && | |
835 | { | |
836 | grep -v patch.description <trailers | unfold && | |
837 | echo | |
838 | } >expect && | |
839 | test_cmp expect actual | |
840 | ' | |
841 | ||
7a5edbdb TB |
842 | test_expect_success '%(contents:trailers:unfold) unfolds trailers' ' |
843 | git for-each-ref --format="%(contents:trailers:unfold)" refs/heads/master >actual && | |
844 | { | |
845 | unfold <trailers | |
846 | echo | |
847 | } >expect && | |
848 | test_cmp expect actual | |
849 | ' | |
850 | ||
851 | test_expect_success '%(contents:trailers:only) shows only "key: value" trailers' ' | |
852 | git for-each-ref --format="%(contents:trailers:only)" refs/heads/master >actual && | |
853 | { | |
854 | grep -v patch.description <trailers && | |
855 | echo | |
856 | } >expect && | |
857 | test_cmp expect actual | |
858 | ' | |
859 | ||
860 | test_expect_success '%(contents:trailers:only) and %(contents:trailers:unfold) work together' ' | |
861 | git for-each-ref --format="%(contents:trailers:only,unfold)" refs/heads/master >actual && | |
862 | git for-each-ref --format="%(contents:trailers:unfold,only)" refs/heads/master >reverse && | |
863 | test_cmp actual reverse && | |
864 | { | |
865 | grep -v patch.description <trailers | unfold && | |
866 | echo | |
867 | } >expect && | |
868 | test_cmp expect actual | |
869 | ' | |
870 | ||
67a20a00 TB |
871 | test_expect_success '%(trailers) rejects unknown trailers arguments' ' |
872 | # error message cannot be checked under i18n | |
873 | cat >expect <<-EOF && | |
874 | fatal: unknown %(trailers) argument: unsupported | |
875 | EOF | |
876 | test_must_fail git for-each-ref --format="%(trailers:unsupported)" 2>actual && | |
877 | test_i18ncmp expect actual | |
878 | ' | |
879 | ||
7a5edbdb TB |
880 | test_expect_success '%(contents:trailers) rejects unknown trailers arguments' ' |
881 | # error message cannot be checked under i18n | |
882 | cat >expect <<-EOF && | |
883 | fatal: unknown %(trailers) argument: unsupported | |
884 | EOF | |
885 | test_must_fail git for-each-ref --format="%(contents:trailers:unsupported)" 2>actual && | |
886 | test_i18ncmp expect actual | |
887 | ' | |
888 | ||
624b44d3 | 889 | test_expect_success 'basic atom: head contents:trailers' ' |
b1d31c89 JK |
890 | git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual && |
891 | sanitize_pgp <actual >actual.clean && | |
892 | # git for-each-ref ends with a blank line | |
893 | cat >expect <<-EOF && | |
894 | $(cat trailers) | |
895 | ||
896 | EOF | |
897 | test_cmp expect actual.clean | |
898 | ' | |
899 | ||
e5fba5d5 JK |
900 | test_expect_success 'trailer parsing not fooled by --- line' ' |
901 | git commit --allow-empty -F - <<-\EOF && | |
902 | this is the subject | |
903 | ||
904 | This is the body. The message has a "---" line which would confuse a | |
905 | message+patch parser. But here we know we have only a commit message, | |
906 | so we get it right. | |
907 | ||
908 | trailer: wrong | |
909 | --- | |
910 | This is more body. | |
911 | ||
912 | trailer: right | |
913 | EOF | |
914 | ||
915 | { | |
916 | echo "trailer: right" && | |
917 | echo | |
918 | } >expect && | |
919 | git for-each-ref --format="%(trailers)" refs/heads/master >actual && | |
920 | test_cmp expect actual | |
921 | ' | |
922 | ||
01f95825 KN |
923 | test_expect_success 'Add symbolic ref for the following tests' ' |
924 | git symbolic-ref refs/heads/sym refs/heads/master | |
925 | ' | |
926 | ||
927 | cat >expected <<EOF | |
928 | refs/heads/master | |
929 | EOF | |
930 | ||
931 | test_expect_success 'Verify usage of %(symref) atom' ' | |
932 | git for-each-ref --format="%(symref)" refs/heads/sym >actual && | |
933 | test_cmp expected actual | |
934 | ' | |
935 | ||
936 | cat >expected <<EOF | |
937 | heads/master | |
938 | EOF | |
939 | ||
940 | test_expect_success 'Verify usage of %(symref:short) atom' ' | |
941 | git for-each-ref --format="%(symref:short)" refs/heads/sym >actual && | |
942 | test_cmp expected actual | |
943 | ' | |
944 | ||
a7984101 KN |
945 | cat >expected <<EOF |
946 | master | |
1a0ca5e3 | 947 | heads/master |
a7984101 KN |
948 | EOF |
949 | ||
17938f17 KN |
950 | test_expect_success 'Verify usage of %(symref:lstrip) atom' ' |
951 | git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual && | |
1a0ca5e3 | 952 | git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual && |
44a6b6ce JH |
953 | test_cmp expected actual && |
954 | ||
955 | git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual && | |
956 | git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual && | |
a7984101 KN |
957 | test_cmp expected actual |
958 | ' | |
959 | ||
1a34728e KN |
960 | cat >expected <<EOF |
961 | refs | |
962 | refs/heads | |
963 | EOF | |
964 | ||
965 | test_expect_success 'Verify usage of %(symref:rstrip) atom' ' | |
966 | git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual && | |
967 | git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual && | |
968 | test_cmp expected actual | |
969 | ' | |
970 | ||
1b586867 JS |
971 | test_expect_success ':remotename and :remoteref' ' |
972 | git init remote-tests && | |
973 | ( | |
974 | cd remote-tests && | |
975 | test_commit initial && | |
976 | git remote add from fifth.coffee:blub && | |
977 | git config branch.master.remote from && | |
978 | git config branch.master.merge refs/heads/stable && | |
979 | git remote add to southridge.audio:repo && | |
980 | git config remote.to.push "refs/heads/*:refs/heads/pushed/*" && | |
981 | git config branch.master.pushRemote to && | |
982 | for pair in "%(upstream)=refs/remotes/from/stable" \ | |
983 | "%(upstream:remotename)=from" \ | |
984 | "%(upstream:remoteref)=refs/heads/stable" \ | |
985 | "%(push)=refs/remotes/to/pushed/master" \ | |
986 | "%(push:remotename)=to" \ | |
987 | "%(push:remoteref)=refs/heads/pushed/master" | |
988 | do | |
989 | echo "${pair#*=}" >expect && | |
990 | git for-each-ref --format="${pair%=*}" \ | |
991 | refs/heads/master >actual && | |
992 | test_cmp expect actual | |
993 | done && | |
994 | git branch push-simple && | |
995 | git config branch.push-simple.pushRemote from && | |
996 | actual="$(git for-each-ref \ | |
997 | --format="%(push:remotename),%(push:remoteref)" \ | |
998 | refs/heads/push-simple)" && | |
999 | test from, = "$actual" | |
1000 | ) | |
1001 | ' | |
1002 | ||
e674eb25 | 1003 | test_expect_success 'for-each-ref --ignore-case ignores case' ' |
ee0f3e22 | 1004 | git for-each-ref --format="%(refname)" refs/heads/MASTER >actual && |
d3c6751b | 1005 | test_must_be_empty actual && |
ee0f3e22 JK |
1006 | |
1007 | echo refs/heads/master >expect && | |
1008 | git for-each-ref --format="%(refname)" --ignore-case \ | |
1009 | refs/heads/MASTER >actual && | |
1010 | test_cmp expect actual | |
1011 | ' | |
1012 | ||
76f9e569 JK |
1013 | test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' ' |
1014 | # name refs numerically to avoid case-insensitive filesystem conflicts | |
1015 | nr=0 && | |
1016 | for email in a A b B | |
1017 | do | |
1018 | for subject in a A b B | |
1019 | do | |
1020 | GIT_COMMITTER_EMAIL="$email@example.com" \ | |
1021 | git tag -m "tag $subject" icase-$(printf %02d $nr) && | |
1022 | nr=$((nr+1))|| | |
1023 | return 1 | |
1024 | done | |
1025 | done && | |
1026 | git for-each-ref --ignore-case \ | |
1027 | --format="%(taggeremail) %(subject) %(refname)" \ | |
1028 | --sort=refname \ | |
1029 | --sort=subject \ | |
1030 | --sort=taggeremail \ | |
1031 | refs/tags/icase-* >actual && | |
1032 | cat >expect <<-\EOF && | |
1033 | <a@example.com> tag a refs/tags/icase-00 | |
1034 | <a@example.com> tag A refs/tags/icase-01 | |
1035 | <A@example.com> tag a refs/tags/icase-04 | |
1036 | <A@example.com> tag A refs/tags/icase-05 | |
1037 | <a@example.com> tag b refs/tags/icase-02 | |
1038 | <a@example.com> tag B refs/tags/icase-03 | |
1039 | <A@example.com> tag b refs/tags/icase-06 | |
1040 | <A@example.com> tag B refs/tags/icase-07 | |
1041 | <b@example.com> tag a refs/tags/icase-08 | |
1042 | <b@example.com> tag A refs/tags/icase-09 | |
1043 | <B@example.com> tag a refs/tags/icase-12 | |
1044 | <B@example.com> tag A refs/tags/icase-13 | |
1045 | <b@example.com> tag b refs/tags/icase-10 | |
1046 | <b@example.com> tag B refs/tags/icase-11 | |
1047 | <B@example.com> tag b refs/tags/icase-14 | |
1048 | <B@example.com> tag B refs/tags/icase-15 | |
1049 | EOF | |
1050 | test_cmp expect actual | |
1051 | ' | |
1052 | ||
96b2d4fa | 1053 | test_done |