]>
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 |
96b2d4fa | 10 | |
db7bae25 JK |
11 | # Mon Jul 3 23:18:43 2006 +0000 |
12 | datestamp=1151968723 | |
96b2d4fa AP |
13 | setdate_and_increment () { |
14 | GIT_COMMITTER_DATE="$datestamp +0200" | |
15 | datestamp=$(expr "$datestamp" + 1) | |
16 | GIT_AUTHOR_DATE="$datestamp +0200" | |
17 | datestamp=$(expr "$datestamp" + 1) | |
18 | export GIT_COMMITTER_DATE GIT_AUTHOR_DATE | |
19 | } | |
20 | ||
bc147968 | 21 | test_expect_success setup ' |
96b2d4fa AP |
22 | setdate_and_increment && |
23 | echo "Using $datestamp" > one && | |
24 | git add one && | |
25 | git commit -m "Initial" && | |
26 | setdate_and_increment && | |
bc147968 | 27 | git tag -a -m "Tagging at $datestamp" testtag && |
8cae19d9 JK |
28 | git update-ref refs/remotes/origin/master master && |
29 | git remote add origin nowhere && | |
30 | git config branch.master.remote origin && | |
29bc8850 JK |
31 | git config branch.master.merge refs/heads/master && |
32 | git remote add myfork elsewhere && | |
33 | git config remote.pushdefault myfork && | |
34 | git config push.default current | |
8cae19d9 JK |
35 | ' |
36 | ||
d2bf48d2 JK |
37 | test_atom() { |
38 | case "$1" in | |
39 | head) ref=refs/heads/master ;; | |
40 | tag) ref=refs/tags/testtag ;; | |
01f95825 | 41 | sym) ref=refs/heads/sym ;; |
7140c22c | 42 | *) ref=$1 ;; |
d2bf48d2 JK |
43 | esac |
44 | printf '%s\n' "$3" >expected | |
e2b23972 | 45 | test_expect_${4:-success} $PREREQ "basic atom: $1 $2" " |
d2bf48d2 | 46 | git for-each-ref --format='%($2)' $ref >actual && |
e2b23972 MG |
47 | sanitize_pgp <actual >actual.clean && |
48 | test_cmp expected actual.clean | |
d2bf48d2 JK |
49 | " |
50 | } | |
51 | ||
52 | test_atom head refname refs/heads/master | |
1d094db9 | 53 | test_atom head refname:short master |
17938f17 KN |
54 | test_atom head refname:lstrip=1 heads/master |
55 | test_atom head refname:lstrip=2 master | |
1a0ca5e3 KN |
56 | test_atom head refname:lstrip=-1 master |
57 | test_atom head refname:lstrip=-2 heads/master | |
8cae19d9 | 58 | test_atom head upstream refs/remotes/origin/master |
1d094db9 | 59 | test_atom head upstream:short origin/master |
17938f17 | 60 | test_atom head upstream:lstrip=2 origin/master |
1a0ca5e3 | 61 | test_atom head upstream:lstrip=-2 origin/master |
29bc8850 | 62 | test_atom head push refs/remotes/myfork/master |
1d094db9 | 63 | test_atom head push:short myfork/master |
17938f17 | 64 | test_atom head push:lstrip=1 remotes/myfork/master |
1a0ca5e3 | 65 | test_atom head push:lstrip=-1 master |
d2bf48d2 JK |
66 | test_atom head objecttype commit |
67 | test_atom head objectsize 171 | |
189a5467 | 68 | test_atom head objectname $(git rev-parse refs/heads/master) |
1d094db9 | 69 | test_atom head objectname:short $(git rev-parse --short refs/heads/master) |
42d0eb05 KN |
70 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) |
71 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) | |
189a5467 | 72 | test_atom head tree $(git rev-parse refs/heads/master^{tree}) |
d2bf48d2 JK |
73 | test_atom head parent '' |
74 | test_atom head numparent 0 | |
75 | test_atom head object '' | |
76 | test_atom head type '' | |
b74cf648 JK |
77 | test_atom head '*objectname' '' |
78 | test_atom head '*objecttype' '' | |
db7bae25 | 79 | test_atom head author 'A U Thor <author@example.com> 1151968724 +0200' |
d2bf48d2 JK |
80 | test_atom head authorname 'A U Thor' |
81 | test_atom head authoremail '<author@example.com>' | |
db7bae25 JK |
82 | test_atom head authordate 'Tue Jul 4 01:18:44 2006 +0200' |
83 | test_atom head committer 'C O Mitter <committer@example.com> 1151968723 +0200' | |
d2bf48d2 JK |
84 | test_atom head committername 'C O Mitter' |
85 | test_atom head committeremail '<committer@example.com>' | |
db7bae25 | 86 | test_atom head committerdate 'Tue Jul 4 01:18:43 2006 +0200' |
d2bf48d2 JK |
87 | test_atom head tag '' |
88 | test_atom head tagger '' | |
89 | test_atom head taggername '' | |
90 | test_atom head taggeremail '' | |
91 | test_atom head taggerdate '' | |
db7bae25 JK |
92 | test_atom head creator 'C O Mitter <committer@example.com> 1151968723 +0200' |
93 | test_atom head creatordate 'Tue Jul 4 01:18:43 2006 +0200' | |
d2bf48d2 | 94 | test_atom head subject 'Initial' |
e2b23972 | 95 | test_atom head contents:subject 'Initial' |
d2bf48d2 | 96 | test_atom head body '' |
e2b23972 MG |
97 | test_atom head contents:body '' |
98 | test_atom head contents:signature '' | |
d2bf48d2 JK |
99 | test_atom head contents 'Initial |
100 | ' | |
7a48b832 | 101 | test_atom head HEAD '*' |
d2bf48d2 JK |
102 | |
103 | test_atom tag refname refs/tags/testtag | |
1d094db9 | 104 | test_atom tag refname:short testtag |
8cae19d9 | 105 | test_atom tag upstream '' |
29bc8850 | 106 | test_atom tag push '' |
d2bf48d2 JK |
107 | test_atom tag objecttype tag |
108 | test_atom tag objectsize 154 | |
189a5467 | 109 | test_atom tag objectname $(git rev-parse refs/tags/testtag) |
1d094db9 | 110 | test_atom tag objectname:short $(git rev-parse --short refs/tags/testtag) |
42d0eb05 KN |
111 | test_atom head objectname:short=1 $(git rev-parse --short=1 refs/heads/master) |
112 | test_atom head objectname:short=10 $(git rev-parse --short=10 refs/heads/master) | |
d2bf48d2 JK |
113 | test_atom tag tree '' |
114 | test_atom tag parent '' | |
115 | test_atom tag numparent '' | |
189a5467 | 116 | test_atom tag object $(git rev-parse refs/tags/testtag^0) |
d2bf48d2 | 117 | test_atom tag type 'commit' |
db7bae25 | 118 | test_atom tag '*objectname' 'ea122842f48be4afb2d1fc6a4b96c05885ab7463' |
b74cf648 | 119 | test_atom tag '*objecttype' 'commit' |
d2bf48d2 JK |
120 | test_atom tag author '' |
121 | test_atom tag authorname '' | |
122 | test_atom tag authoremail '' | |
123 | test_atom tag authordate '' | |
124 | test_atom tag committer '' | |
125 | test_atom tag committername '' | |
126 | test_atom tag committeremail '' | |
127 | test_atom tag committerdate '' | |
128 | test_atom tag tag 'testtag' | |
db7bae25 | 129 | test_atom tag tagger 'C O Mitter <committer@example.com> 1151968725 +0200' |
d2bf48d2 JK |
130 | test_atom tag taggername 'C O Mitter' |
131 | test_atom tag taggeremail '<committer@example.com>' | |
db7bae25 JK |
132 | test_atom tag taggerdate 'Tue Jul 4 01:18:45 2006 +0200' |
133 | test_atom tag creator 'C O Mitter <committer@example.com> 1151968725 +0200' | |
134 | test_atom tag creatordate 'Tue Jul 4 01:18:45 2006 +0200' | |
135 | test_atom tag subject 'Tagging at 1151968727' | |
136 | test_atom tag contents:subject 'Tagging at 1151968727' | |
d2bf48d2 | 137 | test_atom tag body '' |
e2b23972 MG |
138 | test_atom tag contents:body '' |
139 | test_atom tag contents:signature '' | |
db7bae25 | 140 | test_atom tag contents 'Tagging at 1151968727 |
96b2d4fa | 141 | ' |
7a48b832 | 142 | test_atom tag HEAD ' ' |
96b2d4fa | 143 | |
41ac414e | 144 | test_expect_success 'Check invalid atoms names are errors' ' |
3604e7c5 | 145 | test_must_fail git for-each-ref --format="%(INVALID)" refs/heads |
96b2d4fa AP |
146 | ' |
147 | ||
148 | test_expect_success 'Check format specifiers are ignored in naming date atoms' ' | |
3604e7c5 NS |
149 | git for-each-ref --format="%(authordate)" refs/heads && |
150 | git for-each-ref --format="%(authordate:default) %(authordate)" refs/heads && | |
151 | git for-each-ref --format="%(authordate) %(authordate:default)" refs/heads && | |
152 | git for-each-ref --format="%(authordate:default) %(authordate:default)" refs/heads | |
96b2d4fa AP |
153 | ' |
154 | ||
155 | test_expect_success 'Check valid format specifiers for date fields' ' | |
3604e7c5 NS |
156 | git for-each-ref --format="%(authordate:default)" refs/heads && |
157 | git for-each-ref --format="%(authordate:relative)" refs/heads && | |
158 | git for-each-ref --format="%(authordate:short)" refs/heads && | |
159 | git for-each-ref --format="%(authordate:local)" refs/heads && | |
160 | git for-each-ref --format="%(authordate:iso8601)" refs/heads && | |
161 | git for-each-ref --format="%(authordate:rfc2822)" refs/heads | |
96b2d4fa AP |
162 | ' |
163 | ||
41ac414e | 164 | test_expect_success 'Check invalid format specifiers are errors' ' |
3604e7c5 | 165 | test_must_fail git for-each-ref --format="%(authordate:INVALID)" refs/heads |
96b2d4fa AP |
166 | ' |
167 | ||
42d0eb05 KN |
168 | test_expect_success 'arguments to %(objectname:short=) must be positive integers' ' |
169 | test_must_fail git for-each-ref --format="%(objectname:short=0)" && | |
170 | test_must_fail git for-each-ref --format="%(objectname:short=-1)" && | |
171 | test_must_fail git for-each-ref --format="%(objectname:short=foo)" | |
172 | ' | |
173 | ||
f95cecf4 JK |
174 | test_date () { |
175 | f=$1 && | |
176 | committer_date=$2 && | |
177 | author_date=$3 && | |
178 | tagger_date=$4 && | |
179 | cat >expected <<-EOF && | |
180 | 'refs/heads/master' '$committer_date' '$author_date' | |
181 | 'refs/tags/testtag' '$tagger_date' | |
182 | EOF | |
183 | ( | |
184 | git for-each-ref --shell \ | |
185 | --format="%(refname) %(committerdate${f:+:$f}) %(authordate${f:+:$f})" \ | |
186 | refs/heads && | |
187 | git for-each-ref --shell \ | |
188 | --format="%(refname) %(taggerdate${f:+:$f})" \ | |
189 | refs/tags | |
190 | ) >actual && | |
191 | test_cmp expected actual | |
192 | } | |
96b2d4fa AP |
193 | |
194 | test_expect_success 'Check unformatted date fields output' ' | |
f95cecf4 | 195 | test_date "" \ |
db7bae25 JK |
196 | "Tue Jul 4 01:18:43 2006 +0200" \ |
197 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
198 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
199 | ' |
200 | ||
201 | test_expect_success 'Check format "default" formatted date fields output' ' | |
f95cecf4 | 202 | test_date default \ |
db7bae25 JK |
203 | "Tue Jul 4 01:18:43 2006 +0200" \ |
204 | "Tue Jul 4 01:18:44 2006 +0200" \ | |
205 | "Tue Jul 4 01:18:45 2006 +0200" | |
96b2d4fa AP |
206 | ' |
207 | ||
99264e93 JK |
208 | test_expect_success 'Check format "default-local" date fields output' ' |
209 | 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 |
210 | ' |
211 | ||
212 | # Don't know how to do relative check because I can't know when this script | |
213 | # is going to be run and can't fake the current time to git, and hence can't | |
214 | # provide expected output. Instead, I'll just make sure that "relative" | |
215 | # doesn't exit in error | |
96b2d4fa AP |
216 | test_expect_success 'Check format "relative" date fields output' ' |
217 | f=relative && | |
218 | (git for-each-ref --shell --format="%(refname) %(committerdate:$f) %(authordate:$f)" refs/heads && | |
219 | git for-each-ref --shell --format="%(refname) %(taggerdate:$f)" refs/tags) >actual | |
220 | ' | |
221 | ||
99264e93 JK |
222 | # We just check that this is the same as "relative" for now. |
223 | test_expect_success 'Check format "relative-local" date fields output' ' | |
224 | test_date relative-local \ | |
225 | "$(git for-each-ref --format="%(committerdate:relative)" refs/heads)" \ | |
226 | "$(git for-each-ref --format="%(authordate:relative)" refs/heads)" \ | |
227 | "$(git for-each-ref --format="%(taggerdate:relative)" refs/tags)" | |
228 | ' | |
96b2d4fa AP |
229 | |
230 | test_expect_success 'Check format "short" date fields output' ' | |
db7bae25 | 231 | test_date short 2006-07-04 2006-07-04 2006-07-04 |
96b2d4fa AP |
232 | ' |
233 | ||
99264e93 JK |
234 | test_expect_success 'Check format "short-local" date fields output' ' |
235 | test_date short-local 2006-07-03 2006-07-03 2006-07-03 | |
236 | ' | |
96b2d4fa AP |
237 | |
238 | test_expect_success 'Check format "local" date fields output' ' | |
f95cecf4 | 239 | test_date local \ |
db7bae25 JK |
240 | "Mon Jul 3 23:18:43 2006" \ |
241 | "Mon Jul 3 23:18:44 2006" \ | |
242 | "Mon Jul 3 23:18:45 2006" | |
96b2d4fa AP |
243 | ' |
244 | ||
96b2d4fa | 245 | test_expect_success 'Check format "iso8601" date fields output' ' |
f95cecf4 | 246 | test_date iso8601 \ |
db7bae25 JK |
247 | "2006-07-04 01:18:43 +0200" \ |
248 | "2006-07-04 01:18:44 +0200" \ | |
249 | "2006-07-04 01:18:45 +0200" | |
96b2d4fa AP |
250 | ' |
251 | ||
99264e93 JK |
252 | test_expect_success 'Check format "iso8601-local" date fields output' ' |
253 | 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" | |
254 | ' | |
96b2d4fa AP |
255 | |
256 | test_expect_success 'Check format "rfc2822" date fields output' ' | |
f95cecf4 | 257 | test_date rfc2822 \ |
db7bae25 JK |
258 | "Tue, 4 Jul 2006 01:18:43 +0200" \ |
259 | "Tue, 4 Jul 2006 01:18:44 +0200" \ | |
260 | "Tue, 4 Jul 2006 01:18:45 +0200" | |
96b2d4fa AP |
261 | ' |
262 | ||
99264e93 JK |
263 | test_expect_success 'Check format "rfc2822-local" date fields output' ' |
264 | 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" | |
265 | ' | |
266 | ||
f3c1ba50 | 267 | test_expect_success 'Check format "raw" date fields output' ' |
db7bae25 | 268 | test_date raw "1151968723 +0200" "1151968724 +0200" "1151968725 +0200" |
f3c1ba50 JK |
269 | ' |
270 | ||
99264e93 JK |
271 | test_expect_success 'Check format "raw-local" date fields output' ' |
272 | test_date raw-local "1151968723 +0000" "1151968724 +0000" "1151968725 +0000" | |
96b2d4fa AP |
273 | ' |
274 | ||
aa1462cc | 275 | test_expect_success 'Check format of strftime date fields' ' |
db7bae25 | 276 | echo "my date is 2006-07-04" >expected && |
aa1462cc JK |
277 | git for-each-ref \ |
278 | --format="%(authordate:format:my date is %Y-%m-%d)" \ | |
279 | refs/heads >actual && | |
280 | test_cmp expected actual | |
281 | ' | |
282 | ||
99264e93 JK |
283 | test_expect_success 'Check format of strftime-local date fields' ' |
284 | echo "my date is 2006-07-03" >expected && | |
285 | git for-each-ref \ | |
286 | --format="%(authordate:format-local:my date is %Y-%m-%d)" \ | |
287 | refs/heads >actual && | |
288 | test_cmp expected actual | |
289 | ' | |
290 | ||
e4f031e3 JK |
291 | test_expect_success 'exercise strftime with odd fields' ' |
292 | echo >expected && | |
293 | git for-each-ref --format="%(authordate:format:)" refs/heads >actual && | |
294 | test_cmp expected actual && | |
295 | long="long format -- $_z40$_z40$_z40$_z40$_z40$_z40$_z40" && | |
296 | echo $long >expected && | |
297 | git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && | |
298 | test_cmp expected actual | |
299 | ' | |
300 | ||
c899a57c LH |
301 | cat >expected <<\EOF |
302 | refs/heads/master | |
8cae19d9 | 303 | refs/remotes/origin/master |
c899a57c LH |
304 | refs/tags/testtag |
305 | EOF | |
306 | ||
307 | test_expect_success 'Verify ascending sort' ' | |
3604e7c5 | 308 | git for-each-ref --format="%(refname)" --sort=refname >actual && |
3af82863 | 309 | test_cmp expected actual |
c899a57c LH |
310 | ' |
311 | ||
312 | ||
313 | cat >expected <<\EOF | |
314 | refs/tags/testtag | |
8cae19d9 | 315 | refs/remotes/origin/master |
c899a57c LH |
316 | refs/heads/master |
317 | EOF | |
318 | ||
319 | test_expect_success 'Verify descending sort' ' | |
3604e7c5 | 320 | git for-each-ref --format="%(refname)" --sort=-refname >actual && |
3af82863 | 321 | test_cmp expected actual |
c899a57c LH |
322 | ' |
323 | ||
c9ecf4f1 JS |
324 | cat >expected <<\EOF |
325 | 'refs/heads/master' | |
8cae19d9 | 326 | 'refs/remotes/origin/master' |
c9ecf4f1 JS |
327 | 'refs/tags/testtag' |
328 | EOF | |
329 | ||
330 | test_expect_success 'Quoting style: shell' ' | |
331 | git for-each-ref --shell --format="%(refname)" >actual && | |
3af82863 | 332 | test_cmp expected actual |
c9ecf4f1 JS |
333 | ' |
334 | ||
335 | test_expect_success 'Quoting style: perl' ' | |
336 | git for-each-ref --perl --format="%(refname)" >actual && | |
3af82863 | 337 | test_cmp expected actual |
c9ecf4f1 JS |
338 | ' |
339 | ||
340 | test_expect_success 'Quoting style: python' ' | |
341 | git for-each-ref --python --format="%(refname)" >actual && | |
3af82863 | 342 | test_cmp expected actual |
c9ecf4f1 JS |
343 | ' |
344 | ||
345 | cat >expected <<\EOF | |
346 | "refs/heads/master" | |
8cae19d9 | 347 | "refs/remotes/origin/master" |
c9ecf4f1 JS |
348 | "refs/tags/testtag" |
349 | EOF | |
350 | ||
351 | test_expect_success 'Quoting style: tcl' ' | |
352 | git for-each-ref --tcl --format="%(refname)" >actual && | |
3af82863 | 353 | test_cmp expected actual |
c9ecf4f1 JS |
354 | ' |
355 | ||
356 | for i in "--perl --shell" "-s --python" "--python --tcl" "--tcl --perl"; do | |
357 | test_expect_success "more than one quoting style: $i" " | |
358 | git for-each-ref $i 2>&1 | (read line && | |
359 | case \$line in | |
360 | \"error: more than one quoting style\"*) : happy;; | |
361 | *) false | |
362 | esac) | |
363 | " | |
364 | done | |
c899a57c | 365 | |
b28061ce RR |
366 | test_expect_success 'setup for upstream:track[short]' ' |
367 | test_commit two | |
368 | ' | |
369 | ||
1d094db9 JK |
370 | test_atom head upstream:track '[ahead 1]' |
371 | test_atom head upstream:trackshort '>' | |
7743fcca KN |
372 | test_atom head upstream:track,nobracket 'ahead 1' |
373 | test_atom head upstream:nobracket,track 'ahead 1' | |
1d094db9 JK |
374 | test_atom head push:track '[ahead 1]' |
375 | test_atom head push:trackshort '>' | |
b28061ce RR |
376 | |
377 | test_expect_success 'Check that :track[short] cannot be used with other atoms' ' | |
378 | test_must_fail git for-each-ref --format="%(refname:track)" 2>/dev/null && | |
379 | test_must_fail git for-each-ref --format="%(refname:trackshort)" 2>/dev/null | |
380 | ' | |
381 | ||
b6160d95 RKC |
382 | test_expect_success 'Check that :track[short] works when upstream is invalid' ' |
383 | cat >expected <<-\EOF && | |
ffd921d3 | 384 | [gone] |
b6160d95 RKC |
385 | |
386 | EOF | |
387 | test_when_finished "git config branch.master.merge refs/heads/master" && | |
388 | git config branch.master.merge refs/heads/does-not-exist && | |
389 | git for-each-ref \ | |
390 | --format="%(upstream:track)$LF%(upstream:trackshort)" \ | |
391 | refs/heads >actual && | |
392 | test_cmp expected actual | |
29bc8850 JK |
393 | ' |
394 | ||
7d66f21a BW |
395 | test_expect_success 'Check for invalid refname format' ' |
396 | test_must_fail git for-each-ref --format="%(refname:INVALID)" | |
397 | ' | |
398 | ||
fddb74c9 RR |
399 | get_color () |
400 | { | |
401 | git config --get-color no.such.slot "$1" | |
402 | } | |
403 | ||
404 | cat >expected <<EOF | |
405 | $(git rev-parse --short refs/heads/master) $(get_color green)master$(get_color reset) | |
406 | $(git rev-parse --short refs/remotes/origin/master) $(get_color green)origin/master$(get_color reset) | |
407 | $(git rev-parse --short refs/tags/testtag) $(get_color green)testtag$(get_color reset) | |
408 | $(git rev-parse --short refs/tags/two) $(get_color green)two$(get_color reset) | |
409 | EOF | |
410 | ||
411 | test_expect_success 'Check %(color:...) ' ' | |
db64eb65 | 412 | git for-each-ref --format="%(objectname:short) %(color:green)%(refname:short)" >actual && |
fddb74c9 RR |
413 | test_cmp expected actual |
414 | ' | |
415 | ||
7d66f21a BW |
416 | cat >expected <<\EOF |
417 | heads/master | |
2bb98169 | 418 | tags/master |
7d66f21a BW |
419 | EOF |
420 | ||
2bb98169 BW |
421 | test_expect_success 'Check ambiguous head and tag refs (strict)' ' |
422 | git config --bool core.warnambiguousrefs true && | |
7d66f21a BW |
423 | git checkout -b newtag && |
424 | echo "Using $datestamp" > one && | |
425 | git add one && | |
426 | git commit -m "Branch" && | |
427 | setdate_and_increment && | |
428 | git tag -m "Tagging at $datestamp" master && | |
429 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
430 | test_cmp expected actual | |
431 | ' | |
432 | ||
2bb98169 BW |
433 | cat >expected <<\EOF |
434 | heads/master | |
435 | master | |
436 | EOF | |
437 | ||
438 | test_expect_success 'Check ambiguous head and tag refs (loose)' ' | |
439 | git config --bool core.warnambiguousrefs false && | |
440 | git for-each-ref --format "%(refname:short)" refs/heads/master refs/tags/master >actual && | |
441 | test_cmp expected actual | |
442 | ' | |
443 | ||
7d66f21a BW |
444 | cat >expected <<\EOF |
445 | heads/ambiguous | |
446 | ambiguous | |
447 | EOF | |
448 | ||
2bb98169 | 449 | test_expect_success 'Check ambiguous head and tag refs II (loose)' ' |
7d66f21a BW |
450 | git checkout master && |
451 | git tag ambiguous testtag^0 && | |
452 | git branch ambiguous testtag^0 && | |
453 | git for-each-ref --format "%(refname:short)" refs/heads/ambiguous refs/tags/ambiguous >actual && | |
454 | test_cmp expected actual | |
455 | ' | |
456 | ||
e276c26b JH |
457 | test_expect_success 'an unusual tag with an incomplete line' ' |
458 | ||
459 | git tag -m "bogo" bogo && | |
460 | bogo=$(git cat-file tag bogo) && | |
461 | bogo=$(printf "%s" "$bogo" | git mktag) && | |
462 | git tag -f bogo "$bogo" && | |
463 | git for-each-ref --format "%(body)" refs/tags/bogo | |
464 | ||
465 | ' | |
466 | ||
7140c22c JK |
467 | test_expect_success 'create tag with subject and body content' ' |
468 | cat >>msg <<-\EOF && | |
469 | the subject line | |
470 | ||
471 | first body line | |
472 | second body line | |
473 | EOF | |
474 | git tag -F msg subject-body | |
475 | ' | |
476 | test_atom refs/tags/subject-body subject 'the subject line' | |
477 | test_atom refs/tags/subject-body body 'first body line | |
478 | second body line | |
479 | ' | |
480 | test_atom refs/tags/subject-body contents 'the subject line | |
481 | ||
482 | first body line | |
483 | second body line | |
484 | ' | |
485 | ||
7f6e275b JK |
486 | test_expect_success 'create tag with multiline subject' ' |
487 | cat >msg <<-\EOF && | |
488 | first subject line | |
489 | second subject line | |
490 | ||
491 | first body line | |
492 | second body line | |
493 | EOF | |
494 | git tag -F msg multiline | |
495 | ' | |
496 | test_atom refs/tags/multiline subject 'first subject line second subject line' | |
e2b23972 | 497 | test_atom refs/tags/multiline contents:subject 'first subject line second subject line' |
7f6e275b JK |
498 | test_atom refs/tags/multiline body 'first body line |
499 | second body line | |
500 | ' | |
e2b23972 MG |
501 | test_atom refs/tags/multiline contents:body 'first body line |
502 | second body line | |
503 | ' | |
504 | test_atom refs/tags/multiline contents:signature '' | |
7f6e275b JK |
505 | test_atom refs/tags/multiline contents 'first subject line |
506 | second subject line | |
507 | ||
508 | first body line | |
509 | second body line | |
510 | ' | |
511 | ||
e2b23972 MG |
512 | test_expect_success GPG 'create signed tags' ' |
513 | git tag -s -m "" signed-empty && | |
514 | git tag -s -m "subject line" signed-short && | |
515 | cat >msg <<-\EOF && | |
516 | subject line | |
517 | ||
518 | body contents | |
519 | EOF | |
520 | git tag -s -F msg signed-long | |
521 | ' | |
522 | ||
523 | sig='-----BEGIN PGP SIGNATURE----- | |
524 | -----END PGP SIGNATURE----- | |
525 | ' | |
526 | ||
527 | PREREQ=GPG | |
528 | test_atom refs/tags/signed-empty subject '' | |
529 | test_atom refs/tags/signed-empty contents:subject '' | |
530 | test_atom refs/tags/signed-empty body "$sig" | |
531 | test_atom refs/tags/signed-empty contents:body '' | |
532 | test_atom refs/tags/signed-empty contents:signature "$sig" | |
533 | test_atom refs/tags/signed-empty contents "$sig" | |
534 | ||
535 | test_atom refs/tags/signed-short subject 'subject line' | |
536 | test_atom refs/tags/signed-short contents:subject 'subject line' | |
537 | test_atom refs/tags/signed-short body "$sig" | |
538 | test_atom refs/tags/signed-short contents:body '' | |
539 | test_atom refs/tags/signed-short contents:signature "$sig" | |
540 | test_atom refs/tags/signed-short contents "subject line | |
541 | $sig" | |
542 | ||
543 | test_atom refs/tags/signed-long subject 'subject line' | |
544 | test_atom refs/tags/signed-long contents:subject 'subject line' | |
545 | test_atom refs/tags/signed-long body "body contents | |
546 | $sig" | |
547 | test_atom refs/tags/signed-long contents:body 'body contents | |
548 | ' | |
549 | test_atom refs/tags/signed-long contents:signature "$sig" | |
550 | test_atom refs/tags/signed-long contents "subject line | |
551 | ||
552 | body contents | |
553 | $sig" | |
554 | ||
189a5467 | 555 | cat >expected <<EOF |
189a5467 | 556 | $(git rev-parse refs/tags/bogo) <committer@example.com> refs/tags/bogo |
db7bae25 | 557 | $(git rev-parse refs/tags/master) <committer@example.com> refs/tags/master |
912072d5 KK |
558 | EOF |
559 | ||
3b51222c | 560 | test_expect_success 'Verify sort with multiple keys' ' |
912072d5 KK |
561 | git for-each-ref --format="%(objectname) %(taggeremail) %(refname)" --sort=objectname --sort=taggeremail \ |
562 | refs/tags/bogo refs/tags/master > actual && | |
563 | test_cmp expected actual | |
564 | ' | |
84679d47 | 565 | |
01f95825 | 566 | |
84679d47 JH |
567 | test_expect_success 'do not dereference NULL upon %(HEAD) on unborn branch' ' |
568 | test_when_finished "git checkout master" && | |
569 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && | |
570 | sed -e "s/^\* / /" actual >expect && | |
571 | git checkout --orphan HEAD && | |
572 | git for-each-ref --format="%(HEAD) %(refname:short)" refs/heads/ >actual && | |
573 | test_cmp expect actual | |
574 | ' | |
575 | ||
b1d31c89 JK |
576 | cat >trailers <<EOF |
577 | Reviewed-by: A U Thor <author@example.com> | |
578 | Signed-off-by: A U Thor <author@example.com> | |
579 | EOF | |
580 | ||
581 | test_expect_success 'basic atom: head contents:trailers' ' | |
582 | echo "Some contents" > two && | |
583 | git add two && | |
584 | git commit -F - <<-EOF && | |
585 | trailers: this commit message has trailers | |
586 | ||
587 | Some message contents | |
588 | ||
589 | $(cat trailers) | |
590 | EOF | |
591 | git for-each-ref --format="%(contents:trailers)" refs/heads/master >actual && | |
592 | sanitize_pgp <actual >actual.clean && | |
593 | # git for-each-ref ends with a blank line | |
594 | cat >expect <<-EOF && | |
595 | $(cat trailers) | |
596 | ||
597 | EOF | |
598 | test_cmp expect actual.clean | |
599 | ' | |
600 | ||
01f95825 KN |
601 | test_expect_success 'Add symbolic ref for the following tests' ' |
602 | git symbolic-ref refs/heads/sym refs/heads/master | |
603 | ' | |
604 | ||
605 | cat >expected <<EOF | |
606 | refs/heads/master | |
607 | EOF | |
608 | ||
609 | test_expect_success 'Verify usage of %(symref) atom' ' | |
610 | git for-each-ref --format="%(symref)" refs/heads/sym >actual && | |
611 | test_cmp expected actual | |
612 | ' | |
613 | ||
614 | cat >expected <<EOF | |
615 | heads/master | |
616 | EOF | |
617 | ||
618 | test_expect_success 'Verify usage of %(symref:short) atom' ' | |
619 | git for-each-ref --format="%(symref:short)" refs/heads/sym >actual && | |
620 | test_cmp expected actual | |
621 | ' | |
622 | ||
a7984101 KN |
623 | cat >expected <<EOF |
624 | master | |
1a0ca5e3 | 625 | heads/master |
a7984101 KN |
626 | EOF |
627 | ||
17938f17 KN |
628 | test_expect_success 'Verify usage of %(symref:lstrip) atom' ' |
629 | git for-each-ref --format="%(symref:lstrip=2)" refs/heads/sym > actual && | |
1a0ca5e3 | 630 | git for-each-ref --format="%(symref:lstrip=-2)" refs/heads/sym >> actual && |
a7984101 KN |
631 | test_cmp expected actual |
632 | ' | |
633 | ||
96b2d4fa | 634 | test_done |