]>
Commit | Line | Data |
---|---|---|
8028184e WP |
1 | #!/bin/sh |
2 | # | |
3 | # Copyright (c) 2010, Will Palmer | |
de6029a2 | 4 | # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests) |
8028184e WP |
5 | # |
6 | ||
7 | test_description='Test pretty formats' | |
8 | . ./test-lib.sh | |
9 | ||
ee3efaf6 AS |
10 | # Tested non-UTF-8 encoding |
11 | test_encoding="ISO8859-1" | |
12 | ||
37eb772e AS |
13 | sample_utf8_part=$(printf "f\303\244ng") |
14 | ||
de6029a2 | 15 | commit_msg () { |
17cc2ef1 AS |
16 | # String "initial. initial" partly in German |
17 | # (translated with Google Translate), | |
de6029a2 | 18 | # encoded in UTF-8, used as a commit log message below. |
37eb772e | 19 | msg="initial. an${sample_utf8_part}lich\n" |
de6029a2 AS |
20 | if test -n "$1" |
21 | then | |
37eb772e AS |
22 | printf "$msg" | iconv -f utf-8 -t "$1" |
23 | else | |
24 | printf "$msg" | |
de6029a2 | 25 | fi |
de6029a2 AS |
26 | } |
27 | ||
8028184e WP |
28 | test_expect_success 'set up basic repos' ' |
29 | >foo && | |
30 | >bar && | |
31 | git add foo && | |
32 | test_tick && | |
2cd134f2 | 33 | test_config i18n.commitEncoding $test_encoding && |
e6ce2be2 | 34 | commit_msg $test_encoding | git commit -F - && |
8028184e WP |
35 | git add bar && |
36 | test_tick && | |
2cd134f2 | 37 | git commit -m "add bar" |
8028184e WP |
38 | ' |
39 | ||
40 | test_expect_success 'alias builtin format' ' | |
41 | git log --pretty=oneline >expected && | |
2cd134f2 | 42 | test_config pretty.test-alias oneline && |
8028184e WP |
43 | git log --pretty=test-alias >actual && |
44 | test_cmp expected actual | |
45 | ' | |
46 | ||
47 | test_expect_success 'alias masking builtin format' ' | |
48 | git log --pretty=oneline >expected && | |
2cd134f2 | 49 | test_config pretty.oneline "%H" && |
8028184e WP |
50 | git log --pretty=oneline >actual && |
51 | test_cmp expected actual | |
52 | ' | |
53 | ||
54 | test_expect_success 'alias user-defined format' ' | |
55 | git log --pretty="format:%h" >expected && | |
2cd134f2 | 56 | test_config pretty.test-alias "format:%h" && |
8028184e WP |
57 | git log --pretty=test-alias >actual && |
58 | test_cmp expected actual | |
59 | ' | |
60 | ||
f999d518 BL |
61 | test_expect_success 'alias user-defined format is matched case-insensitively' ' |
62 | git log --pretty="format:%h" >expected && | |
63 | test_config pretty.testone "format:%h" && | |
64 | test_config pretty.testtwo testOne && | |
65 | git log --pretty=testTwo >actual && | |
66 | test_cmp expected actual | |
67 | ' | |
68 | ||
ee3efaf6 | 69 | test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' ' |
2cd134f2 | 70 | test_config i18n.logOutputEncoding $test_encoding && |
de6029a2 AS |
71 | git log --oneline >expected-s && |
72 | git log --pretty="tformat:%h %s" >actual-s && | |
de6029a2 AS |
73 | test_cmp expected-s actual-s |
74 | ' | |
75 | ||
ecaee805 | 76 | test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' ' |
de6029a2 AS |
77 | git log --oneline >expected-s && |
78 | git log --pretty="tformat:%h %s" >actual-s && | |
79 | test_cmp expected-s actual-s | |
80 | ' | |
81 | ||
8028184e WP |
82 | test_expect_success 'alias user-defined tformat' ' |
83 | git log --pretty="tformat:%h" >expected && | |
2cd134f2 | 84 | test_config pretty.test-alias "tformat:%h" && |
8028184e WP |
85 | git log --pretty=test-alias >actual && |
86 | test_cmp expected actual | |
87 | ' | |
88 | ||
7be8b3ba | 89 | test_expect_success 'alias non-existent format' ' |
2cd134f2 | 90 | test_config pretty.test-alias format-that-will-never-exist && |
8028184e WP |
91 | test_must_fail git log --pretty=test-alias |
92 | ' | |
93 | ||
94 | test_expect_success 'alias of an alias' ' | |
95 | git log --pretty="tformat:%h" >expected && | |
2cd134f2 BL |
96 | test_config pretty.test-foo "tformat:%h" && |
97 | test_config pretty.test-bar test-foo && | |
8028184e WP |
98 | git log --pretty=test-bar >actual && test_cmp expected actual |
99 | ' | |
100 | ||
101 | test_expect_success 'alias masking an alias' ' | |
102 | git log --pretty=format:"Two %H" >expected && | |
2cd134f2 BL |
103 | test_config pretty.duplicate "format:One %H" && |
104 | test_config pretty.duplicate "format:Two %H" --add && | |
8028184e WP |
105 | git log --pretty=duplicate >actual && |
106 | test_cmp expected actual | |
107 | ' | |
108 | ||
109 | test_expect_success 'alias loop' ' | |
2cd134f2 BL |
110 | test_config pretty.test-foo test-bar && |
111 | test_config pretty.test-bar test-foo && | |
8028184e WP |
112 | test_must_fail git log --pretty=test-foo |
113 | ' | |
114 | ||
ecaee805 | 115 | test_expect_success 'NUL separation' ' |
de6029a2 | 116 | printf "add bar\0$(commit_msg)" >expected && |
3e065308 JK |
117 | git log -z --pretty="format:%s" >actual && |
118 | test_cmp expected actual | |
119 | ' | |
120 | ||
ecaee805 | 121 | test_expect_success 'NUL termination' ' |
de6029a2 | 122 | printf "add bar\0$(commit_msg)\0" >expected && |
3e065308 JK |
123 | git log -z --pretty="tformat:%s" >actual && |
124 | test_cmp expected actual | |
125 | ' | |
126 | ||
ecaee805 | 127 | test_expect_success 'NUL separation with --stat' ' |
fafd3829 | 128 | stat0_part=$(git diff --stat HEAD^ HEAD) && |
74faaa16 | 129 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
de6029a2 | 130 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected && |
fafd3829 | 131 | git log -z --stat --pretty="format:%s" >actual && |
1108cea7 | 132 | test_cmp expected actual |
fafd3829 JH |
133 | ' |
134 | ||
a926c4b9 | 135 | test_expect_failure 'NUL termination with --stat' ' |
fafd3829 | 136 | stat0_part=$(git diff --stat HEAD^ HEAD) && |
74faaa16 | 137 | stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) && |
de6029a2 | 138 | printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected && |
fafd3829 | 139 | git log -z --stat --pretty="tformat:%s" >actual && |
0d75bfe6 | 140 | test_cmp expected actual |
fafd3829 JH |
141 | ' |
142 | ||
ac52d941 DL |
143 | for p in short medium full fuller email raw |
144 | do | |
145 | test_expect_success "NUL termination with --reflog --pretty=$p" ' | |
146 | revs="$(git rev-list --reflog)" && | |
147 | for r in $revs | |
148 | do | |
149 | git show -s "$r" --pretty="$p" && | |
150 | printf "\0" || return 1 | |
151 | done >expect && | |
152 | { | |
153 | git log -z --reflog --pretty="$p" && | |
154 | printf "\0" | |
155 | } >actual && | |
156 | test_cmp expect actual | |
157 | ' | |
158 | done | |
159 | ||
160 | test_expect_success 'NUL termination with --reflog --pretty=oneline' ' | |
161 | revs="$(git rev-list --reflog)" && | |
162 | for r in $revs | |
163 | do | |
164 | git show -s --pretty=oneline "$r" >raw && | |
77e04b2e | 165 | cat raw | lf_to_nul || return 1 |
ac52d941 DL |
166 | done >expect && |
167 | # the trailing NUL is already produced so we do not need to | |
168 | # output another one | |
169 | git log -z --pretty=oneline --reflog >actual && | |
170 | test_cmp expect actual | |
171 | ' | |
172 | ||
a5752342 NTND |
173 | test_expect_success 'setup more commits' ' |
174 | test_commit "message one" one one message-one && | |
a742f2a0 AS |
175 | test_commit "message two" two two message-two && |
176 | head1=$(git rev-parse --verify --short HEAD~0) && | |
177 | head2=$(git rev-parse --verify --short HEAD~1) && | |
178 | head3=$(git rev-parse --verify --short HEAD~2) && | |
179 | head4=$(git rev-parse --verify --short HEAD~3) | |
a5752342 NTND |
180 | ' |
181 | ||
f3445f78 | 182 | test_expect_success 'left alignment formatting' ' |
c82134a9 | 183 | git log --pretty="tformat:%<(40)%s" >actual && |
9d1ca1da JK |
184 | qz_to_tab_space <<-EOF >expected && |
185 | message two Z | |
186 | message one Z | |
187 | add bar Z | |
188 | $(commit_msg) Z | |
189 | EOF | |
a5752342 | 190 | test_cmp expected actual |
f3445f78 | 191 | ' |
a5752342 | 192 | |
d928d810 AS |
193 | test_expect_success 'left alignment formatting. i18n.logOutputEncoding' ' |
194 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && | |
9d1ca1da JK |
195 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
196 | message two Z | |
197 | message one Z | |
198 | add bar Z | |
199 | $(commit_msg) Z | |
200 | EOF | |
d928d810 AS |
201 | test_cmp expected actual |
202 | ' | |
203 | ||
f3445f78 | 204 | test_expect_success 'left alignment formatting at the nth column' ' |
c82134a9 | 205 | git log --pretty="tformat:%h %<|(40)%s" >actual && |
9d1ca1da JK |
206 | qz_to_tab_space <<-EOF >expected && |
207 | $head1 message two Z | |
208 | $head2 message one Z | |
209 | $head3 add bar Z | |
210 | $head4 $(commit_msg) Z | |
211 | EOF | |
a5752342 | 212 | test_cmp expected actual |
f3445f78 | 213 | ' |
a5752342 | 214 | |
066790d7 NTND |
215 | test_expect_success 'left alignment formatting at the nth column' ' |
216 | COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual && | |
9d1ca1da JK |
217 | qz_to_tab_space <<-EOF >expected && |
218 | $head1 message two Z | |
219 | $head2 message one Z | |
220 | $head3 add bar Z | |
221 | $head4 $(commit_msg) Z | |
222 | EOF | |
066790d7 NTND |
223 | test_cmp expected actual |
224 | ' | |
225 | ||
d928d810 AS |
226 | test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' |
227 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && | |
9d1ca1da JK |
228 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
229 | $head1 message two Z | |
230 | $head2 message one Z | |
231 | $head3 add bar Z | |
232 | $head4 $(commit_msg) Z | |
233 | EOF | |
d928d810 AS |
234 | test_cmp expected actual |
235 | ' | |
236 | ||
f3445f78 | 237 | test_expect_success 'left alignment formatting with no padding' ' |
c82134a9 | 238 | git log --pretty="tformat:%<(1)%s" >actual && |
9d1ca1da JK |
239 | cat <<-EOF >expected && |
240 | message two | |
241 | message one | |
242 | add bar | |
243 | $(commit_msg) | |
244 | EOF | |
a5752342 | 245 | test_cmp expected actual |
f3445f78 | 246 | ' |
a5752342 | 247 | |
d928d810 AS |
248 | test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' ' |
249 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && | |
9d1ca1da JK |
250 | cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
251 | message two | |
252 | message one | |
253 | add bar | |
254 | $(commit_msg) | |
255 | EOF | |
d928d810 AS |
256 | test_cmp expected actual |
257 | ' | |
258 | ||
f3445f78 | 259 | test_expect_success 'left alignment formatting with trunc' ' |
c82134a9 | 260 | git log --pretty="tformat:%<(10,trunc)%s" >actual && |
9d1ca1da JK |
261 | qz_to_tab_space <<-\EOF >expected && |
262 | message .. | |
263 | message .. | |
264 | add bar Z | |
265 | initial... | |
266 | EOF | |
a7f01c6b | 267 | test_cmp expected actual |
f3445f78 | 268 | ' |
a7f01c6b | 269 | |
7d509878 | 270 | test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' ' |
d928d810 | 271 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && |
9d1ca1da JK |
272 | qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && |
273 | message .. | |
274 | message .. | |
275 | add bar Z | |
276 | initial... | |
277 | EOF | |
d928d810 AS |
278 | test_cmp expected actual |
279 | ' | |
280 | ||
f3445f78 | 281 | test_expect_success 'left alignment formatting with ltrunc' ' |
c82134a9 | 282 | git log --pretty="tformat:%<(10,ltrunc)%s" >actual && |
9d1ca1da JK |
283 | qz_to_tab_space <<-EOF >expected && |
284 | ..sage two | |
285 | ..sage one | |
286 | add bar Z | |
287 | ..${sample_utf8_part}lich | |
288 | EOF | |
a7f01c6b | 289 | test_cmp expected actual |
f3445f78 | 290 | ' |
a7f01c6b | 291 | |
7d509878 | 292 | test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' |
d928d810 | 293 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && |
9d1ca1da JK |
294 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
295 | ..sage two | |
296 | ..sage one | |
297 | add bar Z | |
298 | ..${sample_utf8_part}lich | |
299 | EOF | |
d928d810 AS |
300 | test_cmp expected actual |
301 | ' | |
302 | ||
f3445f78 | 303 | test_expect_success 'left alignment formatting with mtrunc' ' |
c82134a9 | 304 | git log --pretty="tformat:%<(10,mtrunc)%s" >actual && |
9d1ca1da JK |
305 | qz_to_tab_space <<-\EOF >expected && |
306 | mess.. two | |
307 | mess.. one | |
308 | add bar Z | |
309 | init..lich | |
310 | EOF | |
a7f01c6b | 311 | test_cmp expected actual |
f3445f78 | 312 | ' |
a7f01c6b | 313 | |
7d509878 | 314 | test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' |
d928d810 | 315 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && |
9d1ca1da JK |
316 | qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && |
317 | mess.. two | |
318 | mess.. one | |
319 | add bar Z | |
320 | init..lich | |
321 | EOF | |
d928d810 AS |
322 | test_cmp expected actual |
323 | ' | |
324 | ||
f3445f78 | 325 | test_expect_success 'right alignment formatting' ' |
c82134a9 | 326 | git log --pretty="tformat:%>(40)%s" >actual && |
9d1ca1da JK |
327 | qz_to_tab_space <<-EOF >expected && |
328 | Z message two | |
329 | Z message one | |
330 | Z add bar | |
331 | Z $(commit_msg) | |
332 | EOF | |
a5752342 | 333 | test_cmp expected actual |
f3445f78 | 334 | ' |
a5752342 | 335 | |
d928d810 AS |
336 | test_expect_success 'right alignment formatting. i18n.logOutputEncoding' ' |
337 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && | |
9d1ca1da JK |
338 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
339 | Z message two | |
340 | Z message one | |
341 | Z add bar | |
342 | Z $(commit_msg) | |
343 | EOF | |
d928d810 AS |
344 | test_cmp expected actual |
345 | ' | |
346 | ||
f3445f78 | 347 | test_expect_success 'right alignment formatting at the nth column' ' |
c82134a9 | 348 | git log --pretty="tformat:%h %>|(40)%s" >actual && |
9d1ca1da JK |
349 | qz_to_tab_space <<-EOF >expected && |
350 | $head1 message two | |
351 | $head2 message one | |
352 | $head3 add bar | |
353 | $head4 $(commit_msg) | |
354 | EOF | |
a5752342 | 355 | test_cmp expected actual |
f3445f78 | 356 | ' |
a5752342 | 357 | |
066790d7 NTND |
358 | test_expect_success 'right alignment formatting at the nth column' ' |
359 | COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual && | |
9d1ca1da JK |
360 | qz_to_tab_space <<-EOF >expected && |
361 | $head1 message two | |
362 | $head2 message one | |
363 | $head3 add bar | |
364 | $head4 $(commit_msg) | |
365 | EOF | |
066790d7 NTND |
366 | test_cmp expected actual |
367 | ' | |
368 | ||
d928d810 AS |
369 | test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' |
370 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && | |
9d1ca1da JK |
371 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
372 | $head1 message two | |
373 | $head2 message one | |
374 | $head3 add bar | |
375 | $head4 $(commit_msg) | |
376 | EOF | |
d928d810 AS |
377 | test_cmp expected actual |
378 | ' | |
379 | ||
3ad87c80 JK |
380 | # Note: Space between 'message' and 'two' should be in the same column |
381 | # as in previous test. | |
382 | test_expect_success 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' ' | |
383 | git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual && | |
9d1ca1da JK |
384 | iconv -f utf-8 -t $test_encoding >expected <<-EOF && |
385 | * $head1 message two | |
386 | * $head2 message one | |
387 | * $head3 add bar | |
388 | * $head4 $(commit_msg) | |
389 | EOF | |
3ad87c80 JK |
390 | test_cmp expected actual |
391 | ' | |
392 | ||
f3445f78 | 393 | test_expect_success 'right alignment formatting with no padding' ' |
c82134a9 | 394 | git log --pretty="tformat:%>(1)%s" >actual && |
9d1ca1da JK |
395 | cat <<-EOF >expected && |
396 | message two | |
397 | message one | |
398 | add bar | |
399 | $(commit_msg) | |
400 | EOF | |
a5752342 | 401 | test_cmp expected actual |
f3445f78 | 402 | ' |
a5752342 | 403 | |
3ad87c80 JK |
404 | test_expect_success 'right alignment formatting with no padding and with --graph' ' |
405 | git log --graph --pretty="tformat:%>(1)%s" >actual && | |
9d1ca1da JK |
406 | cat <<-EOF >expected && |
407 | * message two | |
408 | * message one | |
409 | * add bar | |
410 | * $(commit_msg) | |
411 | EOF | |
3ad87c80 JK |
412 | test_cmp expected actual |
413 | ' | |
414 | ||
d928d810 AS |
415 | test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' ' |
416 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && | |
9d1ca1da JK |
417 | cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
418 | message two | |
419 | message one | |
420 | add bar | |
421 | $(commit_msg) | |
422 | EOF | |
d928d810 AS |
423 | test_cmp expected actual |
424 | ' | |
425 | ||
f3445f78 | 426 | test_expect_success 'center alignment formatting' ' |
c82134a9 | 427 | git log --pretty="tformat:%><(40)%s" >actual && |
9d1ca1da JK |
428 | qz_to_tab_space <<-EOF >expected && |
429 | Z message two Z | |
430 | Z message one Z | |
431 | Z add bar Z | |
432 | Z $(commit_msg) Z | |
433 | EOF | |
a5752342 | 434 | test_cmp expected actual |
f3445f78 | 435 | ' |
a5752342 | 436 | |
d928d810 AS |
437 | test_expect_success 'center alignment formatting. i18n.logOutputEncoding' ' |
438 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && | |
9d1ca1da JK |
439 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
440 | Z message two Z | |
441 | Z message one Z | |
442 | Z add bar Z | |
443 | Z $(commit_msg) Z | |
444 | EOF | |
d928d810 AS |
445 | test_cmp expected actual |
446 | ' | |
f3445f78 | 447 | test_expect_success 'center alignment formatting at the nth column' ' |
c82134a9 | 448 | git log --pretty="tformat:%h %><|(40)%s" >actual && |
9d1ca1da JK |
449 | qz_to_tab_space <<-EOF >expected && |
450 | $head1 message two Z | |
451 | $head2 message one Z | |
452 | $head3 add bar Z | |
453 | $head4 $(commit_msg) Z | |
454 | EOF | |
a5752342 | 455 | test_cmp expected actual |
f3445f78 | 456 | ' |
a5752342 | 457 | |
066790d7 NTND |
458 | test_expect_success 'center alignment formatting at the nth column' ' |
459 | COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual && | |
9d1ca1da JK |
460 | qz_to_tab_space <<-EOF >expected && |
461 | $head1 message two Z | |
462 | $head2 message one Z | |
463 | $head3 add bar Z | |
464 | $head4 $(commit_msg) Z | |
465 | EOF | |
066790d7 NTND |
466 | test_cmp expected actual |
467 | ' | |
468 | ||
d928d810 AS |
469 | test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' |
470 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && | |
9d1ca1da JK |
471 | qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
472 | $head1 message two Z | |
473 | $head2 message one Z | |
474 | $head3 add bar Z | |
475 | $head4 $(commit_msg) Z | |
476 | EOF | |
d928d810 AS |
477 | test_cmp expected actual |
478 | ' | |
479 | ||
f3445f78 | 480 | test_expect_success 'center alignment formatting with no padding' ' |
c82134a9 | 481 | git log --pretty="tformat:%><(1)%s" >actual && |
9d1ca1da JK |
482 | cat <<-EOF >expected && |
483 | message two | |
484 | message one | |
485 | add bar | |
486 | $(commit_msg) | |
487 | EOF | |
a5752342 | 488 | test_cmp expected actual |
f3445f78 | 489 | ' |
a5752342 | 490 | |
496a6980 AS |
491 | # save HEAD's SHA-1 digest (with no abbreviations) to use it below |
492 | # as far as the next test amends HEAD | |
493 | old_head1=$(git rev-parse --verify HEAD~0) | |
d928d810 AS |
494 | test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' ' |
495 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && | |
9d1ca1da JK |
496 | cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected && |
497 | message two | |
498 | message one | |
499 | add bar | |
500 | $(commit_msg) | |
501 | EOF | |
d928d810 AS |
502 | test_cmp expected actual |
503 | ' | |
496a6980 | 504 | |
f3445f78 AS |
505 | test_expect_success 'left/right alignment formatting with stealing' ' |
506 | git commit --amend -m short --author "long long long <long@me.com>" && | |
c82134a9 | 507 | git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && |
9d1ca1da JK |
508 | cat <<-\EOF >expected && |
509 | short long long long | |
510 | message .. A U Thor | |
511 | add bar A U Thor | |
512 | initial... A U Thor | |
513 | EOF | |
1640632b | 514 | test_cmp expected actual |
f3445f78 | 515 | ' |
7d509878 | 516 | test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' |
d928d810 | 517 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && |
9d1ca1da JK |
518 | cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected && |
519 | short long long long | |
520 | message .. A U Thor | |
521 | add bar A U Thor | |
522 | initial... A U Thor | |
523 | EOF | |
d928d810 AS |
524 | test_cmp expected actual |
525 | ' | |
1640632b | 526 | |
43087596 NTND |
527 | test_expect_success 'strbuf_utf8_replace() not producing NUL' ' |
528 | git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" | | |
529 | test_decode_color | | |
530 | nul_to_q >actual && | |
531 | ! grep Q actual | |
532 | ' | |
533 | ||
3593ebd3 ÆAB |
534 | # --date=[XXX] and corresponding %a[X] %c[X] format equivalency |
535 | test_expect_success '--date=iso-strict %ad%cd is the same as %aI%cI' ' | |
fbfcaec8 | 536 | git log --format=%ad%n%cd --date=iso-strict >expected && |
466fb674 BB |
537 | git log --format=%aI%n%cI >actual && |
538 | test_cmp expected actual | |
539 | ' | |
540 | ||
3593ebd3 | 541 | test_expect_success '--date=short %ad%cd is the same as %as%cs' ' |
0df62117 RS |
542 | git log --format=%ad%n%cd --date=short >expected && |
543 | git log --format=%as%n%cs >actual && | |
544 | test_cmp expected actual | |
545 | ' | |
546 | ||
b722d456 ZH |
547 | test_expect_success '--date=human %ad%cd is the same as %ah%ch' ' |
548 | git log --format=%ad%n%cd --date=human >expected && | |
549 | git log --format=%ah%n%ch >actual && | |
550 | test_cmp expected actual | |
551 | ' | |
552 | ||
496a6980 | 553 | # get new digests (with no abbreviations) |
1bd37509 JK |
554 | test_expect_success 'set up log decoration tests' ' |
555 | head1=$(git rev-parse --verify HEAD~0) && | |
556 | head2=$(git rev-parse --verify HEAD~1) | |
557 | ' | |
496a6980 | 558 | |
5e1361cc | 559 | test_expect_success 'log decoration properly follows tag chain' ' |
560 | git tag -a tag1 -m tag1 && | |
561 | git tag -a tag2 -m tag2 tag1 && | |
562 | git tag -d tag1 && | |
563 | git commit --amend -m shorter && | |
564 | git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && | |
9d1ca1da | 565 | cat <<-EOF >expected && |
9d1ca1da JK |
566 | $head2 (tag: refs/tags/message-one) |
567 | $old_head1 (tag: refs/tags/message-two) | |
2a73022e | 568 | $head1 (tag: refs/tags/tag2) |
9d1ca1da | 569 | EOF |
2a73022e | 570 | sort -k3 actual >actual1 && |
5e1361cc | 571 | test_cmp expected actual1 |
572 | ' | |
573 | ||
9271095c HJ |
574 | test_expect_success 'clean log decoration' ' |
575 | git log --no-walk --tags --pretty="%H %D" --decorate=full >actual && | |
9d1ca1da | 576 | cat >expected <<-EOF && |
9d1ca1da JK |
577 | $head2 tag: refs/tags/message-one |
578 | $old_head1 tag: refs/tags/message-two | |
2a73022e | 579 | $head1 tag: refs/tags/tag2 |
9d1ca1da | 580 | EOF |
2a73022e | 581 | sort -k3 actual >actual1 && |
9271095c HJ |
582 | test_cmp expected actual1 |
583 | ' | |
584 | ||
d9f31fbf JK |
585 | cat >trailers <<EOF |
586 | Signed-off-by: A U Thor <author@example.com> | |
587 | Acked-by: A U Thor <author@example.com> | |
588 | [ v2 updated patch description ] | |
cc1735c4 JK |
589 | Signed-off-by: A U Thor |
590 | <author@example.com> | |
d9f31fbf JK |
591 | EOF |
592 | ||
58311c66 | 593 | unfold () { |
6f5c77a1 | 594 | perl -0pe 's/\n\s+/ /g' |
58311c66 JK |
595 | } |
596 | ||
cc1735c4 | 597 | test_expect_success 'set up trailer tests' ' |
d9f31fbf JK |
598 | echo "Some contents" >trailerfile && |
599 | git add trailerfile && | |
cc1735c4 | 600 | git commit -F - <<-EOF |
d9f31fbf JK |
601 | trailers: this commit message has trailers |
602 | ||
603 | This commit is a test commit with trailers at the end. We parse this | |
cc1735c4 | 604 | message and display the trailers using %(trailers). |
d9f31fbf JK |
605 | |
606 | $(cat trailers) | |
607 | EOF | |
cc1735c4 | 608 | ' |
d9f31fbf | 609 | |
cc1735c4 JK |
610 | test_expect_success 'pretty format %(trailers) shows trailers' ' |
611 | git log --no-walk --pretty="%(trailers)" >actual && | |
612 | { | |
613 | cat trailers && | |
614 | echo | |
615 | } >expect && | |
d9f31fbf JK |
616 | test_cmp expect actual |
617 | ' | |
618 | ||
8b966a05 ÆAB |
619 | test_expect_success 'pretty format %(trailers:) enables no options' ' |
620 | git log --no-walk --pretty="%(trailers:)" >actual && | |
621 | # "expect" the same as the test above | |
622 | test_cmp expect actual | |
623 | ' | |
624 | ||
58311c66 JK |
625 | test_expect_success '%(trailers:only) shows only "key: value" trailers' ' |
626 | git log --no-walk --pretty="%(trailers:only)" >actual && | |
627 | { | |
628 | grep -v patch.description <trailers && | |
629 | echo | |
630 | } >expect && | |
631 | test_cmp expect actual | |
632 | ' | |
633 | ||
4f732e0f AW |
634 | test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' ' |
635 | git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && | |
636 | grep -v patch.description <trailers >expect && | |
637 | test_cmp expect actual | |
638 | ' | |
639 | ||
640 | test_expect_success '%(trailers:only=no) shows all trailers' ' | |
641 | git log --no-walk --pretty=format:"%(trailers:only=no)" >actual && | |
642 | cat trailers >expect && | |
643 | test_cmp expect actual | |
644 | ' | |
645 | ||
646 | test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' ' | |
647 | git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && | |
648 | grep -v patch.description <trailers >expect && | |
649 | test_cmp expect actual | |
58311c66 JK |
650 | ' |
651 | ||
652 | test_expect_success '%(trailers:unfold) unfolds trailers' ' | |
653 | git log --no-walk --pretty="%(trailers:unfold)" >actual && | |
654 | { | |
655 | unfold <trailers && | |
656 | echo | |
657 | } >expect && | |
658 | test_cmp expect actual | |
659 | ' | |
660 | ||
661 | test_expect_success ':only and :unfold work together' ' | |
84ff053d TB |
662 | git log --no-walk --pretty="%(trailers:only,unfold)" >actual && |
663 | git log --no-walk --pretty="%(trailers:unfold,only)" >reverse && | |
58311c66 JK |
664 | test_cmp actual reverse && |
665 | { | |
666 | grep -v patch.description <trailers | unfold && | |
667 | echo | |
668 | } >expect && | |
669 | test_cmp expect actual | |
670 | ' | |
671 | ||
250bea0c AW |
672 | test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' ' |
673 | git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual && | |
674 | echo "Acked-by: A U Thor <author@example.com>" >expect && | |
675 | test_cmp expect actual | |
676 | ' | |
677 | ||
678 | test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' ' | |
679 | git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual && | |
680 | echo "Acked-by: A U Thor <author@example.com>" >expect && | |
681 | test_cmp expect actual | |
682 | ' | |
683 | ||
684 | test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' ' | |
685 | git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual && | |
686 | echo "Acked-by: A U Thor <author@example.com>" >expect && | |
687 | test_cmp expect actual | |
688 | ' | |
689 | ||
690 | test_expect_success 'pretty format %(trailers:key=foo) multiple keys' ' | |
691 | git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual && | |
692 | grep -v patch.description <trailers >expect && | |
693 | test_cmp expect actual | |
694 | ' | |
695 | ||
4dc8b1c1 | 696 | test_expect_success '%(trailers:key=nonexistent) becomes empty' ' |
250bea0c AW |
697 | git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual && |
698 | echo "xx" >expect && | |
699 | test_cmp expect actual | |
700 | ' | |
701 | ||
702 | test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' ' | |
703 | git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual && | |
704 | grep -v patch.description <trailers | grep -v Acked-by >expect && | |
705 | test_cmp expect actual | |
706 | ' | |
707 | ||
708 | test_expect_success '%(trailers:key=foo,unfold) properly unfolds' ' | |
709 | git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual && | |
710 | unfold <trailers | grep Signed-off-by >expect && | |
711 | test_cmp expect actual | |
712 | ' | |
713 | ||
714 | test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' ' | |
715 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual && | |
716 | { | |
717 | echo "Acked-by: A U Thor <author@example.com>" && | |
718 | grep patch.description <trailers | |
719 | } >expect && | |
720 | test_cmp expect actual | |
721 | ' | |
722 | ||
723 | test_expect_success '%(trailers:key) without value is error' ' | |
724 | git log --no-walk --pretty="tformat:%(trailers:key)" >actual && | |
725 | echo "%(trailers:key)" >expect && | |
726 | test_cmp expect actual | |
727 | ' | |
728 | ||
9d87d5ae ÆAB |
729 | test_expect_success '%(trailers:keyonly) shows only keys' ' |
730 | git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && | |
731 | test_write_lines \ | |
732 | "Signed-off-by" \ | |
733 | "Acked-by" \ | |
734 | "[ v2 updated patch description ]" \ | |
735 | "Signed-off-by" >expect && | |
736 | test_cmp expect actual | |
737 | ' | |
738 | ||
739 | test_expect_success '%(trailers:key=foo,keyonly) shows only key' ' | |
740 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual && | |
741 | echo "Acked-by" >expect && | |
742 | test_cmp expect actual | |
743 | ' | |
744 | ||
d9b936db AW |
745 | test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' |
746 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual && | |
747 | echo "A U Thor <author@example.com>" >expect && | |
748 | test_cmp expect actual | |
749 | ' | |
750 | ||
8b966a05 ÆAB |
751 | test_expect_success '%(trailers:valueonly) shows only values' ' |
752 | git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && | |
753 | test_write_lines \ | |
754 | "A U Thor <author@example.com>" \ | |
755 | "A U Thor <author@example.com>" \ | |
756 | "[ v2 updated patch description ]" \ | |
757 | "A U Thor" \ | |
758 | " <author@example.com>" >expect && | |
759 | test_cmp expect actual | |
760 | ' | |
761 | ||
9d87d5ae ÆAB |
762 | test_expect_success '%(trailers:key=foo,keyonly,valueonly) shows nothing' ' |
763 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual && | |
764 | echo >expect && | |
765 | test_cmp expect actual | |
766 | ' | |
767 | ||
0b691d86 | 768 | test_expect_success 'pretty format %(trailers:separator) changes separator' ' |
8b966a05 ÆAB |
769 | git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual && |
770 | ( | |
771 | printf "XSigned-off-by: A U Thor <author@example.com>\0" && | |
772 | printf "Acked-by: A U Thor <author@example.com>\0" && | |
773 | printf "[ v2 updated patch description ]\0" && | |
774 | printf "Signed-off-by: A U Thor\n <author@example.com>X" | |
775 | ) >expect && | |
776 | test_cmp expect actual | |
777 | ' | |
778 | ||
779 | test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separator' ' | |
0b691d86 | 780 | git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual && |
7c1f79fc ÆAB |
781 | ( |
782 | printf "XSigned-off-by: A U Thor <author@example.com>\0" && | |
783 | printf "Acked-by: A U Thor <author@example.com>\0" && | |
784 | printf "[ v2 updated patch description ]\0" && | |
785 | printf "Signed-off-by: A U Thor <author@example.com>X" | |
786 | ) >expect && | |
0b691d86 | 787 | test_cmp expect actual |
058761f1 ÆAB |
788 | ' |
789 | ||
790 | test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' | |
791 | git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && | |
792 | ( | |
793 | printf "XSigned-off-by\0A U Thor <author@example.com>\n" && | |
794 | printf "Acked-by\0A U Thor <author@example.com>\n" && | |
795 | printf "[ v2 updated patch description ]\n" && | |
796 | printf "Signed-off-by\0A U Thor\n <author@example.com>\nX" | |
797 | ) >expect && | |
798 | test_cmp expect actual | |
799 | ' | |
800 | ||
801 | test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' | |
802 | git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && | |
803 | ( | |
804 | printf "XSigned-off-by\0A U Thor <author@example.com>\n" && | |
805 | printf "Acked-by\0A U Thor <author@example.com>\n" && | |
806 | printf "[ v2 updated patch description ]\n" && | |
807 | printf "Signed-off-by\0A U Thor <author@example.com>\nX" | |
808 | ) >expect && | |
809 | test_cmp expect actual | |
810 | ' | |
811 | ||
812 | test_expect_success 'pretty format %(trailers:separator,key_value_separator) changes both separators' ' | |
813 | git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual && | |
814 | ( | |
815 | printf "Signed-off-by\0\0A U Thor <author@example.com>\0" && | |
816 | printf "Acked-by\0\0A U Thor <author@example.com>\0" && | |
817 | printf "[ v2 updated patch description ]\0" && | |
818 | printf "Signed-off-by\0\0A U Thor <author@example.com>" | |
819 | ) >expect && | |
820 | test_cmp expect actual | |
0b691d86 AW |
821 | ' |
822 | ||
9d87d5ae | 823 | test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' ' |
0b691d86 AW |
824 | git commit --allow-empty -F - <<-\EOF && |
825 | Important fix | |
826 | ||
827 | The fix is explained here | |
828 | ||
829 | Closes: #1234 | |
830 | EOF | |
831 | ||
832 | git commit --allow-empty -F - <<-\EOF && | |
833 | Another fix | |
834 | ||
835 | The fix is explained here | |
836 | ||
837 | Closes: #567 | |
838 | Closes: #890 | |
839 | EOF | |
840 | ||
841 | git commit --allow-empty -F - <<-\EOF && | |
842 | Does not close any tickets | |
843 | EOF | |
844 | ||
845 | git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual && | |
846 | test_write_lines \ | |
847 | "Does not close any tickets" \ | |
848 | "Another fix #567, #890" \ | |
849 | "Important fix #1234" >expect && | |
9d87d5ae ÆAB |
850 | test_cmp expect actual && |
851 | ||
852 | git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual && | |
853 | test_write_lines \ | |
854 | "Does not close any tickets" \ | |
855 | "Another fix Closes, Closes" \ | |
856 | "Important fix Closes" >expect && | |
0b691d86 AW |
857 | test_cmp expect actual |
858 | ' | |
859 | ||
e5fba5d5 JK |
860 | test_expect_success 'trailer parsing not fooled by --- line' ' |
861 | git commit --allow-empty -F - <<-\EOF && | |
862 | this is the subject | |
863 | ||
864 | This is the body. The message has a "---" line which would confuse a | |
865 | message+patch parser. But here we know we have only a commit message, | |
866 | so we get it right. | |
867 | ||
868 | trailer: wrong | |
869 | --- | |
870 | This is more body. | |
871 | ||
872 | trailer: right | |
873 | EOF | |
874 | ||
875 | { | |
876 | echo "trailer: right" && | |
877 | echo | |
878 | } >expect && | |
879 | git log --no-walk --format="%(trailers)" >actual && | |
880 | test_cmp expect actual | |
881 | ' | |
882 | ||
ad6f028f IT |
883 | test_expect_success 'set up %S tests' ' |
884 | git checkout --orphan source-a && | |
885 | test_commit one && | |
886 | test_commit two && | |
887 | git checkout -b source-b HEAD^ && | |
888 | test_commit three | |
889 | ' | |
890 | ||
891 | test_expect_success 'log --format=%S paints branch names' ' | |
892 | cat >expect <<-\EOF && | |
893 | source-b | |
894 | source-a | |
895 | source-b | |
896 | EOF | |
897 | git log --format=%S source-a source-b >actual && | |
898 | test_cmp expect actual | |
899 | ' | |
900 | ||
901 | test_expect_success 'log --format=%S paints tag names' ' | |
902 | git tag -m tagged source-tag && | |
903 | cat >expect <<-\EOF && | |
904 | source-tag | |
905 | source-a | |
906 | source-tag | |
907 | EOF | |
908 | git log --format=%S source-tag source-a >actual && | |
909 | test_cmp expect actual | |
910 | ' | |
911 | ||
912 | test_expect_success 'log --format=%S paints symmetric ranges' ' | |
913 | cat >expect <<-\EOF && | |
914 | source-b | |
915 | source-a | |
916 | EOF | |
917 | git log --format=%S source-a...source-b >actual && | |
918 | test_cmp expect actual | |
919 | ' | |
920 | ||
921 | test_expect_success '%S in git log --format works with other placeholders (part 1)' ' | |
922 | git log --format="source-b %h" source-b >expect && | |
923 | git log --format="%S %h" source-b >actual && | |
924 | test_cmp expect actual | |
925 | ' | |
926 | ||
927 | test_expect_success '%S in git log --format works with other placeholders (part 2)' ' | |
928 | git log --format="%h source-b" source-b >expect && | |
929 | git log --format="%h %S" source-b >actual && | |
930 | test_cmp expect actual | |
931 | ' | |
932 | ||
1f0fc1db DL |
933 | test_expect_success 'log --pretty=reference' ' |
934 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
935 | git log --pretty=reference >actual && | |
936 | test_cmp expect actual | |
937 | ' | |
938 | ||
939 | test_expect_success 'log --pretty=reference with log.date is overridden by short date' ' | |
940 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
941 | test_config log.date rfc && | |
942 | git log --pretty=reference >actual && | |
943 | test_cmp expect actual | |
944 | ' | |
945 | ||
946 | test_expect_success 'log --pretty=reference with explicit date overrides short date' ' | |
947 | git log --date=rfc --pretty="tformat:%h (%s, %ad)" >expect && | |
948 | git log --date=rfc --pretty=reference >actual && | |
949 | test_cmp expect actual | |
950 | ' | |
951 | ||
952 | test_expect_success 'log --pretty=reference is never unabbreviated' ' | |
953 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
954 | git log --no-abbrev-commit --pretty=reference >actual && | |
955 | test_cmp expect actual | |
956 | ' | |
957 | ||
958 | test_expect_success 'log --pretty=reference is never decorated' ' | |
959 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
960 | git log --decorate=short --pretty=reference >actual && | |
961 | test_cmp expect actual | |
962 | ' | |
963 | ||
964 | test_expect_success 'log --pretty=reference does not output reflog info' ' | |
965 | git log --walk-reflogs --pretty="tformat:%h (%s, %as)" >expect && | |
966 | git log --walk-reflogs --pretty=reference >actual && | |
967 | test_cmp expect actual | |
968 | ' | |
969 | ||
970 | test_expect_success 'log --pretty=reference is colored appropriately' ' | |
971 | git log --color=always --pretty="tformat:%C(auto)%h (%s, %as)" >expect && | |
972 | git log --color=always --pretty=reference >actual && | |
973 | test_cmp expect actual | |
974 | ' | |
975 | ||
15ae82d5 RS |
976 | test_expect_success '%(describe) vs git describe' ' |
977 | git log --format="%H" | while read hash | |
978 | do | |
09fe8ca9 RS |
979 | if desc=$(git describe $hash) |
980 | then | |
981 | : >expect-contains-good | |
982 | else | |
983 | : >expect-contains-bad | |
984 | fi && | |
cbe1d9d6 | 985 | echo "$hash $desc" || return 1 |
15ae82d5 | 986 | done >expect && |
09fe8ca9 RS |
987 | test_path_exists expect-contains-good && |
988 | test_path_exists expect-contains-bad && | |
989 | ||
15ae82d5 RS |
990 | git log --format="%H %(describe)" >actual 2>err && |
991 | test_cmp expect actual && | |
992 | test_must_be_empty err | |
993 | ' | |
994 | ||
b081547e RS |
995 | test_expect_success '%(describe:match=...) vs git describe --match ...' ' |
996 | test_when_finished "git tag -d tag-match" && | |
52ff891c | 997 | git tag -a -m tagged tag-match && |
b081547e RS |
998 | git describe --match "*-match" >expect && |
999 | git log -1 --format="%(describe:match=*-match)" >actual && | |
1000 | test_cmp expect actual | |
1001 | ' | |
1002 | ||
1003 | test_expect_success '%(describe:exclude=...) vs git describe --exclude ...' ' | |
1004 | test_when_finished "git tag -d tag-exclude" && | |
1005 | git tag -a -m tagged tag-exclude && | |
1006 | git describe --exclude "*-exclude" >expect && | |
1007 | git log -1 --format="%(describe:exclude=*-exclude)" >actual && | |
1008 | test_cmp expect actual | |
1009 | ' | |
1010 | ||
1d517cea ES |
1011 | test_expect_success '%(describe:tags) vs git describe --tags' ' |
1012 | test_when_finished "git tag -d tagname" && | |
1013 | git tag tagname && | |
1014 | git describe --tags >expect && | |
1015 | git log -1 --format="%(describe:tags)" >actual && | |
1016 | test_cmp expect actual | |
1017 | ' | |
1018 | ||
eccd97d0 ES |
1019 | test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' ' |
1020 | test_when_finished "git tag -d tagname" && | |
1021 | git tag -a -m tagged tagname && | |
1022 | git describe --abbrev=15 >expect && | |
1023 | git log -1 --format="%(describe:abbrev=15)" >actual && | |
1024 | test_cmp expect actual | |
1025 | ' | |
1026 | ||
b49f309a PS |
1027 | test_expect_success 'log --pretty with space stealing' ' |
1028 | printf mm0 >expect && | |
1029 | git log -1 --pretty="format:mm%>>|(1)%x30" >actual && | |
1030 | test_cmp expect actual | |
1031 | ' | |
1032 | ||
f6e0b9f3 PS |
1033 | test_expect_success 'log --pretty with invalid padding format' ' |
1034 | printf "%s%%<(20" "$(git rev-parse HEAD)" >expect && | |
1035 | git log -1 --pretty="format:%H%<(20" >actual && | |
1036 | test_cmp expect actual | |
1037 | ' | |
1038 | ||
1de69c0c PS |
1039 | test_expect_success 'log --pretty with magical wrapping directives' ' |
1040 | commit_id=$(git commit-tree HEAD^{tree} -m "describe me") && | |
1041 | git tag describe-me $commit_id && | |
1042 | printf "\n(tag:\ndescribe-me)%%+w(2)" >expect && | |
1043 | git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual && | |
1044 | test_cmp expect actual | |
1045 | ' | |
1046 | ||
48050c42 | 1047 | test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing wrapping directive' ' |
304a50ad PS |
1048 | printf "%%w(2147483649,1,1)0" >expect && |
1049 | git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual && | |
1050 | test_cmp expect actual && | |
1051 | printf "%%w(1,2147483649,1)0" >expect && | |
1052 | git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual && | |
1053 | test_cmp expect actual && | |
1054 | printf "%%w(1,1,2147483649)0" >expect && | |
1055 | git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual && | |
1056 | test_cmp expect actual | |
1057 | ' | |
1058 | ||
1059 | test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing padding directive' ' | |
1060 | printf "%%<(2147483649)0" >expect && | |
1061 | git log -1 --pretty="format:%<(2147483649)%x30" >actual && | |
1062 | test_cmp expect actual | |
48050c42 PS |
1063 | ' |
1064 | ||
17d23e8a PS |
1065 | test_expect_success 'log --pretty with padding and preceding control chars' ' |
1066 | printf "\20\20 0" >expect && | |
1067 | git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual && | |
1068 | test_cmp expect actual | |
81c2d4c3 PS |
1069 | ' |
1070 | ||
1071 | test_expect_success 'log --pretty truncation with control chars' ' | |
1072 | test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars && | |
1073 | printf "\20\20\20\20x.." >expect && | |
1074 | git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual && | |
1075 | test_cmp expect actual | |
17d23e8a PS |
1076 | ' |
1077 | ||
81dc898d PS |
1078 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' |
1079 | # We only assert that this command does not crash. This needs to be | |
1080 | # executed with the address sanitizer to demonstrate failure. | |
1081 | git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null | |
1082 | ' | |
1083 | ||
1084 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' ' | |
1085 | test-tool genzeros 2147483649 | tr "\000" "1" >expect && | |
1086 | huge_commit=$(git commit-tree -F expect HEAD^{tree}) | |
1087 | ' | |
1088 | ||
1089 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' | |
1090 | git log -1 --format="%B%<(1)%x30" $huge_commit >actual && | |
1091 | echo 0 >>expect && | |
1092 | test_cmp expect actual | |
1093 | ' | |
1094 | ||
937b71cc PS |
1095 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message does not cause allocation failure' ' |
1096 | test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error && | |
1097 | cat >expect <<-EOF && | |
1098 | fatal: number too large to represent as int on this platform: 2147483649 | |
1099 | EOF | |
1100 | test_cmp expect error | |
1101 | ' | |
1102 | ||
540e7bc4 PO |
1103 | # pretty-formats note wide char limitations, and add tests |
1104 | test_expect_failure 'wide and decomposed characters column counting' ' | |
1105 | ||
1106 | # from t/lib-unicode-nfc-nfd.sh hex values converted to octal | |
1107 | utf8_nfc=$(printf "\303\251") && # e acute combined. | |
1108 | utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed) | |
1109 | utf8_emoji=$(printf "\360\237\221\250") && | |
1110 | ||
1111 | # replacement character when requesting a wide char fits in a single display colum. | |
1112 | # "half wide" alternative could be a plain ASCII dot `.` | |
1113 | utf8_vert_ell=$(printf "\342\213\256") && | |
1114 | ||
1115 | # use ${xxx} here! | |
1116 | nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" && | |
1117 | nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" && | |
1118 | emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" && | |
1119 | # emoji5 uses 10 display columns | |
1120 | ||
1121 | test_commit "abcdefghij" && | |
1122 | test_commit --no-tag "${nfc10}" && | |
1123 | test_commit --no-tag "${nfd10}" && | |
1124 | test_commit --no-tag "${emoji5}" && | |
1125 | printf "${utf8_emoji}..${utf8_emoji}${utf8_vert_ell}\n${utf8_nfd}..${utf8_nfd}${utf8_nfd}\n${utf8_nfc}..${utf8_nfc}${utf8_nfc}\na..ij\n" >expected && | |
1126 | git log --format="%<(5,mtrunc)%s" -4 >actual && | |
1127 | test_cmp expected actual | |
1128 | ' | |
1129 | ||
8028184e | 1130 | test_done |