]>
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 | |
26c9c03f | 9 | GNUPGHOME_NOT_USED=$GNUPGHOME |
e2b23972 | 10 | . "$TEST_DIRECTORY"/lib-gpg.sh |
11b087ad | 11 | . "$TEST_DIRECTORY"/lib-terminal.sh |
96b2d4fa | 12 | |
db7bae25 JK |
13 | # Mon Jul 3 23:18:43 2006 +0000 |
14 | datestamp=1151968723 | |
96b2d4fa AP |
15 | setdate_and_increment () { |
16 | GIT_COMMITTER_DATE="$datestamp +0200" | |
17 | datestamp=$(expr "$datestamp" + 1) | |
18 | GIT_AUTHOR_DATE="$datestamp +0200" | |
19 | datestamp=$(expr "$datestamp" + 1) | |
20 | export GIT_COMMITTER_DATE GIT_AUTHOR_DATE | |
21 | } | |
22 | ||
fbc6526e RS |
23 | test_object_file_size () { |
24 | oid=$(git rev-parse "$1") | |
25 | path=".git/objects/$(test_oid_to_path $oid)" | |
26 | test_file_size "$path" | |
27 | } | |
a3d2e83a | 28 | |
fbc6526e | 29 | test_expect_success setup ' |
a3d2e83a KS |
30 | # setup .mailmap |
31 | cat >.mailmap <<-EOF && | |
32 | A Thor <athor@example.com> A U Thor <author@example.com> | |
33 | C Mitter <cmitter@example.com> C O Mitter <committer@example.com> | |
34 | EOF | |
35 | ||
96b2d4fa AP |
36 | setdate_and_increment && |
37 | echo "Using $datestamp" > one && | |
38 | git add one && | |
39 | git commit -m "Initial" && | |
8f19c9fd | 40 | git branch -M main && |
96b2d4fa | 41 | setdate_and_increment && |
bc147968 | 42 | git tag -a -m "Tagging at $datestamp" testtag && |
8f19c9fd | 43 | git update-ref refs/remotes/origin/main main && |
8cae19d9 | 44 | git remote add origin nowhere && |
8f19c9fd JS |
45 | git config branch.main.remote origin && |
46 | git config branch.main.merge refs/heads/main && | |
29bc8850 JK |
47 | git remote add myfork elsewhere && |
48 | git config remote.pushdefault myfork && | |
49 | git config push.default current | |
8cae19d9 JK |
50 | ' |
51 | ||
04830eb7 | 52 | test_atom () { |
d2bf48d2 | 53 | case "$1" in |
8f19c9fd | 54 | head) ref=refs/heads/main ;; |
d2bf48d2 | 55 | tag) ref=refs/tags/testtag ;; |
01f95825 | 56 | sym) ref=refs/heads/sym ;; |
7140c22c | 57 | *) ref=$1 ;; |
d2bf48d2 | 58 | esac |
04830eb7 KS |
59 | format=$2 |
60 | test_do=test_expect_${4:-success} | |
61 | ||
d2bf48d2 | 62 | printf '%s\n' "$3" >expected |
04830eb7 KS |
63 | $test_do $PREREQ "basic atom: $ref $format" ' |
64 | git for-each-ref --format="%($format)" "$ref" >actual && | |
e2b23972 MG |
65 | sanitize_pgp <actual >actual.clean && |
66 | test_cmp expected actual.clean | |
04830eb7 KS |
67 | ' |
68 | ||
b6839fda | 69 | # Automatically test "contents:size" atom after testing "contents" |
04830eb7 | 70 | if test "$format" = "contents" |
b6839fda | 71 | then |
597fa8cb ĐTCD |
72 | # for commit leg, $3 is changed there |
73 | expect=$(printf '%s' "$3" | wc -c) | |
04830eb7 | 74 | $test_do $PREREQ "basic atom: $ref contents:size" ' |
597fa8cb ĐTCD |
75 | type=$(git cat-file -t "$ref") && |
76 | case $type in | |
77 | tag) | |
78 | # We cannot use $3 as it expects sanitize_pgp to run | |
15495773 ĐTCD |
79 | git cat-file tag $ref >out && |
80 | expect=$(tail -n +6 out | wc -c) && | |
81 | rm -f out ;; | |
597fa8cb ĐTCD |
82 | tree | blob) |
83 | expect="" ;; | |
84 | commit) | |
85 | : "use the calculated expect" ;; | |
86 | *) | |
87 | BUG "unknown object type" ;; | |
88 | esac && | |
89 | # Leave $expect unquoted to lose possible leading whitespaces | |
90 | echo $expect >expected && | |
b6839fda | 91 | git for-each-ref --format="%(contents:size)" "$ref" >actual && |
3db796c1 | 92 | test_cmp expected actual |
b6839fda CC |
93 | ' |
94 | fi | |
d2bf48d2 JK |
95 | } |
96 | ||
1f5f8f3e | 97 | hexlen=$(test_oid hexsz) |
1f5f8f3e | 98 | |
8f19c9fd JS |
99 | test_atom head refname refs/heads/main |
100 | test_atom head refname: refs/heads/main | |
101 | test_atom head refname:short main | |
102 | test_atom head refname:lstrip=1 heads/main | |
103 | test_atom head refname:lstrip=2 main | |
104 | test_atom head refname:lstrip=-1 main | |
105 | test_atom head refname:lstrip=-2 heads/main | |
1a34728e KN |
106 | test_atom head refname:rstrip=1 refs/heads |
107 | test_atom head refname:rstrip=2 refs | |
108 | test_atom head refname:rstrip=-1 refs | |
109 | test_atom head refname:rstrip=-2 refs/heads | |
8f19c9fd JS |
110 | test_atom head refname:strip=1 heads/main |
111 | test_atom head refname:strip=2 main | |
112 | test_atom head refname:strip=-1 main | |
113 | test_atom head refname:strip=-2 heads/main | |
114 | test_atom head upstream refs/remotes/origin/main | |
115 | test_atom head upstream:short origin/main | |
116 | test_atom head upstream:lstrip=2 origin/main | |
117 | test_atom head upstream:lstrip=-2 origin/main | |
1a34728e KN |
118 | test_atom head upstream:rstrip=2 refs/remotes |
119 | test_atom head upstream:rstrip=-2 refs/remotes | |
8f19c9fd JS |
120 | test_atom head upstream:strip=2 origin/main |
121 | test_atom head upstream:strip=-2 origin/main | |
122 | test_atom head push refs/remotes/myfork/main | |
123 | test_atom head push:short myfork/main | |
124 | test_atom head push:lstrip=1 remotes/myfork/main | |
125 | test_atom head push:lstrip=-1 main | |
1a34728e KN |
126 | test_atom head push:rstrip=1 refs/remotes/myfork |
127 | test_atom head push:rstrip=-1 refs | |
8f19c9fd JS |
128 | test_atom head push:strip=1 remotes/myfork/main |
129 | test_atom head push:strip=-1 main | |
d2bf48d2 | 130 | test_atom head objecttype commit |
1f5f8f3e | 131 | test_atom head objectsize $((131 + hexlen)) |
fbc6526e | 132 | test_atom head objectsize:disk $(test_object_file_size refs/heads/main) |
1f5f8f3e | 133 | test_atom head deltabase $ZERO_OID |
8f19c9fd JS |
134 | test_atom head objectname $(git rev-parse refs/heads/main) |
135 | test_atom head objectname:short $(git rev-parse --short refs/heads/main) | |
136 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main) | |
137 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main) | |
138 | test_atom head tree $(git rev-parse refs/heads/main^{tree}) | |
139 | test_atom head tree:short $(git rev-parse --short refs/heads/main^{tree}) | |
140 | test_atom head tree:short=1 $(git rev-parse --short=1 refs/heads/main^{tree}) | |
141 | test_atom head tree:short=10 $(git rev-parse --short=10 refs/heads/main^{tree}) | |
d2bf48d2 | 142 | test_atom head parent '' |
26bc0aaf HV |
143 | test_atom head parent:short '' |
144 | test_atom head parent:short=1 '' | |
145 | test_atom head parent:short=10 '' | |
d2bf48d2 JK |
146 | test_atom head numparent 0 |
147 | test_atom head object '' | |
148 | test_atom head type '' | |
bd0708c7 ZH |
149 | test_atom head raw "$(git cat-file commit refs/heads/main) |
150 | " | |
b74cf648 JK |
151 | test_atom head '*objectname' '' |
152 | test_atom head '*objecttype' '' | |
db7bae25 | 153 | test_atom head author 'A U Thor <author@example.com> 1151968724 +0200' |
d2bf48d2 | 154 | test_atom head authorname 'A U Thor' |
a3d2e83a | 155 | test_atom head authorname:mailmap 'A Thor' |
d2bf48d2 | 156 | test_atom head authoremail '<author@example.com>' |
b82445dc HV |
157 | test_atom head authoremail:trim 'author@example.com' |
158 | test_atom head authoremail:localpart 'author' | |
a3d2e83a KS |
159 | test_atom head authoremail:trim,localpart 'author' |
160 | test_atom head authoremail:mailmap '<athor@example.com>' | |
161 | test_atom head authoremail:mailmap,trim 'athor@example.com' | |
162 | test_atom head authoremail:trim,mailmap 'athor@example.com' | |
163 | test_atom head authoremail:mailmap,localpart 'athor' | |
164 | test_atom head authoremail:localpart,mailmap 'athor' | |
165 | test_atom head authoremail:mailmap,trim,localpart,mailmap,trim 'athor' | |
db7bae25 JK |
166 | test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' |
167 | test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200' | |
d2bf48d2 | 168 | test_atom head committername 'C O Mitter' |
a3d2e83a | 169 | test_atom head committername:mailmap 'C Mitter' |
d2bf48d2 | 170 | test_atom head committeremail '<committer@example.com>' |
b82445dc HV |
171 | test_atom head committeremail:trim 'committer@example.com' |
172 | test_atom head committeremail:localpart 'committer' | |
a3d2e83a KS |
173 | test_atom head committeremail:localpart,trim 'committer' |
174 | test_atom head committeremail:mailmap '<cmitter@example.com>' | |
175 | test_atom head committeremail:mailmap,trim 'cmitter@example.com' | |
176 | test_atom head committeremail:trim,mailmap 'cmitter@example.com' | |
177 | test_atom head committeremail:mailmap,localpart 'cmitter' | |
178 | test_atom head committeremail:localpart,mailmap 'cmitter' | |
179 | test_atom head committeremail:trim,mailmap,trim,trim,localpart 'cmitter' | |
db7bae25 | 180 | test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' |
d2bf48d2 JK |
181 | test_atom head tag '' |
182 | test_atom head tagger '' | |
183 | test_atom head taggername '' | |
184 | test_atom head taggeremail '' | |
b82445dc HV |
185 | test_atom head taggeremail:trim '' |
186 | test_atom head taggeremail:localpart '' | |
d2bf48d2 | 187 | test_atom head taggerdate '' |
db7bae25 JK |
188 | test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200' |
189 | test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' | |
d2bf48d2 | 190 | test_atom head subject 'Initial' |
905f0a4e | 191 | test_atom head subject:sanitize 'Initial' |
e2b23972 | 192 | test_atom head contents:subject 'Initial' |
d2bf48d2 | 193 | test_atom head body '' |
e2b23972 MG |
194 | test_atom head contents:body '' |
195 | test_atom head contents:signature '' | |
d2bf48d2 JK |
196 | test_atom head contents 'Initial |
197 | ' | |
7a48b832 | 198 | test_atom head HEAD '*' |
d2bf48d2 JK |
199 | |
200 | test_atom tag refname refs/tags/testtag | |
1d094db9 | 201 | test_atom tag refname:short testtag |
8cae19d9 | 202 | test_atom tag upstream '' |
29bc8850 | 203 | test_atom tag push '' |
d2bf48d2 | 204 | test_atom tag objecttype tag |
1f5f8f3e | 205 | test_atom tag objectsize $((114 + hexlen)) |
fbc6526e RS |
206 | test_atom tag objectsize:disk $(test_object_file_size refs/tags/testtag) |
207 | test_atom tag '*objectsize:disk' $(test_object_file_size refs/heads/main) | |
1f5f8f3e | 208 | test_atom tag deltabase $ZERO_OID |
209 | test_atom tag '*deltabase' $ZERO_OID | |
189a5467 | 210 | test_atom tag objectname $(git rev-parse refs/tags/testtag) |
1d094db9 | 211 | test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) |
8f19c9fd JS |
212 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/main) |
213 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/main) | |
d2bf48d2 | 214 | test_atom tag tree '' |
837adb10 HV |
215 | test_atom tag tree:short '' |
216 | test_atom tag tree:short=1 '' | |
217 | test_atom tag tree:short=10 '' | |
d2bf48d2 | 218 | test_atom tag parent '' |
26bc0aaf HV |
219 | test_atom tag parent:short '' |
220 | test_atom tag parent:short=1 '' | |
221 | test_atom tag parent:short=10 '' | |
d2bf48d2 | 222 | test_atom tag numparent '' |
189a5467 | 223 | test_atom tag object $(git rev-parse refs/tags/testtag^0) |
d2bf48d2 | 224 | test_atom tag type 'commit' |
1f5f8f3e | 225 | test_atom tag '*objectname' $(git rev-parse refs/tags/testtag^{}) |
b74cf648 | 226 | test_atom tag '*objecttype' 'commit' |
d2bf48d2 JK |
227 | test_atom tag author '' |
228 | test_atom tag authorname '' | |
a3d2e83a | 229 | test_atom tag authorname:mailmap '' |
d2bf48d2 | 230 | test_atom tag authoremail '' |
b82445dc HV |
231 | test_atom tag authoremail:trim '' |
232 | test_atom tag authoremail:localpart '' | |
a3d2e83a KS |
233 | test_atom tag authoremail:trim,localpart '' |
234 | test_atom tag authoremail:mailmap '' | |
235 | test_atom tag authoremail:mailmap,trim '' | |
236 | test_atom tag authoremail:trim,mailmap '' | |
237 | test_atom tag authoremail:mailmap,localpart '' | |
238 | test_atom tag authoremail:localpart,mailmap '' | |
239 | test_atom tag authoremail:mailmap,trim,localpart,mailmap,trim '' | |
d2bf48d2 JK |
240 | test_atom tag authordate '' |
241 | test_atom tag committer '' | |
242 | test_atom tag committername '' | |
a3d2e83a | 243 | test_atom tag committername:mailmap '' |
d2bf48d2 | 244 | test_atom tag committeremail '' |
b82445dc HV |
245 | test_atom tag committeremail:trim '' |
246 | test_atom tag committeremail:localpart '' | |
a3d2e83a KS |
247 | test_atom tag committeremail:localpart,trim '' |
248 | test_atom tag committeremail:mailmap '' | |
249 | test_atom tag committeremail:mailmap,trim '' | |
250 | test_atom tag committeremail:trim,mailmap '' | |
251 | test_atom tag committeremail:mailmap,localpart '' | |
252 | test_atom tag committeremail:localpart,mailmap '' | |
253 | test_atom tag committeremail:trim,mailmap,trim,trim,localpart '' | |
d2bf48d2 JK |
254 | test_atom tag committerdate '' |
255 | test_atom tag tag 'testtag' | |
db7bae25 | 256 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200' |
d2bf48d2 | 257 | test_atom tag taggername 'C O Mitter' |
a3d2e83a | 258 | test_atom tag taggername:mailmap 'C Mitter' |
d2bf48d2 | 259 | test_atom tag taggeremail '<committer@example.com>' |
b82445dc HV |
260 | test_atom tag taggeremail:trim 'committer@example.com' |
261 | test_atom tag taggeremail:localpart 'committer' | |
a3d2e83a KS |
262 | test_atom tag taggeremail:trim,localpart 'committer' |
263 | test_atom tag taggeremail:mailmap '<cmitter@example.com>' | |
264 | test_atom tag taggeremail:mailmap,trim 'cmitter@example.com' | |
265 | test_atom tag taggeremail:trim,mailmap 'cmitter@example.com' | |
266 | test_atom tag taggeremail:mailmap,localpart 'cmitter' | |
267 | test_atom tag taggeremail:localpart,mailmap 'cmitter' | |
268 | test_atom tag taggeremail:trim,mailmap,trim,localpart,localpart 'cmitter' | |
db7bae25 JK |
269 | test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' |
270 | test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200' | |
271 | test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' | |
272 | test_atom tag subject 'Tagging at 1151968727' | |
905f0a4e | 273 | test_atom tag subject:sanitize 'Tagging-at-1151968727' |
db7bae25 | 274 | test_atom tag contents:subject 'Tagging at 1151968727' |
d2bf48d2 | 275 | test_atom tag body '' |
e2b23972 MG |
276 | test_atom tag contents:body '' |
277 | test_atom tag contents:signature '' | |
db7bae25 | 278 | test_atom tag contents 'Tagging at 1151968727 |
96b2d4fa | 279 | ' |
7a48b832 | 280 | test_atom tag HEAD ' ' |
96b2d4fa | 281 | |
bd0708c7 ZH |
282 | test_expect_success 'basic atom: refs/tags/testtag *raw' ' |
283 | git cat-file commit refs/tags/testtag^{} >expected && | |
284 | git for-each-ref --format="%(*raw)" refs/tags/testtag >actual && | |
285 | sanitize_pgp <expected >expected.clean && | |
286 | echo >>expected.clean && | |
287 | sanitize_pgp <actual >actual.clean && | |
288 | test_cmp expected.clean actual.clean | |
289 | ' | |
290 | ||
41ac414e | 291 | test_expect_success 'Check invalid atoms names are errors' ' |
3604e7c5 | 292 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
96b2d4fa AP |
293 | ' |
294 | ||
295 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' | |
3604e7c5 NS |
296 | git for-each-ref --format="%(authordate)" refs/heads && |
297 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && | |
298 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && | |
299 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads | |
96b2d4fa AP |
300 | ' |
301 | ||
302 | test_expect_success 'Check valid format specifiers for date fields' ' | |
3604e7c5 NS |
303 | git for-each-ref --format="%(authordate:default)" refs/heads && |
304 | git for-each-ref --format="%(authordate:relative)" refs/heads && | |
305 | git for-each-ref --format="%(authordate:short)" refs/heads && | |
306 | git for-each-ref --format="%(authordate:local)" refs/heads && | |
307 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && | |
308 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads | |
96b2d4fa AP |
309 | ' |
310 | ||
41ac414e | 311 | test_expect_success 'Check invalid format specifiers are errors' ' |
3604e7c5 | 312 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
96b2d4fa AP |
313 | ' |
314 | ||
42d0eb05 KN |
315 | test_expect_success 'arguments to %(objectname:short=) must be positive integers' ' |
316 | test_must_fail git for-each-ref --format="%(objectname:short=0)" && | |
317 | test_must_fail git for-each-ref --format="%(objectname:short=-1)" && | |
318 | test_must_fail git for-each-ref --format="%(objectname:short=foo)" | |
319 | ' | |
320 | ||
0144f0de KS |
321 | test_bad_atom () { |
322 | case "$1" in | |
323 | head) ref=refs/heads/main ;; | |
324 | tag) ref=refs/tags/testtag ;; | |
325 | sym) ref=refs/heads/sym ;; | |
326 | *) ref=$1 ;; | |
327 | esac | |
328 | format=$2 | |
329 | test_do=test_expect_${4:-success} | |
330 | ||
331 | printf '%s\n' "$3" >expect | |
332 | $test_do $PREREQ "err basic atom: $ref $format" ' | |
333 | test_must_fail git for-each-ref \ | |
334 | --format="%($format)" "$ref" 2>error && | |
335 | test_cmp expect error | |
336 | ' | |
337 | } | |
338 | ||
339 | test_bad_atom head 'authoremail:foo' \ | |
340 | 'fatal: unrecognized %(authoremail) argument: foo' | |
341 | ||
a3d2e83a KS |
342 | test_bad_atom head 'authoremail:mailmap,trim,bar' \ |
343 | 'fatal: unrecognized %(authoremail) argument: bar' | |
344 | ||
345 | test_bad_atom head 'authoremail:trim,' \ | |
346 | 'fatal: unrecognized %(authoremail) argument: ' | |
347 | ||
348 | test_bad_atom head 'authoremail:mailmaptrim' \ | |
349 | 'fatal: unrecognized %(authoremail) argument: trim' | |
350 | ||
351 | test_bad_atom head 'committeremail: ' \ | |
352 | 'fatal: unrecognized %(committeremail) argument: ' | |
353 | ||
354 | test_bad_atom head 'committeremail: trim,foo' \ | |
355 | 'fatal: unrecognized %(committeremail) argument: trim,foo' | |
356 | ||
357 | test_bad_atom head 'committeremail:mailmap,localpart ' \ | |
358 | 'fatal: unrecognized %(committeremail) argument: ' | |
359 | ||
360 | test_bad_atom head 'committeremail:trim_localpart' \ | |
361 | 'fatal: unrecognized %(committeremail) argument: _localpart' | |
362 | ||
363 | test_bad_atom head 'committeremail:localpart,,,trim' \ | |
364 | 'fatal: unrecognized %(committeremail) argument: ,,trim' | |
365 | ||
366 | test_bad_atom tag 'taggeremail:mailmap,trim, foo ' \ | |
367 | 'fatal: unrecognized %(taggeremail) argument: foo ' | |
368 | ||
369 | test_bad_atom tag 'taggeremail:trim,localpart,' \ | |
370 | 'fatal: unrecognized %(taggeremail) argument: ' | |
371 | ||
372 | test_bad_atom tag 'taggeremail:mailmap;localpart trim' \ | |
373 | 'fatal: unrecognized %(taggeremail) argument: ;localpart trim' | |
374 | ||
0144f0de | 375 | test_bad_atom tag 'taggeremail:localpart trim' \ |
a3d2e83a KS |
376 | 'fatal: unrecognized %(taggeremail) argument: trim' |
377 | ||
378 | test_bad_atom tag 'taggeremail:mailmap,mailmap,trim,qux,localpart,trim' \ | |
379 | 'fatal: unrecognized %(taggeremail) argument: qux,localpart,trim' | |
0144f0de | 380 | |
f95cecf4 JK |
381 | test_date () { |
382 | f=$1 && | |
383 | committer_date=$2 && | |
384 | author_date=$3 && | |
385 | tagger_date=$4 && | |
386 | cat >expected <<-EOF && | |
8f19c9fd | 387 | 'refs/heads/main' '$committer_date' '$author_date' |
f95cecf4 JK |
388 | 'refs/tags/testtag' '$tagger_date' |
389 | EOF | |
390 | ( | |
391 | git for-each-ref --shell \ | |
392 | --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \ | |
393 | refs/heads && | |
394 | git for-each-ref --shell \ | |
395 | --format="%(refname) %(taggerdate${f:+:$f})" \ | |
396 | refs/tags | |
397 | ) >actual && | |
398 | test_cmp expected actual | |
399 | } | |
96b2d4fa AP |
400 | |
401 | test_expect_success 'Check unformatted date fields output' ' | |
f95cecf4 | 402 | test_date "" \ |
db7bae25 JK |
403 | "Tue Jul 4 01:18:43 2006 +0200" \ |
404 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
405 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
406 | ' |
407 | ||
408 | test_expect_success 'Check format "default" formatted date fields output' ' | |
f95cecf4 | 409 | test_date default \ |
db7bae25 JK |
410 | "Tue Jul 4 01:18:43 2006 +0200" \ |
411 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
412 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
413 | ' |
414 | ||
99264e93 JK |
415 | test_expect_success 'Check format "default-local" date fields output' ' |
416 | 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 |
417 | ' |
418 | ||
419 | # Don't know how to do relative check because I can't know when this script | |
420 | # is going to be run and can't fake the current time to git, and hence can't | |
421 | # provide expected output. Instead, I'll just make sure that "relative" | |
422 | # doesn't exit in error | |
96b2d4fa AP |
423 | test_expect_success 'Check format "relative" date fields output' ' |
424 | f=relative && | |
425 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
426 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual | |
427 | ' | |
428 | ||
99264e93 JK |
429 | # We just check that this is the same as "relative" for now. |
430 | test_expect_success 'Check format "relative-local" date fields output' ' | |
431 | test_date relative-local \ | |
432 | "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \ | |
433 | "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \ | |
434 | "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)" | |
435 | ' | |
96b2d4fa AP |
436 | |
437 | test_expect_success 'Check format "short" date fields output' ' | |
db7bae25 | 438 | test_date short 2006-07-04 2006-07-04 2006-07-04 |
96b2d4fa AP |
439 | ' |
440 | ||
99264e93 JK |
441 | test_expect_success 'Check format "short-local" date fields output' ' |
442 | test_date short-local 2006-07-03 2006-07-03 2006-07-03 | |
443 | ' | |
96b2d4fa AP |
444 | |
445 | test_expect_success 'Check format "local" date fields output' ' | |
f95cecf4 | 446 | test_date local \ |
db7bae25 JK |
447 | "Mon Jul 3 23:18:43 2006" \ |
448 | "Mon Jul 3 23:18:44 2006" \ | |
449 | "Mon Jul 3 23:18:45 2006" | |
96b2d4fa AP |
450 | ' |
451 | ||
96b2d4fa | 452 | test_expect_success 'Check format "iso8601" date fields output' ' |
f95cecf4 | 453 | test_date iso8601 \ |
db7bae25 JK |
454 | "2006-07-04 01:18:43 +0200" \ |
455 | "2006-07-04 01:18:44 +0200" \ | |
456 | "2006-07-04 01:18:45 +0200" | |
96b2d4fa AP |
457 | ' |
458 | ||
99264e93 JK |
459 | test_expect_success 'Check format "iso8601-local" date fields output' ' |
460 | 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" | |
461 | ' | |
96b2d4fa AP |
462 | |
463 | test_expect_success 'Check format "rfc2822" date fields output' ' | |
f95cecf4 | 464 | test_date rfc2822 \ |
db7bae25 JK |
465 | "Tue, 4 Jul 2006 01:18:43 +0200" \ |
466 | "Tue, 4 Jul 2006 01:18:44 +0200" \ | |
467 | "Tue, 4 Jul 2006 01:18:45 +0200" | |
96b2d4fa AP |
468 | ' |
469 | ||
99264e93 JK |
470 | test_expect_success 'Check format "rfc2822-local" date fields output' ' |
471 | 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" | |
472 | ' | |
473 | ||
f3c1ba50 | 474 | test_expect_success 'Check format "raw" date fields output' ' |
db7bae25 | 475 | test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200" |
f3c1ba50 JK |
476 | ' |
477 | ||
99264e93 JK |
478 | test_expect_success 'Check format "raw-local" date fields output' ' |
479 | test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000" | |
96b2d4fa AP |
480 | ' |
481 | ||
aa1462cc | 482 | test_expect_success 'Check format of strftime date fields' ' |
db7bae25 | 483 | echo "my date is 2006-07-04" >expected && |
aa1462cc JK |
484 | git for-each-ref \ |
485 | --format="%(authordate:format:my date is %Y-%m-%d)" \ | |
486 | refs/heads >actual && | |
487 | test_cmp expected actual | |
488 | ' | |
489 | ||
99264e93 JK |
490 | test_expect_success 'Check format of strftime-local date fields' ' |
491 | echo "my date is 2006-07-03" >expected && | |
492 | git for-each-ref \ | |
493 | --format="%(authordate:format-local:my date is %Y-%m-%d)" \ | |
494 | refs/heads >actual && | |
495 | test_cmp expected actual | |
496 | ' | |
497 | ||
e4f031e3 JK |
498 | test_expect_success 'exercise strftime with odd fields' ' |
499 | echo >expected && | |
500 | git for-each-ref --format="%(authordate:format:)" refs/heads >actual && | |
501 | test_cmp expected actual && | |
8125a58b | 502 | long="long format -- $ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID$ZERO_OID" && |
e4f031e3 JK |
503 | echo $long >expected && |
504 | git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && | |
505 | test_cmp expected actual | |
506 | ' | |
507 | ||
c899a57c | 508 | cat >expected <<\EOF |
8f19c9fd JS |
509 | refs/heads/main |
510 | refs/remotes/origin/main | |
c899a57c LH |
511 | refs/tags/testtag |
512 | EOF | |
513 | ||
514 | test_expect_success 'Verify ascending sort' ' | |
3604e7c5 | 515 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
3af82863 | 516 | test_cmp expected actual |
c899a57c LH |
517 | ' |
518 | ||
519 | ||
520 | cat >expected <<\EOF | |
521 | refs/tags/testtag | |
8f19c9fd JS |
522 | refs/remotes/origin/main |
523 | refs/heads/main | |
c899a57c LH |
524 | EOF |
525 | ||
526 | test_expect_success 'Verify descending sort' ' | |
3604e7c5 | 527 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
3af82863 | 528 | test_cmp expected actual |
b31e2680 TB |
529 | ' |
530 | ||
98e7ab6d JH |
531 | test_expect_success 'Give help even with invalid sort atoms' ' |
532 | test_expect_code 129 git for-each-ref --sort=bogus -h >actual 2>&1 && | |
533 | grep "^usage: git for-each-ref" actual | |
534 | ' | |
535 | ||
b31e2680 TB |
536 | cat >expected <<\EOF |
537 | refs/tags/testtag | |
538 | refs/tags/testtag-2 | |
539 | EOF | |
540 | ||
541 | test_expect_success 'exercise patterns with prefixes' ' | |
542 | git tag testtag-2 && | |
543 | test_when_finished "git tag -d testtag-2" && | |
544 | git for-each-ref --format="%(refname)" \ | |
545 | refs/tags/testtag refs/tags/testtag-2 >actual && | |
546 | test_cmp expected actual | |
547 | ' | |
548 | ||
549 | cat >expected <<\EOF | |
550 | refs/tags/testtag | |
551 | refs/tags/testtag-2 | |
552 | EOF | |
553 | ||
554 | test_expect_success 'exercise glob patterns with prefixes' ' | |
555 | git tag testtag-2 && | |
556 | test_when_finished "git tag -d testtag-2" && | |
557 | git for-each-ref --format="%(refname)" \ | |
558 | refs/tags/testtag "refs/tags/testtag-*" >actual && | |
559 | test_cmp expected actual | |
c899a57c LH |
560 | ' |
561 | ||
8255dd8a TB |
562 | cat >expected <<\EOF |
563 | refs/tags/bar | |
564 | refs/tags/baz | |
565 | refs/tags/testtag | |
566 | EOF | |
567 | ||
568 | test_expect_success 'exercise patterns with prefix exclusions' ' | |
569 | for tag in foo/one foo/two foo/three bar baz | |
570 | do | |
571 | git tag "$tag" || return 1 | |
572 | done && | |
573 | test_when_finished "git tag -d foo/one foo/two foo/three bar baz" && | |
574 | git for-each-ref --format="%(refname)" \ | |
575 | refs/tags/ --exclude=refs/tags/foo >actual && | |
576 | test_cmp expected actual | |
577 | ' | |
578 | ||
579 | cat >expected <<\EOF | |
580 | refs/tags/bar | |
581 | refs/tags/baz | |
582 | refs/tags/foo/one | |
583 | refs/tags/testtag | |
584 | EOF | |
585 | ||
586 | test_expect_success 'exercise patterns with pattern exclusions' ' | |
587 | for tag in foo/one foo/two foo/three bar baz | |
588 | do | |
589 | git tag "$tag" || return 1 | |
590 | done && | |
591 | test_when_finished "git tag -d foo/one foo/two foo/three bar baz" && | |
592 | git for-each-ref --format="%(refname)" \ | |
593 | refs/tags/ --exclude="refs/tags/foo/t*" >actual && | |
594 | test_cmp expected actual | |
595 | ' | |
596 | ||
c9ecf4f1 | 597 | cat >expected <<\EOF |
8f19c9fd JS |
598 | 'refs/heads/main' |
599 | 'refs/remotes/origin/main' | |
c9ecf4f1 JS |
600 | 'refs/tags/testtag' |
601 | EOF | |
602 | ||
603 | test_expect_success 'Quoting style: shell' ' | |
604 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 605 | test_cmp expected actual |
c9ecf4f1 JS |
606 | ' |
607 | ||
608 | test_expect_success 'Quoting style: perl' ' | |
609 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 610 | test_cmp expected actual |
c9ecf4f1 JS |
611 | ' |
612 | ||
613 | test_expect_success 'Quoting style: python' ' | |
614 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 615 | test_cmp expected actual |
c9ecf4f1 JS |
616 | ' |
617 | ||
618 | cat >expected <<\EOF | |
8f19c9fd JS |
619 | "refs/heads/main" |
620 | "refs/remotes/origin/main" | |
c9ecf4f1 JS |
621 | "refs/tags/testtag" |
622 | EOF | |
623 | ||
624 | test_expect_success 'Quoting style: tcl' ' | |
625 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 626 | test_cmp expected actual |
c9ecf4f1 JS |
627 | ' |
628 | ||
629 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do | |
630 | test_expect_success "more than one quoting style: $i" " | |
2708ef4a SG |
631 | test_must_fail git for-each-ref $i 2>err && |
632 | grep '^error: more than one quoting style' err | |
c9ecf4f1 JS |
633 | " |
634 | done | |
c899a57c | 635 | |
b28061ce RR |
636 | test_expect_success 'setup for upstream:track[short]' ' |
637 | test_commit two | |
638 | ' | |
639 | ||
1d094db9 JK |
640 | test_atom head upstream:track '[ahead 1]' |
641 | test_atom head upstream:trackshort '>' | |
7743fcca KN |
642 | test_atom head upstream:track,nobracket 'ahead 1' |
643 | test_atom head upstream:nobracket,track 'ahead 1' | |
c646d093 DR |
644 | |
645 | test_expect_success 'setup for push:track[short]' ' | |
646 | test_commit third && | |
8f19c9fd JS |
647 | git update-ref refs/remotes/myfork/main main && |
648 | git reset main~1 | |
c646d093 DR |
649 | ' |
650 | ||
651 | test_atom head push:track '[behind 1]' | |
652 | test_atom head push:trackshort '<' | |
b28061ce RR |
653 | |
654 | test_expect_success 'Check that :track[short] cannot be used with other atoms' ' | |
655 | test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && | |
656 | test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null | |
657 | ' | |
658 | ||
b6160d95 RKC |
659 | test_expect_success 'Check that :track[short] works when upstream is invalid' ' |
660 | cat >expected <<-\EOF && | |
ffd921d3 | 661 | [gone] |
b6160d95 RKC |
662 | |
663 | EOF | |
8f19c9fd JS |
664 | test_when_finished "git config branch.main.merge refs/heads/main" && |
665 | git config branch.main.merge refs/heads/does-not-exist && | |
b6160d95 RKC |
666 | git for-each-ref \ |
667 | --format="%(upstream:track)$LF%(upstream:trackshort)" \ | |
668 | refs/heads >actual && | |
669 | test_cmp expected actual | |
29bc8850 JK |
670 | ' |
671 | ||
7d66f21a BW |
672 | test_expect_success 'Check for invalid refname format' ' |
673 | test_must_fail git for-each-ref --format="%(refname:INVALID)" | |
674 | ' | |
675 | ||
11b087ad JK |
676 | test_expect_success 'set up color tests' ' |
677 | cat >expected.color <<-EOF && | |
8f19c9fd JS |
678 | $(git rev-parse --short refs/heads/main) <GREEN>main<RESET> |
679 | $(git rev-parse --short refs/remotes/myfork/main) <GREEN>myfork/main<RESET> | |
680 | $(git rev-parse --short refs/remotes/origin/main) <GREEN>origin/main<RESET> | |
11b087ad | 681 | $(git rev-parse --short refs/tags/testtag) <GREEN>testtag<RESET> |
c646d093 | 682 | $(git rev-parse --short refs/tags/third) <GREEN>third<RESET> |
11b087ad JK |
683 | $(git rev-parse --short refs/tags/two) <GREEN>two<RESET> |
684 | EOF | |
685 | sed "s/<[^>]*>//g" <expected.color >expected.bare && | |
686 | color_format="%(objectname:short) %(color:green)%(refname:short)" | |
687 | ' | |
fddb74c9 | 688 | |
11b087ad | 689 | test_expect_success TTY '%(color) shows color with a tty' ' |
e433749d | 690 | test_terminal git for-each-ref --format="$color_format" >actual.raw && |
097b681b | 691 | test_decode_color <actual.raw >actual && |
11b087ad JK |
692 | test_cmp expected.color actual |
693 | ' | |
694 | ||
695 | test_expect_success '%(color) does not show color without tty' ' | |
696 | TERM=vt100 git for-each-ref --format="$color_format" >actual && | |
697 | test_cmp expected.bare actual | |
698 | ' | |
699 | ||
0c88bf50 JK |
700 | test_expect_success '--color can override tty check' ' |
701 | git for-each-ref --color --format="$color_format" >actual.raw && | |
11b087ad JK |
702 | test_decode_color <actual.raw >actual && |
703 | test_cmp expected.color actual | |
fddb74c9 RR |
704 | ' |
705 | ||
b521fd12 JK |
706 | test_expect_success 'color.ui=always does not override tty check' ' |
707 | git -c color.ui=always for-each-ref --format="$color_format" >actual && | |
708 | test_cmp expected.bare actual | |
709 | ' | |
710 | ||
f5d18f8c KS |
711 | test_expect_success 'setup for describe atom tests' ' |
712 | git init -b master describe-repo && | |
713 | ( | |
714 | cd describe-repo && | |
715 | ||
716 | test_commit --no-tag one && | |
717 | git tag tagone && | |
718 | ||
719 | test_commit --no-tag two && | |
720 | git tag -a -m "tag two" tagtwo | |
721 | ) | |
722 | ' | |
723 | ||
724 | test_expect_success 'describe atom vs git describe' ' | |
725 | ( | |
726 | cd describe-repo && | |
727 | ||
728 | git for-each-ref --format="%(objectname)" \ | |
729 | refs/tags/ >obj && | |
730 | while read hash | |
731 | do | |
732 | if desc=$(git describe $hash) | |
733 | then | |
734 | : >expect-contains-good | |
735 | else | |
736 | : >expect-contains-bad | |
737 | fi && | |
738 | echo "$hash $desc" || return 1 | |
739 | done <obj >expect && | |
740 | test_path_exists expect-contains-good && | |
741 | test_path_exists expect-contains-bad && | |
742 | ||
743 | git for-each-ref --format="%(objectname) %(describe)" \ | |
744 | refs/tags/ >actual 2>err && | |
745 | test_cmp expect actual && | |
746 | test_must_be_empty err | |
747 | ) | |
748 | ' | |
749 | ||
750 | test_expect_success 'describe:tags vs describe --tags' ' | |
751 | ( | |
752 | cd describe-repo && | |
753 | git describe --tags >expect && | |
754 | git for-each-ref --format="%(describe:tags)" \ | |
755 | refs/heads/master >actual && | |
756 | test_cmp expect actual | |
757 | ) | |
758 | ' | |
759 | ||
760 | test_expect_success 'describe:abbrev=... vs describe --abbrev=...' ' | |
761 | ( | |
762 | cd describe-repo && | |
763 | ||
764 | # Case 1: We have commits between HEAD and the most | |
765 | # recent tag reachable from it | |
766 | test_commit --no-tag file && | |
767 | git describe --abbrev=14 >expect && | |
768 | git for-each-ref --format="%(describe:abbrev=14)" \ | |
769 | refs/heads/master >actual && | |
770 | test_cmp expect actual && | |
771 | ||
772 | # Make sure the hash used is atleast 14 digits long | |
773 | sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart && | |
774 | test 15 -le $(wc -c <hexpart) && | |
775 | ||
776 | # Case 2: We have a tag at HEAD, describe directly gives | |
777 | # the name of the tag | |
778 | git tag -a -m tagged tagname && | |
779 | git describe --abbrev=14 >expect && | |
780 | git for-each-ref --format="%(describe:abbrev=14)" \ | |
781 | refs/heads/master >actual && | |
782 | test_cmp expect actual && | |
783 | test tagname = $(cat actual) | |
784 | ) | |
785 | ' | |
786 | ||
787 | test_expect_success 'describe:match=... vs describe --match ...' ' | |
788 | ( | |
789 | cd describe-repo && | |
790 | git tag -a -m "tag foo" tag-foo && | |
791 | git describe --match "*-foo" >expect && | |
792 | git for-each-ref --format="%(describe:match="*-foo")" \ | |
793 | refs/heads/master >actual && | |
794 | test_cmp expect actual | |
795 | ) | |
796 | ' | |
797 | ||
798 | test_expect_success 'describe:exclude:... vs describe --exclude ...' ' | |
799 | ( | |
800 | cd describe-repo && | |
801 | git tag -a -m "tag bar" tag-bar && | |
802 | git describe --exclude "*-bar" >expect && | |
803 | git for-each-ref --format="%(describe:exclude="*-bar")" \ | |
804 | refs/heads/master >actual && | |
805 | test_cmp expect actual | |
806 | ) | |
807 | ' | |
808 | ||
809 | test_expect_success 'deref with describe atom' ' | |
810 | ( | |
811 | cd describe-repo && | |
812 | cat >expect <<-\EOF && | |
813 | ||
814 | tagname | |
815 | tagname | |
816 | tagname | |
817 | ||
818 | tagtwo | |
819 | EOF | |
820 | git for-each-ref --format="%(*describe)" >actual && | |
821 | test_cmp expect actual | |
822 | ) | |
823 | ' | |
824 | ||
825 | test_expect_success 'err on bad describe atom arg' ' | |
826 | ( | |
827 | cd describe-repo && | |
828 | ||
829 | # The bad arg is the only arg passed to describe atom | |
830 | cat >expect <<-\EOF && | |
831 | fatal: unrecognized %(describe) argument: baz | |
832 | EOF | |
833 | test_must_fail git for-each-ref --format="%(describe:baz)" \ | |
834 | refs/heads/master 2>actual && | |
835 | test_cmp expect actual && | |
836 | ||
837 | # The bad arg is in the middle of the option string | |
838 | # passed to the describe atom | |
839 | cat >expect <<-\EOF && | |
840 | fatal: unrecognized %(describe) argument: qux=1,abbrev=14 | |
841 | EOF | |
842 | test_must_fail git for-each-ref \ | |
843 | --format="%(describe:tags,qux=1,abbrev=14)" \ | |
844 | ref/heads/master 2>actual && | |
845 | test_cmp expect actual | |
846 | ) | |
847 | ' | |
848 | ||
7d66f21a | 849 | cat >expected <<\EOF |
8f19c9fd JS |
850 | heads/main |
851 | tags/main | |
7d66f21a BW |
852 | EOF |
853 | ||
2bb98169 BW |
854 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
855 | git config --bool core.warnambiguousrefs true && | |
7d66f21a BW |
856 | git checkout -b newtag && |
857 | echo "Using $datestamp" > one && | |
858 | git add one && | |
859 | git commit -m "Branch" && | |
860 | setdate_and_increment && | |
8f19c9fd JS |
861 | git tag -m "Tagging at $datestamp" main && |
862 | git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual && | |
7d66f21a BW |
863 | test_cmp expected actual |
864 | ' | |
865 | ||
2bb98169 | 866 | cat >expected <<\EOF |
8f19c9fd JS |
867 | heads/main |
868 | main | |
2bb98169 BW |
869 | EOF |
870 | ||
871 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' | |
872 | git config --bool core.warnambiguousrefs false && | |
8f19c9fd | 873 | git for-each-ref --format "%(refname:short)" refs/heads/main refs/tags/main >actual && |
2bb98169 BW |
874 | test_cmp expected actual |
875 | ' | |
876 | ||
7d66f21a BW |
877 | cat >expected <<\EOF |
878 | heads/ambiguous | |
879 | ambiguous | |
880 | EOF | |
881 | ||
2bb98169 | 882 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
8f19c9fd | 883 | git checkout main && |
7d66f21a BW |
884 | git tag ambiguous testtag^0 && |
885 | git branch ambiguous testtag^0 && | |
886 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && | |
887 | test_cmp expected actual | |
888 | ' | |
889 | ||
8b3f33ef MP |
890 | test_expect_success 'create tag without tagger' ' |
891 | git tag -a -m "Broken tag" taggerless && | |
892 | git tag -f taggerless $(git cat-file tag taggerless | | |
893 | sed -e "/^tagger /d" | | |
34959d80 | 894 | git hash-object --literally --stdin -w -t tag) |
8b3f33ef MP |
895 | ' |
896 | ||
897 | test_atom refs/tags/taggerless type 'commit' | |
898 | test_atom refs/tags/taggerless tag 'taggerless' | |
899 | test_atom refs/tags/taggerless tagger '' | |
900 | test_atom refs/tags/taggerless taggername '' | |
901 | test_atom refs/tags/taggerless taggeremail '' | |
b82445dc HV |
902 | test_atom refs/tags/taggerless taggeremail:trim '' |
903 | test_atom refs/tags/taggerless taggeremail:localpart '' | |
8b3f33ef MP |
904 | test_atom refs/tags/taggerless taggerdate '' |
905 | test_atom refs/tags/taggerless committer '' | |
906 | test_atom refs/tags/taggerless committername '' | |
907 | test_atom refs/tags/taggerless committeremail '' | |
b82445dc HV |
908 | test_atom refs/tags/taggerless committeremail:trim '' |
909 | test_atom refs/tags/taggerless committeremail:localpart '' | |
8b3f33ef MP |
910 | test_atom refs/tags/taggerless committerdate '' |
911 | test_atom refs/tags/taggerless subject 'Broken tag' | |
912 | ||
e276c26b JH |
913 | test_expect_success 'an unusual tag with an incomplete line' ' |
914 | ||
915 | git tag -m "bogo" bogo && | |
916 | bogo=$(git cat-file tag bogo) && | |
917 | bogo=$(printf "%s" "$bogo" | git mktag) && | |
918 | git tag -f bogo "$bogo" && | |
919 | git for-each-ref --format "%(body)" refs/tags/bogo | |
920 | ||
921 | ' | |
922 | ||
7140c22c JK |
923 | test_expect_success 'create tag with subject and body content' ' |
924 | cat >>msg <<-\EOF && | |
925 | the subject line | |
926 | ||
927 | first body line | |
928 | second body line | |
929 | EOF | |
930 | git tag -F msg subject-body | |
931 | ' | |
932 | test_atom refs/tags/subject-body subject 'the subject line' | |
905f0a4e | 933 | test_atom refs/tags/subject-body subject:sanitize 'the-subject-line' |
7140c22c JK |
934 | test_atom refs/tags/subject-body body 'first body line |
935 | second body line | |
936 | ' | |
937 | test_atom refs/tags/subject-body contents 'the subject line | |
938 | ||
939 | first body line | |
940 | second body line | |
941 | ' | |
942 | ||
7f6e275b JK |
943 | test_expect_success 'create tag with multiline subject' ' |
944 | cat >msg <<-\EOF && | |
945 | first subject line | |
946 | second subject line | |
947 | ||
948 | first body line | |
949 | second body line | |
950 | EOF | |
951 | git tag -F msg multiline | |
952 | ' | |
953 | test_atom refs/tags/multiline subject 'first subject line second subject line' | |
905f0a4e | 954 | test_atom refs/tags/multiline subject:sanitize 'first-subject-line-second-subject-line' |
e2b23972 | 955 | test_atom refs/tags/multiline contents:subject 'first subject line second subject line' |
7f6e275b JK |
956 | test_atom refs/tags/multiline body 'first body line |
957 | second body line | |
958 | ' | |
e2b23972 MG |
959 | test_atom refs/tags/multiline contents:body 'first body line |
960 | second body line | |
961 | ' | |
962 | test_atom refs/tags/multiline contents:signature '' | |
7f6e275b JK |
963 | test_atom refs/tags/multiline contents 'first subject line |
964 | second subject line | |
965 | ||
966 | first body line | |
967 | second body line | |
968 | ' | |
969 | ||
e2b23972 MG |
970 | test_expect_success GPG 'create signed tags' ' |
971 | git tag -s -m "" signed-empty && | |
972 | git tag -s -m "subject line" signed-short && | |
973 | cat >msg <<-\EOF && | |
974 | subject line | |
975 | ||
976 | body contents | |
977 | EOF | |
978 | git tag -s -F msg signed-long | |
979 | ' | |
980 | ||
981 | sig='-----BEGIN PGP SIGNATURE----- | |
982 | -----END PGP SIGNATURE----- | |
983 | ' | |
984 | ||
985 | PREREQ=GPG | |
986 | test_atom refs/tags/signed-empty subject '' | |
905f0a4e | 987 | test_atom refs/tags/signed-empty subject:sanitize '' |
e2b23972 MG |
988 | test_atom refs/tags/signed-empty contents:subject '' |
989 | test_atom refs/tags/signed-empty body "$sig" | |
990 | test_atom refs/tags/signed-empty contents:body '' | |
991 | test_atom refs/tags/signed-empty contents:signature "$sig" | |
992 | test_atom refs/tags/signed-empty contents "$sig" | |
993 | ||
bd0708c7 ZH |
994 | test_expect_success GPG 'basic atom: refs/tags/signed-empty raw' ' |
995 | git cat-file tag refs/tags/signed-empty >expected && | |
996 | git for-each-ref --format="%(raw)" refs/tags/signed-empty >actual && | |
997 | sanitize_pgp <expected >expected.clean && | |
998 | echo >>expected.clean && | |
999 | sanitize_pgp <actual >actual.clean && | |
1000 | test_cmp expected.clean actual.clean | |
1001 | ' | |
1002 | ||
e2b23972 | 1003 | test_atom refs/tags/signed-short subject 'subject line' |
905f0a4e | 1004 | test_atom refs/tags/signed-short subject:sanitize 'subject-line' |
e2b23972 MG |
1005 | test_atom refs/tags/signed-short contents:subject 'subject line' |
1006 | test_atom refs/tags/signed-short body "$sig" | |
1007 | test_atom refs/tags/signed-short contents:body '' | |
1008 | test_atom refs/tags/signed-short contents:signature "$sig" | |
1009 | test_atom refs/tags/signed-short contents "subject line | |
1010 | $sig" | |
1011 | ||
bd0708c7 ZH |
1012 | test_expect_success GPG 'basic atom: refs/tags/signed-short raw' ' |
1013 | git cat-file tag refs/tags/signed-short >expected && | |
1014 | git for-each-ref --format="%(raw)" refs/tags/signed-short >actual && | |
1015 | sanitize_pgp <expected >expected.clean && | |
1016 | echo >>expected.clean && | |
1017 | sanitize_pgp <actual >actual.clean && | |
1018 | test_cmp expected.clean actual.clean | |
1019 | ' | |
1020 | ||
e2b23972 | 1021 | test_atom refs/tags/signed-long subject 'subject line' |
905f0a4e | 1022 | test_atom refs/tags/signed-long subject:sanitize 'subject-line' |
e2b23972 MG |
1023 | test_atom refs/tags/signed-long contents:subject 'subject line' |
1024 | test_atom refs/tags/signed-long body "body contents | |
1025 | $sig" | |
1026 | test_atom refs/tags/signed-long contents:body 'body contents | |
1027 | ' | |
1028 | test_atom refs/tags/signed-long contents:signature "$sig" | |
1029 | test_atom refs/tags/signed-long contents "subject line | |
1030 | ||
1031 | body contents | |
1032 | $sig" | |
1033 | ||
bd0708c7 ZH |
1034 | test_expect_success GPG 'basic atom: refs/tags/signed-long raw' ' |
1035 | git cat-file tag refs/tags/signed-long >expected && | |
1036 | git for-each-ref --format="%(raw)" refs/tags/signed-long >actual && | |
1037 | sanitize_pgp <expected >expected.clean && | |
1038 | echo >>expected.clean && | |
1039 | sanitize_pgp <actual >actual.clean && | |
1040 | test_cmp expected.clean actual.clean | |
1041 | ' | |
1042 | ||
6e2ef8eb | 1043 | test_expect_success 'set up refs pointing to tree and blob' ' |
8f19c9fd JS |
1044 | git update-ref refs/mytrees/first refs/heads/main^{tree} && |
1045 | git update-ref refs/myblobs/first refs/heads/main:one | |
6e2ef8eb CC |
1046 | ' |
1047 | ||
1048 | test_atom refs/mytrees/first subject "" | |
1049 | test_atom refs/mytrees/first contents:subject "" | |
1050 | test_atom refs/mytrees/first body "" | |
1051 | test_atom refs/mytrees/first contents:body "" | |
1052 | test_atom refs/mytrees/first contents:signature "" | |
1053 | test_atom refs/mytrees/first contents "" | |
1054 | ||
bd0708c7 ZH |
1055 | test_expect_success 'basic atom: refs/mytrees/first raw' ' |
1056 | git cat-file tree refs/mytrees/first >expected && | |
1057 | echo >>expected && | |
1058 | git for-each-ref --format="%(raw)" refs/mytrees/first >actual && | |
1059 | test_cmp expected actual && | |
1060 | git cat-file -s refs/mytrees/first >expected && | |
1061 | git for-each-ref --format="%(raw:size)" refs/mytrees/first >actual && | |
1062 | test_cmp expected actual | |
1063 | ' | |
1064 | ||
6e2ef8eb CC |
1065 | test_atom refs/myblobs/first subject "" |
1066 | test_atom refs/myblobs/first contents:subject "" | |
1067 | test_atom refs/myblobs/first body "" | |
1068 | test_atom refs/myblobs/first contents:body "" | |
1069 | test_atom refs/myblobs/first contents:signature "" | |
1070 | test_atom refs/myblobs/first contents "" | |
1071 | ||
bd0708c7 ZH |
1072 | test_expect_success 'basic atom: refs/myblobs/first raw' ' |
1073 | git cat-file blob refs/myblobs/first >expected && | |
1074 | echo >>expected && | |
1075 | git for-each-ref --format="%(raw)" refs/myblobs/first >actual && | |
1076 | test_cmp expected actual && | |
1077 | git cat-file -s refs/myblobs/first >expected && | |
1078 | git for-each-ref --format="%(raw:size)" refs/myblobs/first >actual && | |
1079 | test_cmp expected actual | |
1080 | ' | |
1081 | ||
1082 | test_expect_success 'set up refs pointing to binary blob' ' | |
1083 | printf "a\0b\0c" >blob1 && | |
1084 | printf "a\0c\0b" >blob2 && | |
1085 | printf "\0a\0b\0c" >blob3 && | |
1086 | printf "abc" >blob4 && | |
1087 | printf "\0 \0 \0 " >blob5 && | |
1088 | printf "\0 \0a\0 " >blob6 && | |
1089 | printf " " >blob7 && | |
1090 | >blob8 && | |
1091 | obj=$(git hash-object -w blob1) && | |
1092 | git update-ref refs/myblobs/blob1 "$obj" && | |
1093 | obj=$(git hash-object -w blob2) && | |
1094 | git update-ref refs/myblobs/blob2 "$obj" && | |
1095 | obj=$(git hash-object -w blob3) && | |
1096 | git update-ref refs/myblobs/blob3 "$obj" && | |
1097 | obj=$(git hash-object -w blob4) && | |
1098 | git update-ref refs/myblobs/blob4 "$obj" && | |
1099 | obj=$(git hash-object -w blob5) && | |
1100 | git update-ref refs/myblobs/blob5 "$obj" && | |
1101 | obj=$(git hash-object -w blob6) && | |
1102 | git update-ref refs/myblobs/blob6 "$obj" && | |
1103 | obj=$(git hash-object -w blob7) && | |
1104 | git update-ref refs/myblobs/blob7 "$obj" && | |
1105 | obj=$(git hash-object -w blob8) && | |
1106 | git update-ref refs/myblobs/blob8 "$obj" | |
1107 | ' | |
1108 | ||
1109 | test_expect_success 'Verify sorts with raw' ' | |
1110 | cat >expected <<-EOF && | |
1111 | refs/myblobs/blob8 | |
1112 | refs/myblobs/blob5 | |
1113 | refs/myblobs/blob6 | |
1114 | refs/myblobs/blob3 | |
1115 | refs/myblobs/blob7 | |
1116 | refs/mytrees/first | |
1117 | refs/myblobs/first | |
1118 | refs/myblobs/blob1 | |
1119 | refs/myblobs/blob2 | |
1120 | refs/myblobs/blob4 | |
1121 | refs/heads/main | |
1122 | EOF | |
1123 | git for-each-ref --format="%(refname)" --sort=raw \ | |
1124 | refs/heads/main refs/myblobs/ refs/mytrees/first >actual && | |
1125 | test_cmp expected actual | |
1126 | ' | |
1127 | ||
1128 | test_expect_success 'Verify sorts with raw:size' ' | |
1129 | cat >expected <<-EOF && | |
1130 | refs/myblobs/blob8 | |
bd0708c7 | 1131 | refs/myblobs/blob7 |
bd0708c7 ZH |
1132 | refs/myblobs/blob4 |
1133 | refs/myblobs/blob1 | |
1134 | refs/myblobs/blob2 | |
1135 | refs/myblobs/blob3 | |
1136 | refs/myblobs/blob5 | |
1137 | refs/myblobs/blob6 | |
6d79cd84 | 1138 | refs/myblobs/first |
bd0708c7 | 1139 | refs/mytrees/first |
6d79cd84 | 1140 | refs/heads/main |
bd0708c7 ZH |
1141 | EOF |
1142 | git for-each-ref --format="%(refname)" --sort=raw:size \ | |
1143 | refs/heads/main refs/myblobs/ refs/mytrees/first >actual && | |
1144 | test_cmp expected actual | |
1145 | ' | |
1146 | ||
1147 | test_expect_success 'validate raw atom with %(if:equals)' ' | |
1148 | cat >expected <<-EOF && | |
1149 | not equals | |
1150 | not equals | |
1151 | not equals | |
1152 | not equals | |
1153 | not equals | |
1154 | not equals | |
1155 | refs/myblobs/blob4 | |
1156 | not equals | |
1157 | not equals | |
1158 | not equals | |
1159 | not equals | |
1160 | not equals | |
1161 | EOF | |
1162 | git for-each-ref --format="%(if:equals=abc)%(raw)%(then)%(refname)%(else)not equals%(end)" \ | |
1163 | refs/myblobs/ refs/heads/ >actual && | |
1164 | test_cmp expected actual | |
1165 | ' | |
1166 | ||
1167 | test_expect_success 'validate raw atom with %(if:notequals)' ' | |
1168 | cat >expected <<-EOF && | |
1169 | refs/heads/ambiguous | |
1170 | refs/heads/main | |
1171 | refs/heads/newtag | |
1172 | refs/myblobs/blob1 | |
1173 | refs/myblobs/blob2 | |
1174 | refs/myblobs/blob3 | |
1175 | equals | |
1176 | refs/myblobs/blob5 | |
1177 | refs/myblobs/blob6 | |
1178 | refs/myblobs/blob7 | |
1179 | refs/myblobs/blob8 | |
1180 | refs/myblobs/first | |
1181 | EOF | |
1182 | git for-each-ref --format="%(if:notequals=abc)%(raw)%(then)%(refname)%(else)equals%(end)" \ | |
1183 | refs/myblobs/ refs/heads/ >actual && | |
1184 | test_cmp expected actual | |
1185 | ' | |
1186 | ||
1187 | test_expect_success 'empty raw refs with %(if)' ' | |
1188 | cat >expected <<-EOF && | |
1189 | refs/myblobs/blob1 not empty | |
1190 | refs/myblobs/blob2 not empty | |
1191 | refs/myblobs/blob3 not empty | |
1192 | refs/myblobs/blob4 not empty | |
1193 | refs/myblobs/blob5 not empty | |
1194 | refs/myblobs/blob6 not empty | |
1195 | refs/myblobs/blob7 empty | |
1196 | refs/myblobs/blob8 empty | |
1197 | refs/myblobs/first not empty | |
1198 | EOF | |
1199 | git for-each-ref --format="%(refname) %(if)%(raw)%(then)not empty%(else)empty%(end)" \ | |
1200 | refs/myblobs/ >actual && | |
1201 | test_cmp expected actual | |
1202 | ' | |
1203 | ||
1204 | test_expect_success '%(raw) with --python must fail' ' | |
1205 | test_must_fail git for-each-ref --format="%(raw)" --python | |
1206 | ' | |
1207 | ||
1208 | test_expect_success '%(raw) with --tcl must fail' ' | |
1209 | test_must_fail git for-each-ref --format="%(raw)" --tcl | |
1210 | ' | |
1211 | ||
7121c4d4 ZH |
1212 | test_expect_success '%(raw) with --perl' ' |
1213 | git for-each-ref --format="\$name= %(raw); | |
1214 | print \"\$name\"" refs/myblobs/blob1 --perl | perl >actual && | |
1215 | cmp blob1 actual && | |
1216 | git for-each-ref --format="\$name= %(raw); | |
1217 | print \"\$name\"" refs/myblobs/blob3 --perl | perl >actual && | |
1218 | cmp blob3 actual && | |
1219 | git for-each-ref --format="\$name= %(raw); | |
1220 | print \"\$name\"" refs/myblobs/blob8 --perl | perl >actual && | |
1221 | cmp blob8 actual && | |
1222 | git for-each-ref --format="\$name= %(raw); | |
1223 | print \"\$name\"" refs/myblobs/first --perl | perl >actual && | |
1224 | cmp one actual && | |
1225 | git cat-file tree refs/mytrees/first > expected && | |
1226 | git for-each-ref --format="\$name= %(raw); | |
1227 | print \"\$name\"" refs/mytrees/first --perl | perl >actual && | |
1228 | cmp expected actual | |
bd0708c7 ZH |
1229 | ' |
1230 | ||
1231 | test_expect_success '%(raw) with --shell must fail' ' | |
1232 | test_must_fail git for-each-ref --format="%(raw)" --shell | |
1233 | ' | |
1234 | ||
1235 | test_expect_success '%(raw) with --shell and --sort=raw must fail' ' | |
1236 | test_must_fail git for-each-ref --format="%(raw)" --sort=raw --shell | |
1237 | ' | |
1238 | ||
1239 | test_expect_success '%(raw:size) with --shell' ' | |
efe47c83 | 1240 | git for-each-ref --format="%(raw:size)" | sed "s/^/$SQ/;s/$/$SQ/" >expect && |
bd0708c7 ZH |
1241 | git for-each-ref --format="%(raw:size)" --shell >actual && |
1242 | test_cmp expect actual | |
1243 | ' | |
1244 | ||
1245 | test_expect_success 'for-each-ref --format compare with cat-file --batch' ' | |
1246 | git rev-parse refs/mytrees/first | git cat-file --batch >expected && | |
1247 | git for-each-ref --format="%(objectname) %(objecttype) %(objectsize) | |
1248 | %(raw)" refs/mytrees/first >actual && | |
1249 | test_cmp expected actual | |
1250 | ' | |
1251 | ||
6d79cd84 KS |
1252 | test_expect_success 'verify sorts with contents:size' ' |
1253 | cat >expect <<-\EOF && | |
1254 | refs/heads/main | |
1255 | refs/heads/newtag | |
1256 | refs/heads/ambiguous | |
1257 | EOF | |
1258 | git for-each-ref --format="%(refname)" \ | |
1259 | --sort=contents:size refs/heads/ >actual && | |
1260 | test_cmp expect actual | |
1261 | ' | |
1262 | ||
7c5045fc JK |
1263 | test_expect_success 'set up multiple-sort tags' ' |
1264 | for when in 100000 200000 | |
1265 | do | |
1266 | for email in user1 user2 | |
1267 | do | |
1268 | for ref in ref1 ref2 | |
1269 | do | |
1270 | GIT_COMMITTER_DATE="@$when +0000" \ | |
1271 | GIT_COMMITTER_EMAIL="$email@example.com" \ | |
1272 | git tag -m "tag $ref-$when-$email" \ | |
1273 | multi-$ref-$when-$email || return 1 | |
1274 | done | |
1275 | done | |
1276 | done | |
1277 | ' | |
912072d5 | 1278 | |
3b51222c | 1279 | test_expect_success 'Verify sort with multiple keys' ' |
7c5045fc JK |
1280 | cat >expected <<-\EOF && |
1281 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
1282 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
1283 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
1284 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
1285 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
1286 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
1287 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
1288 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
1289 | EOF | |
1290 | git for-each-ref \ | |
1291 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
1292 | --sort=-refname \ | |
1293 | --sort=taggeremail \ | |
1294 | --sort=taggerdate \ | |
1295 | "refs/tags/multi-*" >actual && | |
912072d5 KK |
1296 | test_cmp expected actual |
1297 | ' | |
84679d47 | 1298 | |
7c5045fc JK |
1299 | test_expect_success 'equivalent sorts fall back on refname' ' |
1300 | cat >expected <<-\EOF && | |
1301 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
1302 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
1303 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
1304 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
1305 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
1306 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
1307 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
1308 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
1309 | EOF | |
1310 | git for-each-ref \ | |
1311 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
1312 | --sort=taggerdate \ | |
1313 | "refs/tags/multi-*" >actual && | |
1314 | test_cmp expected actual | |
1315 | ' | |
01f95825 | 1316 | |
98e7ab6d JH |
1317 | test_expect_success '--no-sort cancels the previous sort keys' ' |
1318 | cat >expected <<-\EOF && | |
1319 | 100000 <user1@example.com> refs/tags/multi-ref1-100000-user1 | |
1320 | 100000 <user2@example.com> refs/tags/multi-ref1-100000-user2 | |
1321 | 100000 <user1@example.com> refs/tags/multi-ref2-100000-user1 | |
1322 | 100000 <user2@example.com> refs/tags/multi-ref2-100000-user2 | |
1323 | 200000 <user1@example.com> refs/tags/multi-ref1-200000-user1 | |
1324 | 200000 <user2@example.com> refs/tags/multi-ref1-200000-user2 | |
1325 | 200000 <user1@example.com> refs/tags/multi-ref2-200000-user1 | |
1326 | 200000 <user2@example.com> refs/tags/multi-ref2-200000-user2 | |
1327 | EOF | |
1328 | git for-each-ref \ | |
1329 | --format="%(taggerdate:unix) %(taggeremail) %(refname)" \ | |
1330 | --sort=-refname \ | |
1331 | --sort=taggeremail \ | |
1332 | --no-sort \ | |
1333 | --sort=taggerdate \ | |
1334 | "refs/tags/multi-*" >actual && | |
1335 | test_cmp expected actual | |
1336 | ' | |
1337 | ||
56d26ade VD |
1338 | test_expect_success '--no-sort without subsequent --sort prints expected refs' ' |
1339 | cat >expected <<-\EOF && | |
1340 | refs/tags/multi-ref1-100000-user1 | |
1341 | refs/tags/multi-ref1-100000-user2 | |
1342 | refs/tags/multi-ref1-200000-user1 | |
1343 | refs/tags/multi-ref1-200000-user2 | |
1344 | refs/tags/multi-ref2-100000-user1 | |
1345 | refs/tags/multi-ref2-100000-user2 | |
1346 | refs/tags/multi-ref2-200000-user1 | |
1347 | refs/tags/multi-ref2-200000-user2 | |
1348 | EOF | |
1349 | ||
1350 | # Sort the results with `sort` for a consistent comparison against | |
1351 | # expected | |
1352 | git for-each-ref \ | |
1353 | --format="%(refname)" \ | |
1354 | --no-sort \ | |
1355 | "refs/tags/multi-*" | sort >actual && | |
1356 | test_cmp expected actual | |
1357 | ' | |
1358 | ||
46176d77 VD |
1359 | test_expect_success 'set up custom date sorting' ' |
1360 | # Dates: | |
1361 | # - Wed Feb 07 2024 21:34:20 +0000 | |
1362 | # - Tue Dec 14 1999 00:05:22 +0000 | |
1363 | # - Fri Jun 04 2021 11:26:51 +0000 | |
1364 | # - Mon Jan 22 2007 16:44:01 GMT+0000 | |
1365 | i=1 && | |
1366 | for when in 1707341660 945129922 1622806011 1169484241 | |
1367 | do | |
1368 | GIT_COMMITTER_DATE="@$when +0000" \ | |
1369 | GIT_COMMITTER_EMAIL="user@example.com" \ | |
1370 | git tag -m "tag $when" custom-dates-$i && | |
1371 | i=$(($i+1)) || return 1 | |
1372 | done | |
1373 | ' | |
1374 | ||
1375 | test_expect_success 'sort by date defaults to full timestamp' ' | |
1376 | cat >expected <<-\EOF && | |
1377 | 945129922 refs/tags/custom-dates-2 | |
1378 | 1169484241 refs/tags/custom-dates-4 | |
1379 | 1622806011 refs/tags/custom-dates-3 | |
1380 | 1707341660 refs/tags/custom-dates-1 | |
1381 | EOF | |
1382 | ||
1383 | git for-each-ref \ | |
1384 | --format="%(creatordate:unix) %(refname)" \ | |
1385 | --sort=creatordate \ | |
1386 | "refs/tags/custom-dates-*" >actual && | |
1387 | test_cmp expected actual | |
1388 | ' | |
1389 | ||
1390 | test_expect_success 'sort by custom date format' ' | |
1391 | cat >expected <<-\EOF && | |
1392 | 00:05:22 refs/tags/custom-dates-2 | |
1393 | 11:26:51 refs/tags/custom-dates-3 | |
1394 | 16:44:01 refs/tags/custom-dates-4 | |
1395 | 21:34:20 refs/tags/custom-dates-1 | |
1396 | EOF | |
1397 | ||
1398 | git for-each-ref \ | |
1399 | --format="%(creatordate:format:%H:%M:%S) %(refname)" \ | |
1400 | --sort="creatordate:format:%H:%M:%S" \ | |
1401 | "refs/tags/custom-dates-*" >actual && | |
1402 | test_cmp expected actual | |
1403 | ' | |
1404 | ||
84679d47 | 1405 | test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' |
8f19c9fd | 1406 | test_when_finished "git checkout main" && |
84679d47 JH |
1407 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
1408 | sed -e "s/^\* / /" actual >expect && | |
f0252ca2 | 1409 | git checkout --orphan orphaned-branch && |
84679d47 JH |
1410 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && |
1411 | test_cmp expect actual | |
1412 | ' | |
1413 | ||
b1d31c89 JK |
1414 | cat >trailers <<EOF |
1415 | Reviewed-by: A U Thor <author@example.com> | |
1416 | Signed-off-by: A U Thor <author@example.com> | |
624b44d3 TB |
1417 | [ v2 updated patch description ] |
1418 | Acked-by: A U Thor | |
1419 | <author@example.com> | |
b1d31c89 JK |
1420 | EOF |
1421 | ||
67a20a00 TB |
1422 | unfold () { |
1423 | perl -0pe 's/\n\s+/ /g' | |
1424 | } | |
624b44d3 TB |
1425 | |
1426 | test_expect_success 'set up trailers for next test' ' | |
b1d31c89 JK |
1427 | echo "Some contents" > two && |
1428 | git add two && | |
624b44d3 | 1429 | git commit -F - <<-EOF |
b1d31c89 JK |
1430 | trailers: this commit message has trailers |
1431 | ||
1432 | Some message contents | |
1433 | ||
1434 | $(cat trailers) | |
1435 | EOF | |
624b44d3 TB |
1436 | ' |
1437 | ||
727331dc HV |
1438 | test_trailer_option () { |
1439 | title=$1 option=$2 | |
1440 | cat >expect | |
1441 | test_expect_success "$title" ' | |
1442 | git for-each-ref --format="%($option)" refs/heads/main >actual && | |
1443 | test_cmp expect actual && | |
1444 | git for-each-ref --format="%(contents:$option)" refs/heads/main >actual && | |
1445 | test_cmp expect actual | |
1446 | ' | |
1447 | } | |
67a20a00 | 1448 | |
727331dc HV |
1449 | test_trailer_option '%(trailers:unfold) unfolds trailers' \ |
1450 | 'trailers:unfold' <<-EOF | |
1451 | $(unfold <trailers) | |
67a20a00 | 1452 | |
727331dc | 1453 | EOF |
7a5edbdb | 1454 | |
727331dc HV |
1455 | test_trailer_option '%(trailers:only) shows only "key: value" trailers' \ |
1456 | 'trailers:only' <<-EOF | |
1457 | $(grep -v patch.description <trailers) | |
1458 | ||
1459 | EOF | |
1460 | ||
ee82a487 HV |
1461 | test_trailer_option '%(trailers:only=no,only=true) shows only "key: value" trailers' \ |
1462 | 'trailers:only=no,only=true' <<-EOF | |
1463 | $(grep -v patch.description <trailers) | |
1464 | ||
1465 | EOF | |
1466 | ||
1467 | test_trailer_option '%(trailers:only=yes) shows only "key: value" trailers' \ | |
1468 | 'trailers:only=yes' <<-EOF | |
1469 | $(grep -v patch.description <trailers) | |
1470 | ||
1471 | EOF | |
1472 | ||
1473 | test_trailer_option '%(trailers:only=no) shows all trailers' \ | |
1474 | 'trailers:only=no' <<-EOF | |
1475 | $(cat trailers) | |
1476 | ||
1477 | EOF | |
1478 | ||
727331dc HV |
1479 | test_trailer_option '%(trailers:only) and %(trailers:unfold) work together' \ |
1480 | 'trailers:only,unfold' <<-EOF | |
1481 | $(grep -v patch.description <trailers | unfold) | |
1482 | ||
1483 | EOF | |
1484 | ||
1485 | test_trailer_option '%(trailers:unfold) and %(trailers:only) work together' \ | |
1486 | 'trailers:unfold,only' <<-EOF | |
1487 | $(grep -v patch.description <trailers | unfold) | |
1488 | ||
1489 | EOF | |
1490 | ||
ee82a487 HV |
1491 | test_trailer_option '%(trailers:key=foo) shows that trailer' \ |
1492 | 'trailers:key=Signed-off-by' <<-EOF | |
1493 | Signed-off-by: A U Thor <author@example.com> | |
1494 | ||
1495 | EOF | |
1496 | ||
1497 | test_trailer_option '%(trailers:key=foo) is case insensitive' \ | |
1498 | 'trailers:key=SiGned-oFf-bY' <<-EOF | |
1499 | Signed-off-by: A U Thor <author@example.com> | |
1500 | ||
1501 | EOF | |
1502 | ||
1503 | test_trailer_option '%(trailers:key=foo:) trailing colon also works' \ | |
1504 | 'trailers:key=Signed-off-by:' <<-EOF | |
1505 | Signed-off-by: A U Thor <author@example.com> | |
1506 | ||
1507 | EOF | |
1508 | ||
1509 | test_trailer_option '%(trailers:key=foo) multiple keys' \ | |
1510 | 'trailers:key=Reviewed-by:,key=Signed-off-by' <<-EOF | |
1511 | Reviewed-by: A U Thor <author@example.com> | |
1512 | Signed-off-by: A U Thor <author@example.com> | |
1513 | ||
1514 | EOF | |
1515 | ||
1516 | test_trailer_option '%(trailers:key=nonexistent) becomes empty' \ | |
1517 | 'trailers:key=Shined-off-by:' <<-EOF | |
1518 | ||
1519 | EOF | |
1520 | ||
1521 | test_trailer_option '%(trailers:key=foo) handles multiple lines even if folded' \ | |
1522 | 'trailers:key=Acked-by' <<-EOF | |
1523 | $(grep -v patch.description <trailers | grep -v Signed-off-by | grep -v Reviewed-by) | |
1524 | ||
1525 | EOF | |
1526 | ||
1527 | test_trailer_option '%(trailers:key=foo,unfold) properly unfolds' \ | |
1528 | 'trailers:key=Signed-Off-by,unfold' <<-EOF | |
1529 | $(unfold <trailers | grep Signed-off-by) | |
1530 | ||
1531 | EOF | |
1532 | ||
1533 | test_trailer_option '%(trailers:key=foo,only=no) also includes nontrailer lines' \ | |
1534 | 'trailers:key=Signed-off-by,only=no' <<-EOF | |
1535 | Signed-off-by: A U Thor <author@example.com> | |
1536 | $(grep patch.description <trailers) | |
1537 | ||
1538 | EOF | |
1539 | ||
1540 | test_trailer_option '%(trailers:key=foo,valueonly) shows only value' \ | |
1541 | 'trailers:key=Signed-off-by,valueonly' <<-EOF | |
1542 | A U Thor <author@example.com> | |
1543 | ||
1544 | EOF | |
1545 | ||
1546 | test_trailer_option '%(trailers:separator) changes separator' \ | |
1547 | 'trailers:separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF | |
1548 | Reviewed-by: A U Thor <author@example.com>,Signed-off-by: A U Thor <author@example.com> | |
1549 | EOF | |
1550 | ||
1551 | test_trailer_option '%(trailers:key_value_separator) changes key-value separator' \ | |
1552 | 'trailers:key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF | |
1553 | Reviewed-by,A U Thor <author@example.com> | |
1554 | Signed-off-by,A U Thor <author@example.com> | |
1555 | ||
1556 | EOF | |
1557 | ||
1558 | test_trailer_option '%(trailers:separator,key_value_separator) changes both separators' \ | |
1559 | 'trailers:separator=%x2C,key_value_separator=%x2C,key=Reviewed-by,key=Signed-off-by:' <<-EOF | |
1560 | Reviewed-by,A U Thor <author@example.com>,Signed-off-by,A U Thor <author@example.com> | |
1561 | EOF | |
1562 | ||
727331dc HV |
1563 | test_failing_trailer_option () { |
1564 | title=$1 option=$2 | |
1565 | cat >expect | |
1566 | test_expect_success "$title" ' | |
1567 | # error message cannot be checked under i18n | |
1568 | test_must_fail git for-each-ref --format="%($option)" refs/heads/main 2>actual && | |
feeb03bc | 1569 | test_cmp expect actual && |
727331dc | 1570 | test_must_fail git for-each-ref --format="%(contents:$option)" refs/heads/main 2>actual && |
feeb03bc | 1571 | test_cmp expect actual |
727331dc HV |
1572 | ' |
1573 | } | |
1574 | ||
1575 | test_failing_trailer_option '%(trailers) rejects unknown trailers arguments' \ | |
1576 | 'trailers:unsupported' <<-\EOF | |
67a20a00 TB |
1577 | fatal: unknown %(trailers) argument: unsupported |
1578 | EOF | |
67a20a00 | 1579 | |
ee82a487 HV |
1580 | test_failing_trailer_option '%(trailers:key) without value is error' \ |
1581 | 'trailers:key' <<-\EOF | |
1582 | fatal: expected %(trailers:key=<value>) | |
1583 | EOF | |
1584 | ||
2c22e102 | 1585 | test_expect_success 'if arguments, %(contents:trailers) shows error if colon is missing' ' |
7a5edbdb | 1586 | cat >expect <<-EOF && |
2c22e102 | 1587 | fatal: unrecognized %(contents) argument: trailersonly |
7a5edbdb | 1588 | EOF |
2c22e102 | 1589 | test_must_fail git for-each-ref --format="%(contents:trailersonly)" 2>actual && |
feeb03bc | 1590 | test_cmp expect actual |
7a5edbdb TB |
1591 | ' |
1592 | ||
624b44d3 | 1593 | test_expect_success 'basic atom: head contents:trailers' ' |
8f19c9fd | 1594 | git for-each-ref --format="%(contents:trailers)" refs/heads/main >actual && |
b1d31c89 JK |
1595 | sanitize_pgp <actual >actual.clean && |
1596 | # git for-each-ref ends with a blank line | |
1597 | cat >expect <<-EOF && | |
1598 | $(cat trailers) | |
1599 | ||
1600 | EOF | |
1601 | test_cmp expect actual.clean | |
1602 | ' | |
1603 | ||
b9dee075 ZH |
1604 | test_expect_success 'basic atom: rest must fail' ' |
1605 | test_must_fail git for-each-ref --format="%(rest)" refs/heads/main | |
1606 | ' | |
1607 | ||
a33d0fae JK |
1608 | test_expect_success 'HEAD atom does not take arguments' ' |
1609 | test_must_fail git for-each-ref --format="%(HEAD:foo)" 2>err && | |
1610 | echo "fatal: %(HEAD) does not take arguments" >expect && | |
1611 | test_cmp expect err | |
1612 | ' | |
1613 | ||
dda4fc1a JK |
1614 | test_expect_success 'subject atom rejects unknown arguments' ' |
1615 | test_must_fail git for-each-ref --format="%(subject:foo)" 2>err && | |
1616 | echo "fatal: unrecognized %(subject) argument: foo" >expect && | |
1617 | test_cmp expect err | |
1618 | ' | |
1619 | ||
1955ef10 JK |
1620 | test_expect_success 'refname atom rejects unknown arguments' ' |
1621 | test_must_fail git for-each-ref --format="%(refname:foo)" 2>err && | |
1622 | echo "fatal: unrecognized %(refname) argument: foo" >expect && | |
1623 | test_cmp expect err | |
1624 | ' | |
1625 | ||
e5fba5d5 JK |
1626 | test_expect_success 'trailer parsing not fooled by --- line' ' |
1627 | git commit --allow-empty -F - <<-\EOF && | |
1628 | this is the subject | |
1629 | ||
1630 | This is the body. The message has a "---" line which would confuse a | |
1631 | message+patch parser. But here we know we have only a commit message, | |
1632 | so we get it right. | |
1633 | ||
1634 | trailer: wrong | |
1635 | --- | |
1636 | This is more body. | |
1637 | ||
1638 | trailer: right | |
1639 | EOF | |
1640 | ||
1641 | { | |
1642 | echo "trailer: right" && | |
1643 | echo | |
1644 | } >expect && | |
8f19c9fd | 1645 | git for-each-ref --format="%(trailers)" refs/heads/main >actual && |
e5fba5d5 JK |
1646 | test_cmp expect actual |
1647 | ' | |
1648 | ||
01f95825 | 1649 | test_expect_success 'Add symbolic ref for the following tests' ' |
8f19c9fd | 1650 | git symbolic-ref refs/heads/sym refs/heads/main |
01f95825 KN |
1651 | ' |
1652 | ||
1653 | cat >expected <<EOF | |
8f19c9fd | 1654 | refs/heads/main |
01f95825 KN |
1655 | EOF |
1656 | ||
1657 | test_expect_success 'Verify usage of %(symref) atom' ' | |
1658 | git for-each-ref --format="%(symref)" refs/heads/sym >actual && | |
1659 | test_cmp expected actual | |
1660 | ' | |
1661 | ||
1662 | cat >expected <<EOF | |
8f19c9fd | 1663 | heads/main |
01f95825 KN |
1664 | EOF |
1665 | ||
1666 | test_expect_success 'Verify usage of %(symref:short) atom' ' | |
1667 | git for-each-ref --format="%(symref:short)" refs/heads/sym >actual && | |
1668 | test_cmp expected actual | |
1669 | ' | |
1670 | ||
a7984101 | 1671 | cat >expected <<EOF |
8f19c9fd JS |
1672 | main |
1673 | heads/main | |
a7984101 KN |
1674 | EOF |
1675 | ||
17938f17 KN |
1676 | test_expect_success 'Verify usage of %(symref:lstrip) atom' ' |
1677 | git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual && | |
1a0ca5e3 | 1678 | git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual && |
44a6b6ce JH |
1679 | test_cmp expected actual && |
1680 | ||
1681 | git for-each-ref --format="%(symref:strip=2)" refs/heads/sym > actual && | |
1682 | git for-each-ref --format="%(symref:strip=-2)" refs/heads/sym >> actual && | |
a7984101 KN |
1683 | test_cmp expected actual |
1684 | ' | |
1685 | ||
1a34728e KN |
1686 | cat >expected <<EOF |
1687 | refs | |
1688 | refs/heads | |
1689 | EOF | |
1690 | ||
1691 | test_expect_success 'Verify usage of %(symref:rstrip) atom' ' | |
1692 | git for-each-ref --format="%(symref:rstrip=2)" refs/heads/sym > actual && | |
1693 | git for-each-ref --format="%(symref:rstrip=-2)" refs/heads/sym >> actual && | |
1694 | test_cmp expected actual | |
1695 | ' | |
1696 | ||
1b586867 JS |
1697 | test_expect_success ':remotename and :remoteref' ' |
1698 | git init remote-tests && | |
1699 | ( | |
1700 | cd remote-tests && | |
1701 | test_commit initial && | |
8f19c9fd | 1702 | git branch -M main && |
1b586867 | 1703 | git remote add from fifth.coffee:blub && |
8f19c9fd JS |
1704 | git config branch.main.remote from && |
1705 | git config branch.main.merge refs/heads/stable && | |
1b586867 JS |
1706 | git remote add to southridge.audio:repo && |
1707 | git config remote.to.push "refs/heads/*:refs/heads/pushed/*" && | |
8f19c9fd | 1708 | git config branch.main.pushRemote to && |
1b586867 JS |
1709 | for pair in "%(upstream)=refs/remotes/from/stable" \ |
1710 | "%(upstream:remotename)=from" \ | |
1711 | "%(upstream:remoteref)=refs/heads/stable" \ | |
8f19c9fd | 1712 | "%(push)=refs/remotes/to/pushed/main" \ |
1b586867 | 1713 | "%(push:remotename)=to" \ |
8f19c9fd | 1714 | "%(push:remoteref)=refs/heads/pushed/main" |
1b586867 JS |
1715 | do |
1716 | echo "${pair#*=}" >expect && | |
1717 | git for-each-ref --format="${pair%=*}" \ | |
8f19c9fd | 1718 | refs/heads/main >actual && |
0c51d6b4 | 1719 | test_cmp expect actual || exit 1 |
1b586867 JS |
1720 | done && |
1721 | git branch push-simple && | |
1722 | git config branch.push-simple.pushRemote from && | |
1723 | actual="$(git for-each-ref \ | |
1724 | --format="%(push:remotename),%(push:remoteref)" \ | |
1725 | refs/heads/push-simple)" && | |
1726 | test from, = "$actual" | |
1727 | ) | |
1728 | ' | |
1729 | ||
e674eb25 | 1730 | test_expect_success 'for-each-ref --ignore-case ignores case' ' |
8f19c9fd | 1731 | git for-each-ref --format="%(refname)" refs/heads/MAIN >actual && |
d3c6751b | 1732 | test_must_be_empty actual && |
ee0f3e22 | 1733 | |
8f19c9fd | 1734 | echo refs/heads/main >expect && |
ee0f3e22 | 1735 | git for-each-ref --format="%(refname)" --ignore-case \ |
8f19c9fd | 1736 | refs/heads/MAIN >actual && |
ee0f3e22 JK |
1737 | test_cmp expect actual |
1738 | ' | |
1739 | ||
aabfdc95 ØW |
1740 | test_expect_success 'for-each-ref --omit-empty works' ' |
1741 | git for-each-ref --format="%(refname)" >actual && | |
1742 | test_line_count -gt 1 actual && | |
1743 | git for-each-ref --format="%(if:equals=refs/heads/main)%(refname)%(then)%(refname)%(end)" --omit-empty >actual && | |
1744 | echo refs/heads/main >expect && | |
1745 | test_cmp expect actual | |
1746 | ' | |
1747 | ||
76f9e569 JK |
1748 | test_expect_success 'for-each-ref --ignore-case works on multiple sort keys' ' |
1749 | # name refs numerically to avoid case-insensitive filesystem conflicts | |
1750 | nr=0 && | |
1751 | for email in a A b B | |
1752 | do | |
1753 | for subject in a A b B | |
1754 | do | |
1755 | GIT_COMMITTER_EMAIL="$email@example.com" \ | |
1756 | git tag -m "tag $subject" icase-$(printf %02d $nr) && | |
1757 | nr=$((nr+1))|| | |
1758 | return 1 | |
1759 | done | |
1760 | done && | |
1761 | git for-each-ref --ignore-case \ | |
1762 | --format="%(taggeremail) %(subject) %(refname)" \ | |
1763 | --sort=refname \ | |
1764 | --sort=subject \ | |
1765 | --sort=taggeremail \ | |
1766 | refs/tags/icase-* >actual && | |
1767 | cat >expect <<-\EOF && | |
1768 | <a@example.com> tag a refs/tags/icase-00 | |
1769 | <a@example.com> tag A refs/tags/icase-01 | |
1770 | <A@example.com> tag a refs/tags/icase-04 | |
1771 | <A@example.com> tag A refs/tags/icase-05 | |
1772 | <a@example.com> tag b refs/tags/icase-02 | |
1773 | <a@example.com> tag B refs/tags/icase-03 | |
1774 | <A@example.com> tag b refs/tags/icase-06 | |
1775 | <A@example.com> tag B refs/tags/icase-07 | |
1776 | <b@example.com> tag a refs/tags/icase-08 | |
1777 | <b@example.com> tag A refs/tags/icase-09 | |
1778 | <B@example.com> tag a refs/tags/icase-12 | |
1779 | <B@example.com> tag A refs/tags/icase-13 | |
1780 | <b@example.com> tag b refs/tags/icase-10 | |
1781 | <b@example.com> tag B refs/tags/icase-11 | |
1782 | <B@example.com> tag b refs/tags/icase-14 | |
1783 | <B@example.com> tag B refs/tags/icase-15 | |
1784 | EOF | |
1785 | test_cmp expect actual | |
1786 | ' | |
1787 | ||
c6854508 JK |
1788 | test_expect_success 'for-each-ref reports broken tags' ' |
1789 | git tag -m "good tag" broken-tag-good HEAD && | |
1790 | git cat-file tag broken-tag-good >good && | |
1791 | sed s/commit/blob/ <good >bad && | |
1792 | bad=$(git hash-object -w -t tag bad) && | |
1793 | git update-ref refs/tags/broken-tag-bad $bad && | |
1794 | test_must_fail git for-each-ref --format="%(*objectname)" \ | |
1795 | refs/tags/broken-tag-* | |
1796 | ' | |
1797 | ||
b01e1c7e JK |
1798 | test_expect_success 'set up tag with signature and no blank lines' ' |
1799 | git tag -F - fake-sig-no-blanks <<-\EOF | |
1800 | this is the subject | |
1801 | -----BEGIN PGP SIGNATURE----- | |
1802 | not a real signature, but we just care about the | |
1803 | subject/body parsing. It is important here that | |
1804 | there are no blank lines in the signature. | |
1805 | -----END PGP SIGNATURE----- | |
1806 | EOF | |
1807 | ' | |
1808 | ||
1809 | test_atom refs/tags/fake-sig-no-blanks contents:subject 'this is the subject' | |
1810 | test_atom refs/tags/fake-sig-no-blanks contents:body '' | |
1811 | test_atom refs/tags/fake-sig-no-blanks contents:signature "$sig" | |
1812 | ||
8e1c5fcf JK |
1813 | test_expect_success 'set up tag with CRLF signature' ' |
1814 | append_cr <<-\EOF | | |
1815 | this is the subject | |
1816 | -----BEGIN PGP SIGNATURE----- | |
1817 | ||
1818 | not a real signature, but we just care about | |
1819 | the subject/body parsing. It is important here | |
1820 | that there is a blank line separating this | |
1821 | from the signature header. | |
1822 | -----END PGP SIGNATURE----- | |
1823 | EOF | |
1824 | git tag -F - --cleanup=verbatim fake-sig-crlf | |
1825 | ' | |
1826 | ||
1827 | test_atom refs/tags/fake-sig-crlf contents:subject 'this is the subject' | |
1828 | test_atom refs/tags/fake-sig-crlf contents:body '' | |
1829 | ||
1830 | # CRLF is retained in the signature, so we have to pass our expected value | |
1831 | # through append_cr. But test_atom requires a shell string, which means command | |
1832 | # substitution, and the shell will strip trailing newlines from the output of | |
1833 | # the substitution. Hack around it by adding and then removing a dummy line. | |
1834 | sig_crlf="$(printf "%s" "$sig" | append_cr; echo dummy)" | |
1835 | sig_crlf=${sig_crlf%dummy} | |
1836 | test_atom refs/tags/fake-sig-crlf contents:signature "$sig_crlf" | |
1837 | ||
b73dec55 DS |
1838 | test_expect_success 'git for-each-ref --stdin: empty' ' |
1839 | >in && | |
1840 | git for-each-ref --format="%(refname)" --stdin <in >actual && | |
1841 | git for-each-ref --format="%(refname)" >expect && | |
1842 | test_cmp expect actual | |
1843 | ' | |
1844 | ||
1845 | test_expect_success 'git for-each-ref --stdin: fails if extra args' ' | |
1846 | >in && | |
1847 | test_must_fail git for-each-ref --format="%(refname)" \ | |
1848 | --stdin refs/heads/extra <in 2>err && | |
1849 | grep "unknown arguments supplied with --stdin" err | |
1850 | ' | |
1851 | ||
1852 | test_expect_success 'git for-each-ref --stdin: matches' ' | |
1853 | cat >in <<-EOF && | |
1854 | refs/tags/multi* | |
1855 | refs/heads/amb* | |
1856 | EOF | |
1857 | ||
1858 | cat >expect <<-EOF && | |
1859 | refs/heads/ambiguous | |
1860 | refs/tags/multi-ref1-100000-user1 | |
1861 | refs/tags/multi-ref1-100000-user2 | |
1862 | refs/tags/multi-ref1-200000-user1 | |
1863 | refs/tags/multi-ref1-200000-user2 | |
1864 | refs/tags/multi-ref2-100000-user1 | |
1865 | refs/tags/multi-ref2-100000-user2 | |
1866 | refs/tags/multi-ref2-200000-user1 | |
1867 | refs/tags/multi-ref2-200000-user2 | |
1868 | refs/tags/multiline | |
1869 | EOF | |
1870 | ||
1871 | git for-each-ref --format="%(refname)" --stdin <in >actual && | |
1872 | test_cmp expect actual | |
1873 | ' | |
1874 | ||
b2c51b75 DS |
1875 | test_expect_success 'git for-each-ref with non-existing refs' ' |
1876 | cat >in <<-EOF && | |
1877 | refs/heads/this-ref-does-not-exist | |
1878 | refs/tags/bogus | |
1879 | EOF | |
1880 | ||
1881 | git for-each-ref --format="%(refname)" --stdin <in >actual && | |
1882 | test_must_be_empty actual && | |
1883 | ||
1884 | xargs git for-each-ref --format="%(refname)" <in >actual && | |
1885 | test_must_be_empty actual | |
1886 | ' | |
1887 | ||
188782ec VD |
1888 | test_expect_success 'git for-each-ref with nested tags' ' |
1889 | git tag -am "Normal tag" nested/base HEAD && | |
1890 | git tag -am "Nested tag" nested/nest1 refs/tags/nested/base && | |
1891 | git tag -am "Double nested tag" nested/nest2 refs/tags/nested/nest1 && | |
1892 | ||
1893 | head_oid="$(git rev-parse HEAD)" && | |
1894 | base_tag_oid="$(git rev-parse refs/tags/nested/base)" && | |
1895 | nest1_tag_oid="$(git rev-parse refs/tags/nested/nest1)" && | |
1896 | nest2_tag_oid="$(git rev-parse refs/tags/nested/nest2)" && | |
1897 | ||
1898 | cat >expect <<-EOF && | |
1899 | refs/tags/nested/base $base_tag_oid tag $head_oid commit | |
1900 | refs/tags/nested/nest1 $nest1_tag_oid tag $head_oid commit | |
1901 | refs/tags/nested/nest2 $nest2_tag_oid tag $head_oid commit | |
1902 | EOF | |
1903 | ||
1904 | git for-each-ref \ | |
1905 | --format="%(refname) %(objectname) %(objecttype) %(*objectname) %(*objecttype)" \ | |
1906 | refs/tags/nested/ >actual && | |
1907 | test_cmp expect actual | |
1908 | ' | |
1909 | ||
26c9c03f KS |
1910 | GRADE_FORMAT="%(signature:grade)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)" |
1911 | TRUSTLEVEL_FORMAT="%(signature:trustlevel)%0a%(signature:key)%0a%(signature:signer)%0a%(signature:fingerprint)%0a%(signature:primarykeyfingerprint)" | |
1912 | ||
1913 | test_expect_success GPG 'setup for signature atom using gpg' ' | |
1914 | git checkout -b signed && | |
1915 | ||
1916 | test_when_finished "test_unconfig commit.gpgSign" && | |
1917 | ||
1918 | echo "1" >file && | |
1919 | git add file && | |
1920 | test_tick && | |
1921 | git commit -S -m "file: 1" && | |
1922 | git tag first-signed && | |
1923 | ||
1924 | echo "2" >file && | |
1925 | test_tick && | |
1926 | git commit -a -m "file: 2" && | |
1927 | git tag second-unsigned && | |
1928 | ||
1929 | git config commit.gpgSign 1 && | |
1930 | echo "3" >file && | |
1931 | test_tick && | |
1932 | git commit -a --no-gpg-sign -m "file: 3" && | |
1933 | git tag third-unsigned && | |
1934 | ||
1935 | test_tick && | |
1936 | git rebase -f HEAD^^ && git tag second-signed HEAD^ && | |
1937 | git tag third-signed && | |
1938 | ||
1939 | echo "4" >file && | |
1940 | test_tick && | |
1941 | git commit -a -SB7227189 -m "file: 4" && | |
1942 | git tag fourth-signed && | |
1943 | ||
1944 | echo "5" >file && | |
1945 | test_tick && | |
1946 | git commit -a --no-gpg-sign -m "file: 5" && | |
1947 | git tag fifth-unsigned && | |
1948 | ||
1949 | echo "6" >file && | |
1950 | test_tick && | |
1951 | git commit -a --no-gpg-sign -m "file: 6" && | |
1952 | ||
1953 | test_tick && | |
1954 | git rebase -f HEAD^^ && | |
1955 | git tag fifth-signed HEAD^ && | |
1956 | git tag sixth-signed && | |
1957 | ||
1958 | echo "7" >file && | |
1959 | test_tick && | |
1960 | git commit -a --no-gpg-sign -m "file: 7" && | |
1961 | git tag seventh-unsigned | |
1962 | ' | |
1963 | ||
1964 | test_expect_success GPGSSH 'setup for signature atom using ssh' ' | |
1965 | test_when_finished "test_unconfig gpg.format user.signingkey" && | |
1966 | ||
1967 | test_config gpg.format ssh && | |
1968 | test_config user.signingkey "${GPGSSH_KEY_PRIMARY}" && | |
1969 | echo "8" >file && | |
1970 | test_tick && | |
065135fc RS |
1971 | git add file && |
1972 | git commit -S -m "file: 8" && | |
26c9c03f KS |
1973 | git tag eighth-signed-ssh |
1974 | ' | |
1975 | ||
1976 | test_expect_success GPG2 'bare signature atom' ' | |
d0fc552b | 1977 | git verify-commit first-signed 2>expect && |
26c9c03f KS |
1978 | echo >>expect && |
1979 | git for-each-ref refs/tags/first-signed \ | |
1980 | --format="%(signature)" >actual && | |
1981 | test_cmp expect actual | |
1982 | ' | |
1983 | ||
1984 | test_expect_success GPG 'show good signature with custom format' ' | |
1985 | git verify-commit first-signed && | |
1986 | cat >expect <<-\EOF && | |
1987 | G | |
1988 | 13B6F51ECDDE430D | |
1989 | C O Mitter <committer@example.com> | |
1990 | 73D758744BE721698EC54E8713B6F51ECDDE430D | |
1991 | 73D758744BE721698EC54E8713B6F51ECDDE430D | |
1992 | EOF | |
1993 | git for-each-ref refs/tags/first-signed \ | |
1994 | --format="$GRADE_FORMAT" >actual && | |
1995 | test_cmp expect actual | |
1996 | ' | |
1997 | test_expect_success GPGSSH 'show good signature with custom format | |
1998 | with ssh' ' | |
1999 | test_config gpg.ssh.allowedSignersFile "${GPGSSH_ALLOWED_SIGNERS}" && | |
2000 | FINGERPRINT=$(ssh-keygen -lf "${GPGSSH_KEY_PRIMARY}" | awk "{print \$2;}") && | |
2001 | cat >expect.tmpl <<-\EOF && | |
2002 | G | |
2003 | FINGERPRINT | |
2004 | principal with number 1 | |
2005 | FINGERPRINT | |
2006 | ||
2007 | EOF | |
2008 | sed "s|FINGERPRINT|$FINGERPRINT|g" expect.tmpl >expect && | |
2009 | git for-each-ref refs/tags/eighth-signed-ssh \ | |
2010 | --format="$GRADE_FORMAT" >actual && | |
2011 | test_cmp expect actual | |
2012 | ' | |
2013 | ||
2014 | test_expect_success GPG 'signature atom with grade option and bad signature' ' | |
2015 | git cat-file commit third-signed >raw && | |
2016 | sed -e "s/^file: 3/file: 3 forged/" raw >forged1 && | |
2017 | FORGED1=$(git hash-object -w -t commit forged1) && | |
2018 | git update-ref refs/tags/third-signed "$FORGED1" && | |
2019 | test_must_fail git verify-commit "$FORGED1" && | |
2020 | ||
2021 | cat >expect <<-\EOF && | |
2022 | B | |
2023 | 13B6F51ECDDE430D | |
2024 | C O Mitter <committer@example.com> | |
2025 | ||
2026 | ||
2027 | EOF | |
2028 | git for-each-ref refs/tags/third-signed \ | |
2029 | --format="$GRADE_FORMAT" >actual && | |
2030 | test_cmp expect actual | |
2031 | ' | |
2032 | ||
2033 | test_expect_success GPG 'show untrusted signature with custom format' ' | |
2034 | cat >expect <<-\EOF && | |
2035 | U | |
2036 | 65A0EEA02E30CAD7 | |
2037 | Eris Discordia <discord@example.net> | |
2038 | F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7 | |
2039 | D4BE22311AD3131E5EDA29A461092E85B7227189 | |
2040 | EOF | |
2041 | git for-each-ref refs/tags/fourth-signed \ | |
2042 | --format="$GRADE_FORMAT" >actual && | |
2043 | test_cmp expect actual | |
2044 | ' | |
2045 | ||
2046 | test_expect_success GPG 'show untrusted signature with undefined trust level' ' | |
2047 | cat >expect <<-\EOF && | |
2048 | undefined | |
2049 | 65A0EEA02E30CAD7 | |
2050 | Eris Discordia <discord@example.net> | |
2051 | F8364A59E07FFE9F4D63005A65A0EEA02E30CAD7 | |
2052 | D4BE22311AD3131E5EDA29A461092E85B7227189 | |
2053 | EOF | |
2054 | git for-each-ref refs/tags/fourth-signed \ | |
2055 | --format="$TRUSTLEVEL_FORMAT" >actual && | |
2056 | test_cmp expect actual | |
2057 | ' | |
2058 | ||
2059 | test_expect_success GPG 'show untrusted signature with ultimate trust level' ' | |
2060 | cat >expect <<-\EOF && | |
2061 | ultimate | |
2062 | 13B6F51ECDDE430D | |
2063 | C O Mitter <committer@example.com> | |
2064 | 73D758744BE721698EC54E8713B6F51ECDDE430D | |
2065 | 73D758744BE721698EC54E8713B6F51ECDDE430D | |
2066 | EOF | |
2067 | git for-each-ref refs/tags/sixth-signed \ | |
2068 | --format="$TRUSTLEVEL_FORMAT" >actual && | |
2069 | test_cmp expect actual | |
2070 | ' | |
2071 | ||
2072 | test_expect_success GPG 'show unknown signature with custom format' ' | |
2073 | cat >expect <<-\EOF && | |
2074 | E | |
2075 | 13B6F51ECDDE430D | |
2076 | ||
2077 | ||
2078 | ||
2079 | EOF | |
2080 | GNUPGHOME="$GNUPGHOME_NOT_USED" git for-each-ref \ | |
2081 | refs/tags/sixth-signed --format="$GRADE_FORMAT" >actual && | |
2082 | test_cmp expect actual | |
2083 | ' | |
2084 | ||
2085 | test_expect_success GPG 'show lack of signature with custom format' ' | |
2086 | cat >expect <<-\EOF && | |
2087 | N | |
2088 | ||
2089 | ||
2090 | ||
2091 | ||
2092 | EOF | |
2093 | git for-each-ref refs/tags/seventh-unsigned \ | |
2094 | --format="$GRADE_FORMAT" >actual && | |
2095 | test_cmp expect actual | |
2096 | ' | |
2097 | ||
96b2d4fa | 2098 | test_done |