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