]>
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" && | |
8f19c9fd | 31 | git branch -M main && |
96b2d4fa | 32 | setdate_and_increment && |
bc147968 | 33 | git tag -a -m "Tagging at $datestamp" testtag && |
8f19c9fd | 34 | git update-ref refs/remotes/origin/main main && |
8cae19d9 | 35 | git remote add origin nowhere && |
8f19c9fd JS |
36 | git config branch.main.remote origin && |
37 | git config branch.main.merge refs/heads/main && | |
29bc8850 JK |
38 | git remote add myfork elsewhere && |
39 | git config remote.pushdefault myfork && | |
40 | git config push.default current | |
8cae19d9 JK |
41 | ' |
42 | ||
d2bf48d2 JK |
43 | test_atom() { |
44 | case "$1" in | |
8f19c9fd | 45 | head) ref=refs/heads/main ;; |
d2bf48d2 | 46 | tag) ref=refs/tags/testtag ;; |
01f95825 | 47 | sym) ref=refs/heads/sym ;; |
7140c22c | 48 | *) ref=$1 ;; |
d2bf48d2 JK |
49 | esac |
50 | printf '%s\n' "$3" >expected | |
e2b23972 | 51 | test_expect_${4:-success} $PREREQ "basic atom: $1 $2" " |
d2bf48d2 | 52 | git for-each-ref --format='%($2)' $ref >actual && |
e2b23972 MG |
53 | sanitize_pgp <actual >actual.clean && |
54 | test_cmp expected actual.clean | |
d2bf48d2 | 55 | " |
b6839fda CC |
56 | # Automatically test "contents:size" atom after testing "contents" |
57 | if test "$2" = "contents" | |
58 | then | |
597fa8cb ĐTCD |
59 | # for commit leg, $3 is changed there |
60 | expect=$(printf '%s' "$3" | wc -c) | |
3db796c1 | 61 | test_expect_${4:-success} $PREREQ "basic atom: $1 contents:size" ' |
597fa8cb ĐTCD |
62 | type=$(git cat-file -t "$ref") && |
63 | case $type in | |
64 | tag) | |
65 | # We cannot use $3 as it expects sanitize_pgp to run | |
15495773 ĐTCD |
66 | git cat-file tag $ref >out && |
67 | expect=$(tail -n +6 out | wc -c) && | |
68 | rm -f out ;; | |
597fa8cb ĐTCD |
69 | tree | blob) |
70 | expect="" ;; | |
71 | commit) | |
72 | : "use the calculated expect" ;; | |
73 | *) | |
74 | BUG "unknown object type" ;; | |
75 | esac && | |
76 | # Leave $expect unquoted to lose possible leading whitespaces | |
77 | echo $expect >expected && | |
b6839fda | 78 | git for-each-ref --format="%(contents:size)" "$ref" >actual && |
3db796c1 | 79 | test_cmp expected actual |
b6839fda CC |
80 | ' |
81 | fi | |
d2bf48d2 JK |
82 | } |
83 | ||
1f5f8f3e | 84 | hexlen=$(test_oid hexsz) |
85 | disklen=$(test_oid disklen) | |
86 | ||
8f19c9fd JS |
87 | test_atom head refname refs/heads/main |
88 | test_atom head refname: refs/heads/main | |
89 | test_atom head refname:short main | |
90 | test_atom head refname:lstrip=1 heads/main | |
91 | test_atom head refname:lstrip=2 main | |
92 | test_atom head refname:lstrip=-1 main | |
93 | test_atom head refname:lstrip=-2 heads/main | |
1a34728e KN |
94 | test_atom head refname:rstrip=1 refs/heads |
95 | test_atom head refname:rstrip=2 refs | |
96 | test_atom head refname:rstrip=-1 refs | |
97 | test_atom head refname:rstrip=-2 refs/heads | |
8f19c9fd JS |
98 | test_atom head refname:strip=1 heads/main |
99 | test_atom head refname:strip=2 main | |
100 | test_atom head refname:strip=-1 main | |
101 | test_atom head refname:strip=-2 heads/main | |
102 | test_atom head upstream refs/remotes/origin/main | |
103 | test_atom head upstream:short origin/main | |
104 | test_atom head upstream:lstrip=2 origin/main | |
105 | test_atom head upstream:lstrip=-2 origin/main | |
1a34728e KN |
106 | test_atom head upstream:rstrip=2 refs/remotes |
107 | test_atom head upstream:rstrip=-2 refs/remotes | |
8f19c9fd JS |
108 | test_atom head upstream:strip=2 origin/main |
109 | test_atom head upstream:strip=-2 origin/main | |
110 | test_atom head push refs/remotes/myfork/main | |
111 | test_atom head push:short myfork/main | |
112 | test_atom head push:lstrip=1 remotes/myfork/main | |
113 | test_atom head push:lstrip=-1 main | |
1a34728e KN |
114 | test_atom head push:rstrip=1 refs/remotes/myfork |
115 | test_atom head push:rstrip=-1 refs | |
8f19c9fd JS |
116 | test_atom head push:strip=1 remotes/myfork/main |
117 | test_atom head push:strip=-1 main | |
d2bf48d2 | 118 | test_atom head objecttype commit |
1f5f8f3e | 119 | test_atom head objectsize $((131 + hexlen)) |
120 | test_atom head objectsize:disk $disklen | |
121 | test_atom head deltabase $ZERO_OID | |
8f19c9fd JS |
122 | test_atom head objectname $(git rev-parse refs/heads/main) |
123 | test_atom head objectname:short $(git rev-parse --short refs/heads/main) | |
124 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main) | |
125 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main) | |
126 | test_atom head tree $(git rev-parse refs/heads/main^{tree}) | |
127 | test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree}) | |
128 | test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree}) | |
129 | test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree}) | |
d2bf48d2 | 130 | test_atom head parent '' |
26bc0aaf HV |
131 | test_atom head parent:short '' |
132 | test_atom head parent:short=1 '' | |
133 | test_atom head parent:short=10 '' | |
d2bf48d2 JK |
134 | test_atom head numparent 0 |
135 | test_atom head object '' | |
136 | test_atom head type '' | |
bd0708c7 ZH |
137 | test_atom head raw "$(git cat-file commit refs/heads/main) |
138 | " | |
b74cf648 JK |
139 | test_atom head '*objectname' '' |
140 | test_atom head '*objecttype' '' | |
db7bae25 | 141 | test_atom head author 'A U Thor <author@example.com> 1151968724 +0200' |
d2bf48d2 JK |
142 | test_atom head authorname 'A U Thor' |
143 | test_atom head authoremail '<author@example.com>' | |
b82445dc HV |
144 | test_atom head authoremail:trim 'author@example.com' |
145 | test_atom head authoremail:localpart 'author' | |
db7bae25 JK |
146 | test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' |
147 | test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200' | |
d2bf48d2 JK |
148 | test_atom head committername 'C O Mitter' |
149 | test_atom head committeremail '<committer@example.com>' | |
b82445dc HV |
150 | test_atom head committeremail:trim 'committer@example.com' |
151 | test_atom head committeremail:localpart 'committer' | |
db7bae25 | 152 | test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' |
d2bf48d2 JK |
153 | test_atom head tag '' |
154 | test_atom head tagger '' | |
155 | test_atom head taggername '' | |
156 | test_atom head taggeremail '' | |
b82445dc HV |
157 | test_atom head taggeremail:trim '' |
158 | test_atom head taggeremail:localpart '' | |
d2bf48d2 | 159 | test_atom head taggerdate '' |
db7bae25 JK |
160 | test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200' |
161 | test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' | |
d2bf48d2 | 162 | test_atom head subject 'Initial' |
905f0a4e | 163 | test_atom head subject:sanitize 'Initial' |
e2b23972 | 164 | test_atom head contents:subject 'Initial' |
d2bf48d2 | 165 | test_atom head body '' |
e2b23972 MG |
166 | test_atom head contents:body '' |
167 | test_atom head contents:signature '' | |
d2bf48d2 JK |
168 | test_atom head contents 'Initial |
169 | ' | |
7a48b832 | 170 | test_atom head HEAD '*' |
d2bf48d2 JK |
171 | |
172 | test_atom tag refname refs/tags/testtag | |
1d094db9 | 173 | test_atom tag refname:short testtag |
8cae19d9 | 174 | test_atom tag upstream '' |
29bc8850 | 175 | test_atom tag push '' |
d2bf48d2 | 176 | test_atom tag objecttype tag |
1f5f8f3e | 177 | test_atom tag objectsize $((114 + hexlen)) |
178 | test_atom tag objectsize:disk $disklen | |
179 | test_atom tag '*objectsize:disk' $disklen | |
180 | test_atom tag deltabase $ZERO_OID | |
181 | test_atom tag '*deltabase' $ZERO_OID | |
189a5467 | 182 | test_atom tag objectname $(git rev-parse refs/tags/testtag) |
1d094db9 | 183 | test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) |
8f19c9fd JS |
184 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main) |
185 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main) | |
d2bf48d2 | 186 | test_atom tag tree '' |
837adb10 HV |
187 | test_atom tag tree:short '' |
188 | test_atom tag tree:short=1 '' | |
189 | test_atom tag tree:short=10 '' | |
d2bf48d2 | 190 | test_atom tag parent '' |
26bc0aaf HV |
191 | test_atom tag parent:short '' |
192 | test_atom tag parent:short=1 '' | |
193 | test_atom tag parent:short=10 '' | |
d2bf48d2 | 194 | test_atom tag numparent '' |
189a5467 | 195 | test_atom tag object $(git rev-parse refs/tags/testtag^0) |
d2bf48d2 | 196 | test_atom tag type 'commit' |
1f5f8f3e | 197 | test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{}) |
b74cf648 | 198 | test_atom tag '*objecttype' 'commit' |
d2bf48d2 JK |
199 | test_atom tag author '' |
200 | test_atom tag authorname '' | |
201 | test_atom tag authoremail '' | |
b82445dc HV |
202 | test_atom tag authoremail:trim '' |
203 | test_atom tag authoremail:localpart '' | |
d2bf48d2 JK |
204 | test_atom tag authordate '' |
205 | test_atom tag committer '' | |
206 | test_atom tag committername '' | |
207 | test_atom tag committeremail '' | |
b82445dc HV |
208 | test_atom tag committeremail:trim '' |
209 | test_atom tag committeremail:localpart '' | |
d2bf48d2 JK |
210 | test_atom tag committerdate '' |
211 | test_atom tag tag 'testtag' | |
db7bae25 | 212 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200' |
d2bf48d2 JK |
213 | test_atom tag taggername 'C O Mitter' |
214 | test_atom tag taggeremail '<committer@example.com>' | |
b82445dc HV |
215 | test_atom tag taggeremail:trim 'committer@example.com' |
216 | test_atom tag taggeremail:localpart 'committer' | |
db7bae25 JK |
217 | test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' |
218 | test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200' | |
219 | test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' | |
220 | test_atom tag subject 'Tagging at 1151968727' | |
905f0a4e | 221 | test_atom tag subject:sanitize 'Tagging-at-1151968727' |
db7bae25 | 222 | test_atom tag contents:subject 'Tagging at 1151968727' |
d2bf48d2 | 223 | test_atom tag body '' |
e2b23972 MG |
224 | test_atom tag contents:body '' |
225 | test_atom tag contents:signature '' | |
db7bae25 | 226 | test_atom tag contents 'Tagging at 1151968727 |
96b2d4fa | 227 | ' |
7a48b832 | 228 | test_atom tag HEAD ' ' |
96b2d4fa | 229 | |
bd0708c7 ZH |
230 | test_expect_success 'basic atom: refs/tags/testtag *raw' ' |
231 | git cat-file commit refs/tags/testtag^{} >expected && | |
232 | git for-each-ref --format="%(*raw)" refs/tags/testtag >actual && | |
233 | sanitize_pgp <expected >expected.clean && | |
234 | echo >>expected.clean && | |
235 | sanitize_pgp <actual >actual.clean && | |
236 | test_cmp expected.clean actual.clean | |
237 | ' | |
238 | ||
41ac414e | 239 | test_expect_success 'Check invalid atoms names are errors' ' |
3604e7c5 | 240 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
96b2d4fa AP |
241 | ' |
242 | ||
243 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' | |
3604e7c5 NS |
244 | git for-each-ref --format="%(authordate)" refs/heads && |
245 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && | |
246 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && | |
247 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads | |
96b2d4fa AP |
248 | ' |
249 | ||
250 | test_expect_success 'Check valid format specifiers for date fields' ' | |
3604e7c5 NS |
251 | git for-each-ref --format="%(authordate:default)" refs/heads && |
252 | git for-each-ref --format="%(authordate:relative)" refs/heads && | |
253 | git for-each-ref --format="%(authordate:short)" refs/heads && | |
254 | git for-each-ref --format="%(authordate:local)" refs/heads && | |
255 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && | |
256 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads | |
96b2d4fa AP |
257 | ' |
258 | ||
41ac414e | 259 | test_expect_success 'Check invalid format specifiers are errors' ' |
3604e7c5 | 260 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
96b2d4fa AP |
261 | ' |
262 | ||
42d0eb05 KN |
263 | test_expect_success 'arguments to %(objectname:short=) must be positive integers' ' |
264 | test_must_fail git for-each-ref --format="%(objectname:short=0)" && | |
265 | test_must_fail git for-each-ref --format="%(objectname:short=-1)" && | |
266 | test_must_fail git for-each-ref --format="%(objectname:short=foo)" | |
267 | ' | |
268 | ||
f95cecf4 JK |
269 | test_date () { |
270 | f=$1 && | |
271 | committer_date=$2 && | |
272 | author_date=$3 && | |
273 | tagger_date=$4 && | |
274 | cat >expected <<-EOF && | |
8f19c9fd | 275 | 'refs/heads/main' '$committer_date' '$author_date' |
f95cecf4 JK |
276 | 'refs/tags/testtag' '$tagger_date' |
277 | EOF | |
278 | ( | |
279 | git for-each-ref --shell \ | |
280 | --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \ | |
281 | refs/heads && | |
282 | git for-each-ref --shell \ | |
283 | --format="%(refname) %(taggerdate${f:+:$f})" \ | |
284 | refs/tags | |
285 | ) >actual && | |
286 | test_cmp expected actual | |
287 | } | |
96b2d4fa AP |
288 | |
289 | test_expect_success 'Check unformatted date fields output' ' | |
f95cecf4 | 290 | test_date "" \ |
db7bae25 JK |
291 | "Tue Jul 4 01:18:43 2006 +0200" \ |
292 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
293 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
294 | ' |
295 | ||
296 | test_expect_success 'Check format "default" formatted date fields output' ' | |
f95cecf4 | 297 | test_date default \ |
db7bae25 JK |
298 | "Tue Jul 4 01:18:43 2006 +0200" \ |
299 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
300 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
301 | ' |
302 | ||
99264e93 JK |
303 | test_expect_success 'Check format "default-local" date fields output' ' |
304 | 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 |
305 | ' |
306 | ||
307 | # Don't know how to do relative check because I can't know when this script | |
308 | # is going to be run and can't fake the current time to git, and hence can't | |
309 | # provide expected output. Instead, I'll just make sure that "relative" | |
310 | # doesn't exit in error | |
96b2d4fa AP |
311 | test_expect_success 'Check format "relative" date fields output' ' |
312 | f=relative && | |
313 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
314 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual | |
315 | ' | |
316 | ||
99264e93 JK |
317 | # We just check that this is the same as "relative" for now. |
318 | test_expect_success 'Check format "relative-local" date fields output' ' | |
319 | test_date relative-local \ | |
320 | "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \ | |
321 | "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \ | |
322 | "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)" | |
323 | ' | |
96b2d4fa AP |
324 | |
325 | test_expect_success 'Check format "short" date fields output' ' | |
db7bae25 | 326 | test_date short 2006-07-04 2006-07-04 2006-07-04 |
96b2d4fa AP |
327 | ' |
328 | ||
99264e93 JK |
329 | test_expect_success 'Check format "short-local" date fields output' ' |
330 | test_date short-local 2006-07-03 2006-07-03 2006-07-03 | |
331 | ' | |
96b2d4fa AP |
332 | |
333 | test_expect_success 'Check format "local" date fields output' ' | |
f95cecf4 | 334 | test_date local \ |
db7bae25 JK |
335 | "Mon Jul 3 23:18:43 2006" \ |
336 | "Mon Jul 3 23:18:44 2006" \ | |
337 | "Mon Jul 3 23:18:45 2006" | |
96b2d4fa AP |
338 | ' |
339 | ||
96b2d4fa | 340 | test_expect_success 'Check format "iso8601" date fields output' ' |
f95cecf4 | 341 | test_date iso8601 \ |
db7bae25 JK |
342 | "2006-07-04 01:18:43 +0200" \ |
343 | "2006-07-04 01:18:44 +0200" \ | |
344 | "2006-07-04 01:18:45 +0200" | |
96b2d4fa AP |
345 | ' |
346 | ||
99264e93 JK |
347 | test_expect_success 'Check format "iso8601-local" date fields output' ' |
348 | 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" | |
349 | ' | |
96b2d4fa AP |
350 | |
351 | test_expect_success 'Check format "rfc2822" date fields output' ' | |
f95cecf4 | 352 | test_date rfc2822 \ |
db7bae25 JK |
353 | "Tue, 4 Jul 2006 01:18:43 +0200" \ |
354 | "Tue, 4 Jul 2006 01:18:44 +0200" \ | |
355 | "Tue, 4 Jul 2006 01:18:45 +0200" | |
96b2d4fa AP |
356 | ' |
357 | ||
99264e93 JK |
358 | test_expect_success 'Check format "rfc2822-local" date fields output' ' |
359 | 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" | |
360 | ' | |
361 | ||
f3c1ba50 | 362 | test_expect_success 'Check format "raw" date fields output' ' |
db7bae25 | 363 | test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200" |
f3c1ba50 JK |
364 | ' |
365 | ||
99264e93 JK |
366 | test_expect_success 'Check format "raw-local" date fields output' ' |
367 | test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000" | |
96b2d4fa AP |
368 | ' |
369 | ||
aa1462cc | 370 | test_expect_success 'Check format of strftime date fields' ' |
db7bae25 | 371 | echo "my date is 2006-07-04" >expected && |
aa1462cc JK |
372 | git for-each-ref \ |
373 | --format="%(authordate:format:my date is %Y-%m-%d)" \ | |
374 | refs/heads >actual && | |
375 | test_cmp expected actual | |
376 | ' | |
377 | ||
99264e93 JK |
378 | test_expect_success 'Check format of strftime-local date fields' ' |
379 | echo "my date is 2006-07-03" >expected && | |
380 | git for-each-ref \ | |
381 | --format="%(authordate:format-local:my date is %Y-%m-%d)" \ | |
382 | refs/heads >actual && | |
383 | test_cmp expected actual | |
384 | ' | |
385 | ||
e4f031e3 JK |
386 | test_expect_success 'exercise strftime with odd fields' ' |
387 | echo >expected && | |
388 | git for-each-ref --format="%(authordate:format:)" refs/heads >actual && | |
389 | test_cmp expected actual && | |
8125a58b | 390 | long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" && |
e4f031e3 JK |
391 | echo $long >expected && |
392 | git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && | |
393 | test_cmp expected actual | |
394 | ' | |
395 | ||
c899a57c | 396 | cat >expected <<\EOF |
8f19c9fd JS |
397 | refs/heads/main |
398 | refs/remotes/origin/main | |
c899a57c LH |
399 | refs/tags/testtag |
400 | EOF | |
401 | ||
402 | test_expect_success 'Verify ascending sort' ' | |
3604e7c5 | 403 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
3af82863 | 404 | test_cmp expected actual |
c899a57c LH |
405 | ' |
406 | ||
407 | ||
408 | cat >expected <<\EOF | |
409 | refs/tags/testtag | |
8f19c9fd JS |
410 | refs/remotes/origin/main |
411 | refs/heads/main | |
c899a57c LH |
412 | EOF |
413 | ||
414 | test_expect_success 'Verify descending sort' ' | |
3604e7c5 | 415 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
3af82863 | 416 | test_cmp expected actual |
b31e2680 TB |
417 | ' |
418 | ||
98e7ab6d JH |
419 | test_expect_success 'Give help even with invalid sort atoms' ' |
420 | test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 && | |
421 | grep "^usage: git for-each-ref" actual | |
422 | ' | |
423 | ||
b31e2680 TB |
424 | cat >expected <<\EOF |
425 | refs/tags/testtag | |
426 | refs/tags/testtag-2 | |
427 | EOF | |
428 | ||
429 | test_expect_success 'exercise patterns with prefixes' ' | |
430 | git tag testtag-2 && | |
431 | test_when_finished "git tag -d testtag-2" && | |
432 | git for-each-ref --format="%(refname)" \ | |
433 | refs/tags/testtag refs/tags/testtag-2 >actual && | |
434 | test_cmp expected actual | |
435 | ' | |
436 | ||
437 | cat >expected <<\EOF | |
438 | refs/tags/testtag | |
439 | refs/tags/testtag-2 | |
440 | EOF | |
441 | ||
442 | test_expect_success 'exercise glob patterns with prefixes' ' | |
443 | git tag testtag-2 && | |
444 | test_when_finished "git tag -d testtag-2" && | |
445 | git for-each-ref --format="%(refname)" \ | |
446 | refs/tags/testtag "refs/tags/testtag-*" >actual && | |
447 | test_cmp expected actual | |
c899a57c LH |
448 | ' |
449 | ||
c9ecf4f1 | 450 | cat >expected <<\EOF |
8f19c9fd JS |
451 | 'refs/heads/main' |
452 | 'refs/remotes/origin/main' | |
c9ecf4f1 JS |
453 | 'refs/tags/testtag' |
454 | EOF | |
455 | ||
456 | test_expect_success 'Quoting style: shell' ' | |
457 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 458 | test_cmp expected actual |
c9ecf4f1 JS |
459 | ' |
460 | ||
461 | test_expect_success 'Quoting style: perl' ' | |
462 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 463 | test_cmp expected actual |
c9ecf4f1 JS |
464 | ' |
465 | ||
466 | test_expect_success 'Quoting style: python' ' | |
467 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 468 | test_cmp expected actual |
c9ecf4f1 JS |
469 | ' |
470 | ||
471 | cat >expected <<\EOF | |
8f19c9fd JS |
472 | "refs/heads/main" |
473 | "refs/remotes/origin/main" | |
c9ecf4f1 JS |
474 | "refs/tags/testtag" |
475 | EOF | |
476 | ||
477 | test_expect_success 'Quoting style: tcl' ' | |
478 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 479 | test_cmp expected actual |
c9ecf4f1 JS |
480 | ' |
481 | ||
482 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do | |
483 | test_expect_success "more than one quoting style: $i" " | |
2708ef4a SG |
484 | test_must_fail git for-each-ref $i 2>err && |
485 | grep '^error: more than one quoting style' err | |
c9ecf4f1 JS |
486 | " |
487 | done | |
c899a57c | 488 | |
b28061ce RR |
489 | test_expect_success 'setup for upstream:track[short]' ' |
490 | test_commit two | |
491 | ' | |
492 | ||
1d094db9 JK |
493 | test_atom head upstream:track '[ahead 1]' |
494 | test_atom head upstream:trackshort '>' | |
7743fcca KN |
495 | test_atom head upstream:track,nobracket 'ahead 1' |
496 | test_atom head upstream:nobracket,track 'ahead 1' | |
c646d093 DR |
497 | |
498 | test_expect_success 'setup for push:track[short]' ' | |
499 | test_commit third && | |
8f19c9fd JS |
500 | git update-ref refs/remotes/myfork/main main && |
501 | git reset main~1 | |
c646d093 DR |
502 | ' |
503 | ||
504 | test_atom head push:track '[behind 1]' | |
505 | test_atom head push:trackshort '<' | |
b28061ce RR |
506 | |
507 | test_expect_success 'Check that :track[short] cannot be used with other atoms' ' | |
508 | test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && | |
509 | test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null | |
510 | ' | |
511 | ||
b6160d95 RKC |
512 | test_expect_success 'Check that :track[short] works when upstream is invalid' ' |
513 | cat >expected <<-\EOF && | |
ffd921d3 | 514 | [gone] |
b6160d95 RKC |
515 | |
516 | EOF | |
8f19c9fd JS |
517 | test_when_finished "git config branch.main.merge refs/heads/main" && |
518 | git config branch.main.merge refs/heads/does-not-exist && | |
b6160d95 RKC |
519 | git for-each-ref \ |
520 | --format="%(upstream:track)$LF%(upstream:trackshort)" \ | |
521 | refs/heads >actual && | |
522 | test_cmp expected actual | |
29bc8850 JK |
523 | ' |
524 | ||
7d66f21a BW |
525 | test_expect_success 'Check for invalid refname format' ' |
526 | test_must_fail git for-each-ref --format="%(refname:INVALID)" | |
527 | ' | |
528 | ||
11b087ad JK |
529 | test_expect_success 'set up color tests' ' |
530 | cat >expected.color <<-EOF && | |
8f19c9fd JS |
531 | $(git rev-parse --short refs/heads/main) <GREEN>main<RESET> |
532 | $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET> | |
533 | $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET> | |
11b087ad | 534 | $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> |
c646d093 | 535 | $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> |
11b087ad JK |
536 | $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> |
537 | EOF | |
538 | sed "s/<[^>]*>//g" <expected.color >expected.bare && | |
539 | color_format="%(objectname:short) %(color:green)%(refname:short)" | |
540 | ' | |
fddb74c9 | 541 | |
11b087ad | 542 | test_expect_success TTY '%(color) shows color with a tty' ' |
e433749d | 543 | test_terminal git for-each-ref --format="$color_format" >actual.raw && |
097b681b | 544 | test_decode_color <actual.raw >actual && |
11b087ad JK |
545 | test_cmp expected.color actual |
546 | ' | |
547 | ||
548 | test_expect_success '%(color) does not show color without tty' ' | |
549 | TERM=vt100 git for-each-ref --format="$color_format" >actual && | |
550 | test_cmp expected.bare actual | |
551 | ' | |
552 | ||
0c88bf50 JK |
553 | test_expect_success '--color can override tty check' ' |
554 | git for-each-ref --color --format="$color_format" >actual.raw && | |
11b087ad JK |
555 | test_decode_color <actual.raw >actual && |
556 | test_cmp expected.color actual | |
fddb74c9 RR |
557 | ' |
558 | ||
b521fd12 JK |
559 | test_expect_success 'color.ui=always does not override tty check' ' |
560 | git -c color.ui=always for-each-ref --format="$color_format" >actual && | |
561 | test_cmp expected.bare actual | |
562 | ' | |
563 | ||
7d66f21a | 564 | cat >expected <<\EOF |
8f19c9fd JS |
565 | heads/main |
566 | tags/main | |
7d66f21a BW |
567 | EOF |
568 | ||
2bb98169 BW |
569 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
570 | git config --bool core.warnambiguousrefs true && | |
7d66f21a BW |
571 | git checkout -b newtag && |
572 | echo "Using $datestamp" > one && | |
573 | git add one && | |
574 | git commit -m "Branch" && | |
575 | setdate_and_increment && | |
8f19c9fd JS |
576 | git tag -m "Tagging at $datestamp" main && |
577 | git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual && | |
7d66f21a BW |
578 | test_cmp expected actual |
579 | ' | |
580 | ||
2bb98169 | 581 | cat >expected <<\EOF |
8f19c9fd JS |
582 | heads/main |
583 | main | |
2bb98169 BW |
584 | EOF |
585 | ||
586 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' | |
587 | git config --bool core.warnambiguousrefs false && | |
8f19c9fd | 588 | git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual && |
2bb98169 BW |
589 | test_cmp expected actual |
590 | ' | |
591 | ||
7d66f21a BW |
592 | cat >expected <<\EOF |
593 | heads/ambiguous | |
594 | ambiguous | |
595 | EOF | |
596 | ||
2bb98169 | 597 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
8f19c9fd | 598 | git checkout main && |
7d66f21a BW |
599 | git tag ambiguous testtag^0 && |
600 | git branch ambiguous testtag^0 && | |
601 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && | |
602 | test_cmp expected actual | |
603 | ' | |
604 | ||
8b3f33ef MP |
605 | test_expect_success 'create tag without tagger' ' |
606 | git tag -a -m "Broken tag" taggerless && | |
607 | git tag -f taggerless $(git cat-file tag taggerless | | |
608 | sed -e "/^tagger /d" | | |
34959d80 | 609 | git hash-object --literally --stdin -w -t tag) |
8b3f33ef MP |
610 | ' |
611 | ||
612 | test_atom refs/tags/taggerless type 'commit' | |
613 | test_atom refs/tags/taggerless tag 'taggerless' | |
614 | test_atom refs/tags/taggerless tagger '' | |
615 | test_atom refs/tags/taggerless taggername '' | |
616 | test_atom refs/tags/taggerless taggeremail '' | |
b82445dc HV |
617 | test_atom refs/tags/taggerless taggeremail:trim '' |
618 | test_atom refs/tags/taggerless taggeremail:localpart '' | |
8b3f33ef MP |
619 | test_atom refs/tags/taggerless taggerdate '' |
620 | test_atom refs/tags/taggerless committer '' | |
621 | test_atom refs/tags/taggerless committername '' | |
622 | test_atom refs/tags/taggerless committeremail '' | |
b82445dc HV |
623 | test_atom refs/tags/taggerless committeremail:trim '' |
624 | test_atom refs/tags/taggerless committeremail:localpart '' | |
8b3f33ef MP |
625 | test_atom refs/tags/taggerless committerdate '' |
626 | test_atom refs/tags/taggerless subject 'Broken tag' | |
627 | ||
e276c26b JH |
628 | test_expect_success 'an unusual tag with an incomplete line' ' |
629 | ||
630 | git tag -m "bogo" bogo && | |
631 | bogo=$(git cat-file tag bogo) && | |
632 | bogo=$(printf "%s" "$bogo" | git mktag) && | |
633 | git tag -f bogo "$bogo" && | |
634 | git for-each-ref --format "%(body)" refs/tags/bogo | |
635 | ||
636 | ' | |
637 | ||
7140c22c JK |
638 | test_expect_success 'create tag with subject and body content' ' |
639 | cat >>msg <<-\EOF && | |
640 | the subject line | |
641 | ||
642 | first body line | |
643 | second body line | |
644 | EOF | |
645 | git tag -F msg subject-body | |
646 | ' | |
647 | test_atom refs/tags/subject-body subject 'the subject line' | |
905f0a4e | 648 | test_atom refs/tags/subject-body subject:sanitize 'the-subject-line' |
7140c22c JK |
649 | test_atom refs/tags/subject-body body 'first body line |
650 | second body line | |
651 | ' | |
652 | test_atom refs/tags/subject-body contents 'the subject line | |
653 | ||
654 | first body line | |
655 | second body line | |
656 | ' | |
657 | ||
7f6e275b JK |
658 | test_expect_success 'create tag with multiline subject' ' |
659 | cat >msg <<-\EOF && | |
660 | first subject line | |
661 | second subject line | |
662 | ||
663 | first body line | |
664 | second body line | |
665 | EOF | |
666 | git tag -F msg multiline | |
667 | ' | |
668 | test_atom refs/tags/multiline subject 'first subject line second subject line' | |
905f0a4e | 669 | test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line' |
e2b23972 | 670 | test_atom refs/tags/multiline contents:subject 'first subject line second subject line' |
7f6e275b JK |
671 | test_atom refs/tags/multiline body 'first body line |
672 | second body line | |
673 | ' | |
e2b23972 MG |
674 | test_atom refs/tags/multiline contents:body 'first body line |
675 | second body line | |
676 | ' | |
677 | test_atom refs/tags/multiline contents:signature '' | |
7f6e275b JK |
678 | test_atom refs/tags/multiline contents 'first subject line |
679 | second subject line | |
680 | ||
681 | first body line | |
682 | second body line | |
683 | ' | |
684 | ||
e2b23972 MG |
685 | test_expect_success GPG 'create signed tags' ' |
686 | git tag -s -m "" signed-empty && | |
687 | git tag -s -m "subject line" signed-short && | |
688 | cat >msg <<-\EOF && | |
689 | subject line | |
690 | ||
691 | body contents | |
692 | EOF | |
693 | git tag -s -F msg signed-long | |
694 | ' | |
695 | ||
696 | sig='-----BEGIN PGP SIGNATURE----- | |
697 | -----END PGP SIGNATURE----- | |
698 | ' | |
699 | ||
700 | PREREQ=GPG | |
701 | test_atom refs/tags/signed-empty subject '' | |
905f0a4e | 702 | test_atom refs/tags/signed-empty subject:sanitize '' |
e2b23972 MG |
703 | test_atom refs/tags/signed-empty contents:subject '' |
704 | test_atom refs/tags/signed-empty body "$sig" | |
705 | test_atom refs/tags/signed-empty contents:body '' | |
706 | test_atom refs/tags/signed-empty contents:signature "$sig" | |
707 | test_atom refs/tags/signed-empty contents "$sig" | |
708 | ||
bd0708c7 ZH |
709 | test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' ' |
710 | git cat-file tag refs/tags/signed-empty >expected && | |
711 | git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual && | |
712 | sanitize_pgp <expected >expected.clean && | |
713 | echo >>expected.clean && | |
714 | sanitize_pgp <actual >actual.clean && | |
715 | test_cmp expected.clean actual.clean | |
716 | ' | |
717 | ||
e2b23972 | 718 | test_atom refs/tags/signed-short subject 'subject line' |
905f0a4e | 719 | test_atom refs/tags/signed-short subject:sanitize 'subject-line' |
e2b23972 MG |
720 | test_atom refs/tags/signed-short contents:subject 'subject line' |
721 | test_atom refs/tags/signed-short body "$sig" | |
722 | test_atom refs/tags/signed-short contents:body '' | |
723 | test_atom refs/tags/signed-short contents:signature "$sig" | |
724 | test_atom refs/tags/signed-short contents "subject line | |
725 | $sig" | |
726 | ||
bd0708c7 ZH |
727 | test_expect_success GPG 'basic atom: refs/tags/signed-short raw' ' |
728 | git cat-file tag refs/tags/signed-short >expected && | |
729 | git for-each-ref --format="%(raw)" refs/tags/signed-short >actual && | |
730 | sanitize_pgp <expected >expected.clean && | |
731 | echo >>expected.clean && | |
732 | sanitize_pgp <actual >actual.clean && | |
733 | test_cmp expected.clean actual.clean | |
734 | ' | |
735 | ||
e2b23972 | 736 | test_atom refs/tags/signed-long subject 'subject line' |
905f0a4e | 737 | test_atom refs/tags/signed-long subject:sanitize 'subject-line' |
e2b23972 MG |
738 | test_atom refs/tags/signed-long contents:subject 'subject line' |
739 | test_atom refs/tags/signed-long body "body contents | |
740 | $sig" | |
741 | test_atom refs/tags/signed-long contents:body 'body contents | |
742 | ' | |
743 | test_atom refs/tags/signed-long contents:signature "$sig" | |
744 | test_atom refs/tags/signed-long contents "subject line | |
745 | ||
746 | body contents | |
747 | $sig" | |
748 | ||
bd0708c7 ZH |
749 | test_expect_success GPG 'basic atom: refs/tags/signed-long raw' ' |
750 | git cat-file tag refs/tags/signed-long >expected && | |
751 | git for-each-ref --format="%(raw)" refs/tags/signed-long >actual && | |
752 | sanitize_pgp <expected >expected.clean && | |
753 | echo >>expected.clean && | |
754 | sanitize_pgp <actual >actual.clean && | |
755 | test_cmp expected.clean actual.clean | |
756 | ' | |
757 | ||
6e2ef8eb | 758 | test_expect_success 'set up refs pointing to tree and blob' ' |
8f19c9fd JS |
759 | git update-ref refs/mytrees/first refs/heads/main^{tree} && |
760 | git update-ref refs/myblobs/first refs/heads/main:one | |
6e2ef8eb CC |
761 | ' |
762 | ||
763 | test_atom refs/mytrees/first subject "" | |
764 | test_atom refs/mytrees/first contents:subject "" | |
765 | test_atom refs/mytrees/first body "" | |
766 | test_atom refs/mytrees/first contents:body "" | |
767 | test_atom refs/mytrees/first contents:signature "" | |
768 | test_atom refs/mytrees/first contents "" | |
769 | ||
bd0708c7 ZH |
770 | test_expect_success 'basic atom: refs/mytrees/first raw' ' |
771 | git cat-file tree refs/mytrees/first >expected && | |
772 | echo >>expected && | |
773 | git for-each-ref --format="%(raw)" refs/mytrees/first >actual && | |
774 | test_cmp expected actual && | |
775 | git cat-file -s refs/mytrees/first >expected && | |
776 | git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual && | |
777 | test_cmp expected actual | |
778 | ' | |
779 | ||
6e2ef8eb CC |
780 | test_atom refs/myblobs/first subject "" |
781 | test_atom refs/myblobs/first contents:subject "" | |
782 | test_atom refs/myblobs/first body "" | |
783 | test_atom refs/myblobs/first contents:body "" | |
784 | test_atom refs/myblobs/first contents:signature "" | |
785 | test_atom refs/myblobs/first contents "" | |
786 | ||
bd0708c7 ZH |
787 | test_expect_success 'basic atom: refs/myblobs/first raw' ' |
788 | git cat-file blob refs/myblobs/first >expected && | |
789 | echo >>expected && | |
790 | git for-each-ref --format="%(raw)" refs/myblobs/first >actual && | |
791 | test_cmp expected actual && | |
792 | git cat-file -s refs/myblobs/first >expected && | |
793 | git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual && | |
794 | test_cmp expected actual | |
795 | ' | |
796 | ||
797 | test_expect_success 'set up refs pointing to binary blob' ' | |
798 | printf "a\0b\0c" >blob1 && | |
799 | printf "a\0c\0b" >blob2 && | |
800 | printf "\0a\0b\0c" >blob3 && | |
801 | printf "abc" >blob4 && | |
802 | printf "\0 \0 \0 " >blob5 && | |
803 | printf "\0 \0a\0 " >blob6 && | |
804 | printf " " >blob7 && | |
805 | >blob8 && | |
806 | obj=$(git hash-object -w blob1) && | |
807 | git update-ref refs/myblobs/blob1 "$obj" && | |
808 | obj=$(git hash-object -w blob2) && | |
809 | git update-ref refs/myblobs/blob2 "$obj" && | |
810 | obj=$(git hash-object -w blob3) && | |
811 | git update-ref refs/myblobs/blob3 "$obj" && | |
812 | obj=$(git hash-object -w blob4) && | |
813 | git update-ref refs/myblobs/blob4 "$obj" && | |
814 | obj=$(git hash-object -w blob5) && | |
815 | git update-ref refs/myblobs/blob5 "$obj" && | |
816 | obj=$(git hash-object -w blob6) && | |
817 | git update-ref refs/myblobs/blob6 "$obj" && | |
818 | obj=$(git hash-object -w blob7) && | |
819 | git update-ref refs/myblobs/blob7 "$obj" && | |
820 | obj=$(git hash-object -w blob8) && | |
821 | git update-ref refs/myblobs/blob8 "$obj" | |
822 | ' | |
823 | ||
824 | test_expect_success 'Verify sorts with raw' ' | |
825 | cat >expected <<-EOF && | |
826 | refs/myblobs/blob8 | |
827 | refs/myblobs/blob5 | |
828 | refs/myblobs/blob6 | |
829 | refs/myblobs/blob3 | |
830 | refs/myblobs/blob7 | |
831 | refs/mytrees/first | |
832 | refs/myblobs/first | |
833 | refs/myblobs/blob1 | |
834 | refs/myblobs/blob2 | |
835 | refs/myblobs/blob4 | |
836 | refs/heads/main | |
837 | EOF | |
838 | git for-each-ref --format="%(refname)" --sort=raw \ | |
839 | refs/heads/main refs/myblobs/ refs/mytrees/first >actual && | |
840 | test_cmp expected actual | |
841 | ' | |
842 | ||
843 | test_expect_success 'Verify sorts with raw:size' ' | |
844 | cat >expected <<-EOF && | |
845 | refs/myblobs/blob8 | |
846 | refs/myblobs/first | |
847 | refs/myblobs/blob7 | |
848 | refs/heads/main | |
849 | refs/myblobs/blob4 | |
850 | refs/myblobs/blob1 | |
851 | refs/myblobs/blob2 | |
852 | refs/myblobs/blob3 | |
853 | refs/myblobs/blob5 | |
854 | refs/myblobs/blob6 | |
855 | refs/mytrees/first | |
856 | EOF | |
857 | git for-each-ref --format="%(refname)" --sort=raw:size \ | |
858 | refs/heads/main refs/myblobs/ refs/mytrees/first >actual && | |
859 | test_cmp expected actual | |
860 | ' | |
861 | ||
862 | test_expect_success 'validate raw atom with %(if:equals)' ' | |
863 | cat >expected <<-EOF && | |
864 | not equals | |
865 | not equals | |
866 | not equals | |
867 | not equals | |
868 | not equals | |
869 | not equals | |
870 | refs/myblobs/blob4 | |
871 | not equals | |
872 | not equals | |
873 | not equals | |
874 | not equals | |
875 | not equals | |
876 | EOF | |
877 | git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \ | |
878 | refs/myblobs/ refs/heads/ >actual && | |
879 | test_cmp expected actual | |
880 | ' | |
881 | ||
882 | test_expect_success 'validate raw atom with %(if:notequals)' ' | |
883 | cat >expected <<-EOF && | |
884 | refs/heads/ambiguous | |
885 | refs/heads/main | |
886 | refs/heads/newtag | |
887 | refs/myblobs/blob1 | |
888 | refs/myblobs/blob2 | |
889 | refs/myblobs/blob3 | |
890 | equals | |
891 | refs/myblobs/blob5 | |
892 | refs/myblobs/blob6 | |
893 | refs/myblobs/blob7 | |
894 | refs/myblobs/blob8 | |
895 | refs/myblobs/first | |
896 | EOF | |
897 | git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \ | |
898 | refs/myblobs/ refs/heads/ >actual && | |
899 | test_cmp expected actual | |
900 | ' | |
901 | ||
902 | test_expect_success 'empty raw refs with %(if)' ' | |
903 | cat >expected <<-EOF && | |
904 | refs/myblobs/blob1 not empty | |
905 | refs/myblobs/blob2 not empty | |
906 | refs/myblobs/blob3 not empty | |
907 | refs/myblobs/blob4 not empty | |
908 | refs/myblobs/blob5 not empty | |
909 | refs/myblobs/blob6 not empty | |
910 | refs/myblobs/blob7 empty | |
911 | refs/myblobs/blob8 empty | |
912 | refs/myblobs/first not empty | |
913 | EOF | |
914 | git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \ | |
915 | refs/myblobs/ >actual && | |
916 | test_cmp expected actual | |
917 | ' | |
918 | ||
919 | test_expect_success '%(raw) with --python must fail' ' | |
920 | test_must_fail git for-each-ref --format="%(raw)" --python | |
921 | ' | |
922 | ||
923 | test_expect_success '%(raw) with --tcl must fail' ' | |
924 | test_must_fail git for-each-ref --format="%(raw)" --tcl | |
925 | ' | |
926 | ||
7121c4d4 ZH |
927 | test_expect_success '%(raw) with --perl' ' |
928 | git for-each-ref --format="\$name= %(raw); | |
929 | print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual && | |
930 | cmp blob1 actual && | |
931 | git for-each-ref --format="\$name= %(raw); | |
932 | print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual && | |
933 | cmp blob3 actual && | |
934 | git for-each-ref --format="\$name= %(raw); | |
935 | print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual && | |
936 | cmp blob8 actual && | |
937 | git for-each-ref --format="\$name= %(raw); | |
938 | print \"\$name\"" refs/myblobs/first --perl | perl >actual && | |
939 | cmp one actual && | |
940 | git cat-file tree refs/mytrees/first > expected && | |
941 | git for-each-ref --format="\$name= %(raw); | |
942 | print \"\$name\"" refs/mytrees/first --perl | perl >actual && | |
943 | cmp expected actual | |
bd0708c7 ZH |
944 | ' |
945 | ||
946 | test_expect_success '%(raw) with --shell must fail' ' | |
947 | test_must_fail git for-each-ref --format="%(raw)" --shell | |
948 | ' | |
949 | ||
950 | test_expect_success '%(raw) with --shell and --sort=raw must fail' ' | |
951 | test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell | |
952 | ' | |
953 | ||
954 | test_expect_success '%(raw:size) with --shell' ' | |
efe47c83 | 955 | git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect && |
bd0708c7 ZH |
956 | git for-each-ref --format="%(raw:size)" --shell >actual && |
957 | test_cmp expect actual | |
958 | ' | |
959 | ||
960 | test_expect_success 'for-each-ref --format compare with cat-file --batch' ' | |
961 | git rev-parse refs/mytrees/first | git cat-file --batch >expected && | |
962 | git for-each-ref --format="%(objectname) %(objecttype) %(objectsize) | |
963 | %(raw)" refs/mytrees/first >actual && | |
964 | test_cmp expected actual | |
965 | ' | |
966 | ||
7c5045fc JK |
967 | test_expect_success 'set up multiple-sort tags' ' |
968 | for when in 100000 200000 | |
969 | do | |
970 | for email in user1 user2 | |
971 | do | |
972 | for ref in ref1 ref2 | |
973 | do | |
974 | GIT_COMMITTER_DATE="@$when +0000" \ | |
975 | GIT_COMMITTER_EMAIL="$email@example.com" \ | |
976 | git tag -m "tag $ref-$when-$email" \ | |
977 | multi-$ref-$when-$email || return 1 | |
978 | done | |
979 | done | |
980 | done | |
981 | ' | |
912072d5 | 982 | |
3b51222c | 983 | test_expect_success 'Verify sort with multiple keys' ' |
7c5045fc JK |
984 | cat >expected <<-\EOF && |
985 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
986 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
987 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
988 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
989 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
990 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
991 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
992 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
993 | EOF | |
994 | git for-each-ref \ | |
995 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
996 | --sort=-refname \ | |
997 | --sort=taggeremail \ | |
998 | --sort=taggerdate \ | |
999 | "refs/tags/multi-*" >actual && | |
912072d5 KK |
1000 | test_cmp expected actual |
1001 | ' | |
84679d47 | 1002 | |
7c5045fc JK |
1003 | test_expect_success 'equivalent sorts fall back on refname' ' |
1004 | cat >expected <<-\EOF && | |
1005 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
1006 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
1007 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
1008 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
1009 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
1010 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
1011 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
1012 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
1013 | EOF | |
1014 | git for-each-ref \ | |
1015 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
1016 | --sort=taggerdate \ | |
1017 | "refs/tags/multi-*" >actual && | |
1018 | test_cmp expected actual | |
1019 | ' | |
01f95825 | 1020 | |
98e7ab6d JH |
1021 | test_expect_success '--no-sort cancels the previous sort keys' ' |
1022 | cat >expected <<-\EOF && | |
1023 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
1024 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
1025 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
1026 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
1027 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
1028 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
1029 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
1030 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
1031 | EOF | |
1032 | git for-each-ref \ | |
1033 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
1034 | --sort=-refname \ | |
1035 | --sort=taggeremail \ | |
1036 | --no-sort \ | |
1037 | --sort=taggerdate \ | |
1038 | "refs/tags/multi-*" >actual && | |
1039 | test_cmp expected actual | |
1040 | ' | |
1041 | ||
84679d47 | 1042 | test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' |
8f19c9fd | 1043 | test_when_finished "git checkout main" && |
84679d47 JH |
1044 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
1045 | sed -e "s/^\* / /" actual >expect && | |
f0252ca2 | 1046 | git checkout --orphan orphaned-branch && |
84679d47 JH |
1047 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
1048 | test_cmp expect actual | |
1049 | ' | |
1050 | ||
b1d31c89 JK |
1051 | cat >trailers <<EOF |
1052 | Reviewed-by: A U Thor <author@example.com> | |
1053 | Signed-off-by: A U Thor <author@example.com> | |
624b44d3 TB |
1054 | [ v2 updated patch description ] |
1055 | Acked-by: A U Thor | |
1056 | <author@example.com> | |
b1d31c89 JK |
1057 | EOF |
1058 | ||
67a20a00 TB |
1059 | unfold () { |
1060 | perl -0pe 's/\n\s+/ /g' | |
1061 | } | |
624b44d3 TB |
1062 | |
1063 | test_expect_success 'set up trailers for next test' ' | |
b1d31c89 JK |
1064 | echo "Some contents" > two && |
1065 | git add two && | |
624b44d3 | 1066 | git commit -F - <<-EOF |
b1d31c89 JK |
1067 | trailers: this commit message has trailers |
1068 | ||
1069 | Some message contents | |
1070 | ||
1071 | $(cat trailers) | |
1072 | EOF | |
624b44d3 TB |
1073 | ' |
1074 | ||
727331dc HV |
1075 | test_trailer_option () { |
1076 | title=$1 option=$2 | |
1077 | cat >expect | |
1078 | test_expect_success "$title" ' | |
1079 | git for-each-ref --format="%($option)" refs/heads/main >actual && | |
1080 | test_cmp expect actual && | |
1081 | git for-each-ref --format="%(contents:$option)" refs/heads/main >actual && | |
1082 | test_cmp expect actual | |
1083 | ' | |
1084 | } | |
67a20a00 | 1085 | |
727331dc HV |
1086 | test_trailer_option '%(trailers:unfold) unfolds trailers' \ |
1087 | 'trailers:unfold' <<-EOF | |
1088 | $(unfold <trailers) | |
67a20a00 | 1089 | |
727331dc | 1090 | EOF |
7a5edbdb | 1091 | |
727331dc HV |
1092 | test_trailer_option '%(trailers:only) shows only "key: value" trailers' \ |
1093 | 'trailers:only' <<-EOF | |
1094 | $(grep -v patch.description <trailers) | |
1095 | ||
1096 | EOF | |
1097 | ||
ee82a487 HV |
1098 | test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \ |
1099 | 'trailers:only=no,only=true' <<-EOF | |
1100 | $(grep -v patch.description <trailers) | |
1101 | ||
1102 | EOF | |
1103 | ||
1104 | test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \ | |
1105 | 'trailers:only=yes' <<-EOF | |
1106 | $(grep -v patch.description <trailers) | |
1107 | ||
1108 | EOF | |
1109 | ||
1110 | test_trailer_option '%(trailers:only=no) shows all trailers' \ | |
1111 | 'trailers:only=no' <<-EOF | |
1112 | $(cat trailers) | |
1113 | ||
1114 | EOF | |
1115 | ||
727331dc HV |
1116 | test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \ |
1117 | 'trailers:only,unfold' <<-EOF | |
1118 | $(grep -v patch.description <trailers | unfold) | |
1119 | ||
1120 | EOF | |
1121 | ||
1122 | test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \ | |
1123 | 'trailers:unfold,only' <<-EOF | |
1124 | $(grep -v patch.description <trailers | unfold) | |
1125 | ||
1126 | EOF | |
1127 | ||
ee82a487 HV |
1128 | test_trailer_option '%(trailers:key=foo) shows that trailer' \ |
1129 | 'trailers:key=Signed-off-by' <<-EOF | |
1130 | Signed-off-by: A U Thor <author@example.com> | |
1131 | ||
1132 | EOF | |
1133 | ||
1134 | test_trailer_option '%(trailers:key=foo) is case insensitive' \ | |
1135 | 'trailers:key=SiGned-oFf-bY' <<-EOF | |
1136 | Signed-off-by: A U Thor <author@example.com> | |
1137 | ||
1138 | EOF | |
1139 | ||
1140 | test_trailer_option '%(trailers:key=foo:) trailing colon also works' \ | |
1141 | 'trailers:key=Signed-off-by:' <<-EOF | |
1142 | Signed-off-by: A U Thor <author@example.com> | |
1143 | ||
1144 | EOF | |
1145 | ||
1146 | test_trailer_option '%(trailers:key=foo) multiple keys' \ | |
1147 | 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF | |
1148 | Reviewed-by: A U Thor <author@example.com> | |
1149 | Signed-off-by: A U Thor <author@example.com> | |
1150 | ||
1151 | EOF | |
1152 | ||
1153 | test_trailer_option '%(trailers:key=nonexistent) becomes empty' \ | |
1154 | 'trailers:key=Shined-off-by:' <<-EOF | |
1155 | ||
1156 | EOF | |
1157 | ||
1158 | test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \ | |
1159 | 'trailers:key=Acked-by' <<-EOF | |
1160 | $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by) | |
1161 | ||
1162 | EOF | |
1163 | ||
1164 | test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \ | |
1165 | 'trailers:key=Signed-Off-by,unfold' <<-EOF | |
1166 | $(unfold <trailers | grep Signed-off-by) | |
1167 | ||
1168 | EOF | |
1169 | ||
1170 | test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \ | |
1171 | 'trailers:key=Signed-off-by,only=no' <<-EOF | |
1172 | Signed-off-by: A U Thor <author@example.com> | |
1173 | $(grep patch.description <trailers) | |
1174 | ||
1175 | EOF | |
1176 | ||
1177 | test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \ | |
1178 | 'trailers:key=Signed-off-by,valueonly' <<-EOF | |
1179 | A U Thor <author@example.com> | |
1180 | ||
1181 | EOF | |
1182 | ||
1183 | test_trailer_option '%(trailers:separator) changes separator' \ | |
1184 | 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF | |
1185 | Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com> | |
1186 | EOF | |
1187 | ||
1188 | test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \ | |
1189 | 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF | |
1190 | Reviewed-by,A U Thor <author@example.com> | |
1191 | Signed-off-by,A U Thor <author@example.com> | |
1192 | ||
1193 | EOF | |
1194 | ||
1195 | test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \ | |
1196 | 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF | |
1197 | Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com> | |
1198 | EOF | |
1199 | ||
727331dc HV |
1200 | test_failing_trailer_option () { |
1201 | title=$1 option=$2 | |
1202 | cat >expect | |
1203 | test_expect_success "$title" ' | |
1204 | # error message cannot be checked under i18n | |
1205 | test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual && | |
feeb03bc | 1206 | test_cmp expect actual && |
727331dc | 1207 | test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual && |
feeb03bc | 1208 | test_cmp expect actual |
727331dc HV |
1209 | ' |
1210 | } | |
1211 | ||
1212 | test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \ | |
1213 | 'trailers:unsupported' <<-\EOF | |
67a20a00 TB |
1214 | fatal: unknown %(trailers) argument: unsupported |
1215 | EOF | |
67a20a00 | 1216 | |
ee82a487 HV |
1217 | test_failing_trailer_option '%(trailers:key) without value is error' \ |
1218 | 'trailers:key' <<-\EOF | |
1219 | fatal: expected %(trailers:key=<value>) | |
1220 | EOF | |
1221 | ||
2c22e102 | 1222 | test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' ' |
7a5edbdb | 1223 | cat >expect <<-EOF && |
2c22e102 | 1224 | fatal: unrecognized %(contents) argument: trailersonly |
7a5edbdb | 1225 | EOF |
2c22e102 | 1226 | test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual && |
feeb03bc | 1227 | test_cmp expect actual |
7a5edbdb TB |
1228 | ' |
1229 | ||
624b44d3 | 1230 | test_expect_success 'basic atom: head contents:trailers' ' |
8f19c9fd | 1231 | git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual && |
b1d31c89 JK |
1232 | sanitize_pgp <actual >actual.clean && |
1233 | # git for-each-ref ends with a blank line | |
1234 | cat >expect <<-EOF && | |
1235 | $(cat trailers) | |
1236 | ||
1237 | EOF | |
1238 | test_cmp expect actual.clean | |
1239 | ' | |
1240 | ||
b9dee075 ZH |
1241 | test_expect_success 'basic atom: rest must fail' ' |
1242 | test_must_fail git for-each-ref --format="%(rest)" refs/heads/main | |
1243 | ' | |
1244 | ||
a33d0fae JK |
1245 | test_expect_success 'HEAD atom does not take arguments' ' |
1246 | test_must_fail git for-each-ref --format="%(HEAD:foo)" 2>err && | |
1247 | echo "fatal: %(HEAD) does not take arguments" >expect && | |
1248 | test_cmp expect err | |
1249 | ' | |
1250 | ||
dda4fc1a JK |
1251 | test_expect_success 'subject atom rejects unknown arguments' ' |
1252 | test_must_fail git for-each-ref --format="%(subject:foo)" 2>err && | |
1253 | echo "fatal: unrecognized %(subject) argument: foo" >expect && | |
1254 | test_cmp expect err | |
1255 | ' | |
1256 | ||
1955ef10 JK |
1257 | test_expect_success 'refname atom rejects unknown arguments' ' |
1258 | test_must_fail git for-each-ref --format="%(refname:foo)" 2>err && | |
1259 | echo "fatal: unrecognized %(refname) argument: foo" >expect && | |
1260 | test_cmp expect err | |
1261 | ' | |
1262 | ||
e5fba5d5 JK |
1263 | test_expect_success 'trailer parsing not fooled by --- line' ' |
1264 | git commit --allow-empty -F - <<-\EOF && | |
1265 | this is the subject | |
1266 | ||
1267 | This is the body. The message has a "---" line which would confuse a | |
1268 | message+patch parser. But here we know we have only a commit message, | |
1269 | so we get it right. | |
1270 | ||
1271 | trailer: wrong | |
1272 | --- | |
1273 | This is more body. | |
1274 | ||
1275 | trailer: right | |
1276 | EOF | |
1277 | ||
1278 | { | |
1279 | echo "trailer: right" && | |
1280 | echo | |
1281 | } >expect && | |
8f19c9fd | 1282 | git for-each-ref --format="%(trailers)" refs/heads/main >actual && |
e5fba5d5 JK |
1283 | test_cmp expect actual |
1284 | ' | |
1285 | ||
01f95825 | 1286 | test_expect_success 'Add symbolic ref for the following tests' ' |
8f19c9fd | 1287 | git symbolic-ref refs/heads/sym refs/heads/main |
01f95825 KN |
1288 | ' |
1289 | ||
1290 | cat >expected <<EOF | |
8f19c9fd | 1291 | refs/heads/main |
01f95825 KN |
1292 | EOF |
1293 | ||
1294 | test_expect_success 'Verify usage of %(symref) atom' ' | |
1295 | git for-each-ref --format="%(symref)" refs/heads/sym >actual && | |
1296 | test_cmp expected actual | |
1297 | ' | |
1298 | ||
1299 | cat >expected <<EOF | |
8f19c9fd | 1300 | heads/main |
01f95825 KN |
1301 | EOF |
1302 | ||
1303 | test_expect_success 'Verify usage of %(symref:short) atom' ' | |
1304 | git for-each-ref --format="%(symref:short)" refs/heads/sym >actual && | |
1305 | test_cmp expected actual | |
1306 | ' | |
1307 | ||
a7984101 | 1308 | cat >expected <<EOF |
8f19c9fd JS |
1309 | main |
1310 | heads/main | |
a7984101 KN |
1311 | EOF |
1312 | ||
17938f17 KN |
1313 | test_expect_success 'Verify usage of %(symref:lstrip) atom' ' |
1314 | git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual && | |
1a0ca5e3 | 1315 | git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual && |
44a6b6ce JH |
1316 | test_cmp expected actual && |
1317 | ||
1318 | git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual && | |
1319 | git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual && | |
a7984101 KN |
1320 | test_cmp expected actual |
1321 | ' | |
1322 | ||
1a34728e KN |
1323 | cat >expected <<EOF |
1324 | refs | |
1325 | refs/heads | |
1326 | EOF | |
1327 | ||
1328 | test_expect_success 'Verify usage of %(symref:rstrip) atom' ' | |
1329 | git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual && | |
1330 | git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual && | |
1331 | test_cmp expected actual | |
1332 | ' | |
1333 | ||
1b586867 JS |
1334 | test_expect_success ':remotename and :remoteref' ' |
1335 | git init remote-tests && | |
1336 | ( | |
1337 | cd remote-tests && | |
1338 | test_commit initial && | |
8f19c9fd | 1339 | git branch -M main && |
1b586867 | 1340 | git remote add from fifth.coffee:blub && |
8f19c9fd JS |
1341 | git config branch.main.remote from && |
1342 | git config branch.main.merge refs/heads/stable && | |
1b586867 JS |
1343 | git remote add to southridge.audio:repo && |
1344 | git config remote.to.push "refs/heads/*:refs/heads/pushed/*" && | |
8f19c9fd | 1345 | git config branch.main.pushRemote to && |
1b586867 JS |
1346 | for pair in "%(upstream)=refs/remotes/from/stable" \ |
1347 | "%(upstream:remotename)=from" \ | |
1348 | "%(upstream:remoteref)=refs/heads/stable" \ | |
8f19c9fd | 1349 | "%(push)=refs/remotes/to/pushed/main" \ |
1b586867 | 1350 | "%(push:remotename)=to" \ |
8f19c9fd | 1351 | "%(push:remoteref)=refs/heads/pushed/main" |
1b586867 JS |
1352 | do |
1353 | echo "${pair#*=}" >expect && | |
1354 | git for-each-ref --format="${pair%=*}" \ | |
8f19c9fd | 1355 | refs/heads/main >actual && |
0c51d6b4 | 1356 | test_cmp expect actual || exit 1 |
1b586867 JS |
1357 | done && |
1358 | git branch push-simple && | |
1359 | git config branch.push-simple.pushRemote from && | |
1360 | actual="$(git for-each-ref \ | |
1361 | --format="%(push:remotename),%(push:remoteref)" \ | |
1362 | refs/heads/push-simple)" && | |
1363 | test from, = "$actual" | |
1364 | ) | |
1365 | ' | |
1366 | ||
e674eb25 | 1367 | test_expect_success 'for-each-ref --ignore-case ignores case' ' |
8f19c9fd | 1368 | git for-each-ref --format="%(refname)" refs/heads/MAIN >actual && |
d3c6751b | 1369 | test_must_be_empty actual && |
ee0f3e22 | 1370 | |
8f19c9fd | 1371 | echo refs/heads/main >expect && |
ee0f3e22 | 1372 | git for-each-ref --format="%(refname)" --ignore-case \ |
8f19c9fd | 1373 | refs/heads/MAIN >actual && |
ee0f3e22 JK |
1374 | test_cmp expect actual |
1375 | ' | |
1376 | ||
aabfdc95 ØW |
1377 | test_expect_success 'for-each-ref --omit-empty works' ' |
1378 | git for-each-ref --format="%(refname)" >actual && | |
1379 | test_line_count -gt 1 actual && | |
1380 | git for-each-ref --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual && | |
1381 | echo refs/heads/main >expect && | |
1382 | test_cmp expect actual | |
1383 | ' | |
1384 | ||
76f9e569 JK |
1385 | test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' ' |
1386 | # name refs numerically to avoid case-insensitive filesystem conflicts | |
1387 | nr=0 && | |
1388 | for email in a A b B | |
1389 | do | |
1390 | for subject in a A b B | |
1391 | do | |
1392 | GIT_COMMITTER_EMAIL="$email@example.com" \ | |
1393 | git tag -m "tag $subject" icase-$(printf %02d $nr) && | |
1394 | nr=$((nr+1))|| | |
1395 | return 1 | |
1396 | done | |
1397 | done && | |
1398 | git for-each-ref --ignore-case \ | |
1399 | --format="%(taggeremail) %(subject) %(refname)" \ | |
1400 | --sort=refname \ | |
1401 | --sort=subject \ | |
1402 | --sort=taggeremail \ | |
1403 | refs/tags/icase-* >actual && | |
1404 | cat >expect <<-\EOF && | |
1405 | <a@example.com> tag a refs/tags/icase-00 | |
1406 | <a@example.com> tag A refs/tags/icase-01 | |
1407 | <A@example.com> tag a refs/tags/icase-04 | |
1408 | <A@example.com> tag A refs/tags/icase-05 | |
1409 | <a@example.com> tag b refs/tags/icase-02 | |
1410 | <a@example.com> tag B refs/tags/icase-03 | |
1411 | <A@example.com> tag b refs/tags/icase-06 | |
1412 | <A@example.com> tag B refs/tags/icase-07 | |
1413 | <b@example.com> tag a refs/tags/icase-08 | |
1414 | <b@example.com> tag A refs/tags/icase-09 | |
1415 | <B@example.com> tag a refs/tags/icase-12 | |
1416 | <B@example.com> tag A refs/tags/icase-13 | |
1417 | <b@example.com> tag b refs/tags/icase-10 | |
1418 | <b@example.com> tag B refs/tags/icase-11 | |
1419 | <B@example.com> tag b refs/tags/icase-14 | |
1420 | <B@example.com> tag B refs/tags/icase-15 | |
1421 | EOF | |
1422 | test_cmp expect actual | |
1423 | ' | |
1424 | ||
c6854508 JK |
1425 | test_expect_success 'for-each-ref reports broken tags' ' |
1426 | git tag -m "good tag" broken-tag-good HEAD && | |
1427 | git cat-file tag broken-tag-good >good && | |
1428 | sed s/commit/blob/ <good >bad && | |
1429 | bad=$(git hash-object -w -t tag bad) && | |
1430 | git update-ref refs/tags/broken-tag-bad $bad && | |
1431 | test_must_fail git for-each-ref --format="%(*objectname)" \ | |
1432 | refs/tags/broken-tag-* | |
1433 | ' | |
1434 | ||
b01e1c7e JK |
1435 | test_expect_success 'set up tag with signature and no blank lines' ' |
1436 | git tag -F - fake-sig-no-blanks <<-\EOF | |
1437 | this is the subject | |
1438 | -----BEGIN PGP SIGNATURE----- | |
1439 | not a real signature, but we just care about the | |
1440 | subject/body parsing. It is important here that | |
1441 | there are no blank lines in the signature. | |
1442 | -----END PGP SIGNATURE----- | |
1443 | EOF | |
1444 | ' | |
1445 | ||
1446 | test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject' | |
1447 | test_atom refs/tags/fake-sig-no-blanks contents:body '' | |
1448 | test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig" | |
1449 | ||
8e1c5fcf JK |
1450 | test_expect_success 'set up tag with CRLF signature' ' |
1451 | append_cr <<-\EOF | | |
1452 | this is the subject | |
1453 | -----BEGIN PGP SIGNATURE----- | |
1454 | ||
1455 | not a real signature, but we just care about | |
1456 | the subject/body parsing. It is important here | |
1457 | that there is a blank line separating this | |
1458 | from the signature header. | |
1459 | -----END PGP SIGNATURE----- | |
1460 | EOF | |
1461 | git tag -F - --cleanup=verbatim fake-sig-crlf | |
1462 | ' | |
1463 | ||
1464 | test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject' | |
1465 | test_atom refs/tags/fake-sig-crlf contents:body '' | |
1466 | ||
1467 | # CRLF is retained in the signature, so we have to pass our expected value | |
1468 | # through append_cr. But test_atom requires a shell string, which means command | |
1469 | # substitution, and the shell will strip trailing newlines from the output of | |
1470 | # the substitution. Hack around it by adding and then removing a dummy line. | |
1471 | sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)" | |
1472 | sig_crlf=${sig_crlf%dummy} | |
1473 | test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf" | |
1474 | ||
b73dec55 DS |
1475 | test_expect_success 'git for-each-ref --stdin: empty' ' |
1476 | >in && | |
1477 | git for-each-ref --format="%(refname)" --stdin <in >actual && | |
1478 | git for-each-ref --format="%(refname)" >expect && | |
1479 | test_cmp expect actual | |
1480 | ' | |
1481 | ||
1482 | test_expect_success 'git for-each-ref --stdin: fails if extra args' ' | |
1483 | >in && | |
1484 | test_must_fail git for-each-ref --format="%(refname)" \ | |
1485 | --stdin refs/heads/extra <in 2>err && | |
1486 | grep "unknown arguments supplied with --stdin" err | |
1487 | ' | |
1488 | ||
1489 | test_expect_success 'git for-each-ref --stdin: matches' ' | |
1490 | cat >in <<-EOF && | |
1491 | refs/tags/multi* | |
1492 | refs/heads/amb* | |
1493 | EOF | |
1494 | ||
1495 | cat >expect <<-EOF && | |
1496 | refs/heads/ambiguous | |
1497 | refs/tags/multi-ref1-100000-user1 | |
1498 | refs/tags/multi-ref1-100000-user2 | |
1499 | refs/tags/multi-ref1-200000-user1 | |
1500 | refs/tags/multi-ref1-200000-user2 | |
1501 | refs/tags/multi-ref2-100000-user1 | |
1502 | refs/tags/multi-ref2-100000-user2 | |
1503 | refs/tags/multi-ref2-200000-user1 | |
1504 | refs/tags/multi-ref2-200000-user2 | |
1505 | refs/tags/multiline | |
1506 | EOF | |
1507 | ||
1508 | git for-each-ref --format="%(refname)" --stdin <in >actual && | |
1509 | test_cmp expect actual | |
1510 | ' | |
1511 | ||
b2c51b75 DS |
1512 | test_expect_success 'git for-each-ref with non-existing refs' ' |
1513 | cat >in <<-EOF && | |
1514 | refs/heads/this-ref-does-not-exist | |
1515 | refs/tags/bogus | |
1516 | EOF | |
1517 | ||
1518 | git for-each-ref --format="%(refname)" --stdin <in >actual && | |
1519 | test_must_be_empty actual && | |
1520 | ||
1521 | xargs git for-each-ref --format="%(refname)" <in >actual && | |
1522 | test_must_be_empty actual | |
1523 | ' | |
1524 | ||
96b2d4fa | 1525 | test_done |