]>
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 && | |
237ce762 | 165 | lf_to_nul <raw || 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 | ||
a58dd835 AK |
585 | test_expect_success 'pretty format %decorate' ' |
586 | git checkout -b foo && | |
587 | git commit --allow-empty -m "new commit" && | |
588 | git tag bar && | |
589 | git branch qux && | |
590 | ||
591 | echo " (HEAD -> foo, tag: bar, qux)" >expect1 && | |
592 | git log --format="%(decorate)" -1 >actual1 && | |
593 | test_cmp expect1 actual1 && | |
594 | ||
595 | echo "HEAD -> foo, tag: bar, qux" >expect2 && | |
596 | git log --format="%(decorate:prefix=,suffix=)" -1 >actual2 && | |
597 | test_cmp expect2 actual2 && | |
598 | ||
2b09d16a AK |
599 | echo "[ bar; qux; foo ]" >expect3 && |
600 | git log --format="%(decorate:prefix=[ ,suffix= ],separator=%x3B ,tag=)" \ | |
601 | --decorate-refs=refs/ -1 >actual3 && | |
a58dd835 AK |
602 | test_cmp expect3 actual3 && |
603 | ||
604 | # Try with a typo (in "separator"), in which case the placeholder should | |
605 | # not be replaced. | |
606 | echo "%(decorate:prefix=[ ,suffix= ],separater=; )" >expect4 && | |
607 | git log --format="%(decorate:prefix=[ ,suffix= ],separater=%x3B )" \ | |
608 | -1 >actual4 && | |
f1f8a258 AK |
609 | test_cmp expect4 actual4 && |
610 | ||
611 | echo "HEAD->foo bar qux" >expect5 && | |
612 | git log --format="%(decorate:prefix=,suffix=,separator= ,tag=,pointer=->)" \ | |
613 | -1 >actual5 && | |
614 | test_cmp expect5 actual5 | |
a58dd835 AK |
615 | ' |
616 | ||
d9f31fbf JK |
617 | cat >trailers <<EOF |
618 | Signed-off-by: A U Thor <author@example.com> | |
619 | Acked-by: A U Thor <author@example.com> | |
620 | [ v2 updated patch description ] | |
cc1735c4 JK |
621 | Signed-off-by: A U Thor |
622 | <author@example.com> | |
d9f31fbf JK |
623 | EOF |
624 | ||
58311c66 | 625 | unfold () { |
6f5c77a1 | 626 | perl -0pe 's/\n\s+/ /g' |
58311c66 JK |
627 | } |
628 | ||
cc1735c4 | 629 | test_expect_success 'set up trailer tests' ' |
d9f31fbf JK |
630 | echo "Some contents" >trailerfile && |
631 | git add trailerfile && | |
cc1735c4 | 632 | git commit -F - <<-EOF |
d9f31fbf JK |
633 | trailers: this commit message has trailers |
634 | ||
635 | This commit is a test commit with trailers at the end. We parse this | |
cc1735c4 | 636 | message and display the trailers using %(trailers). |
d9f31fbf JK |
637 | |
638 | $(cat trailers) | |
639 | EOF | |
cc1735c4 | 640 | ' |
d9f31fbf | 641 | |
cc1735c4 JK |
642 | test_expect_success 'pretty format %(trailers) shows trailers' ' |
643 | git log --no-walk --pretty="%(trailers)" >actual && | |
644 | { | |
645 | cat trailers && | |
646 | echo | |
647 | } >expect && | |
d9f31fbf JK |
648 | test_cmp expect actual |
649 | ' | |
650 | ||
8b966a05 ÆAB |
651 | test_expect_success 'pretty format %(trailers:) enables no options' ' |
652 | git log --no-walk --pretty="%(trailers:)" >actual && | |
653 | # "expect" the same as the test above | |
654 | test_cmp expect actual | |
655 | ' | |
656 | ||
58311c66 JK |
657 | test_expect_success '%(trailers:only) shows only "key: value" trailers' ' |
658 | git log --no-walk --pretty="%(trailers:only)" >actual && | |
659 | { | |
660 | grep -v patch.description <trailers && | |
661 | echo | |
662 | } >expect && | |
663 | test_cmp expect actual | |
664 | ' | |
665 | ||
4f732e0f AW |
666 | test_expect_success '%(trailers:only=yes) shows only "key: value" trailers' ' |
667 | git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && | |
668 | grep -v patch.description <trailers >expect && | |
669 | test_cmp expect actual | |
670 | ' | |
671 | ||
672 | test_expect_success '%(trailers:only=no) shows all trailers' ' | |
673 | git log --no-walk --pretty=format:"%(trailers:only=no)" >actual && | |
674 | cat trailers >expect && | |
675 | test_cmp expect actual | |
676 | ' | |
677 | ||
678 | test_expect_success '%(trailers:only=no,only=true) shows only "key: value" trailers' ' | |
679 | git log --no-walk --pretty=format:"%(trailers:only=yes)" >actual && | |
680 | grep -v patch.description <trailers >expect && | |
681 | test_cmp expect actual | |
58311c66 JK |
682 | ' |
683 | ||
684 | test_expect_success '%(trailers:unfold) unfolds trailers' ' | |
685 | git log --no-walk --pretty="%(trailers:unfold)" >actual && | |
686 | { | |
687 | unfold <trailers && | |
688 | echo | |
689 | } >expect && | |
690 | test_cmp expect actual | |
691 | ' | |
692 | ||
693 | test_expect_success ':only and :unfold work together' ' | |
84ff053d TB |
694 | git log --no-walk --pretty="%(trailers:only,unfold)" >actual && |
695 | git log --no-walk --pretty="%(trailers:unfold,only)" >reverse && | |
58311c66 JK |
696 | test_cmp actual reverse && |
697 | { | |
698 | grep -v patch.description <trailers | unfold && | |
699 | echo | |
700 | } >expect && | |
701 | test_cmp expect actual | |
702 | ' | |
703 | ||
250bea0c AW |
704 | test_expect_success 'pretty format %(trailers:key=foo) shows that trailer' ' |
705 | git log --no-walk --pretty="format:%(trailers:key=Acked-by)" >actual && | |
706 | echo "Acked-by: A U Thor <author@example.com>" >expect && | |
707 | test_cmp expect actual | |
708 | ' | |
709 | ||
710 | test_expect_success 'pretty format %(trailers:key=foo) is case insensitive' ' | |
711 | git log --no-walk --pretty="format:%(trailers:key=AcKed-bY)" >actual && | |
712 | echo "Acked-by: A U Thor <author@example.com>" >expect && | |
713 | test_cmp expect actual | |
714 | ' | |
715 | ||
716 | test_expect_success 'pretty format %(trailers:key=foo:) trailing colon also works' ' | |
717 | git log --no-walk --pretty="format:%(trailers:key=Acked-by:)" >actual && | |
718 | echo "Acked-by: A U Thor <author@example.com>" >expect && | |
719 | test_cmp expect actual | |
720 | ' | |
721 | ||
722 | test_expect_success 'pretty format %(trailers:key=foo) multiple keys' ' | |
723 | git log --no-walk --pretty="format:%(trailers:key=Acked-by:,key=Signed-off-By)" >actual && | |
724 | grep -v patch.description <trailers >expect && | |
725 | test_cmp expect actual | |
726 | ' | |
727 | ||
4dc8b1c1 | 728 | test_expect_success '%(trailers:key=nonexistent) becomes empty' ' |
250bea0c AW |
729 | git log --no-walk --pretty="x%(trailers:key=Nacked-by)x" >actual && |
730 | echo "xx" >expect && | |
731 | test_cmp expect actual | |
732 | ' | |
733 | ||
734 | test_expect_success '%(trailers:key=foo) handles multiple lines even if folded' ' | |
735 | git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by)" >actual && | |
736 | grep -v patch.description <trailers | grep -v Acked-by >expect && | |
737 | test_cmp expect actual | |
738 | ' | |
739 | ||
740 | test_expect_success '%(trailers:key=foo,unfold) properly unfolds' ' | |
741 | git log --no-walk --pretty="format:%(trailers:key=Signed-Off-by,unfold)" >actual && | |
742 | unfold <trailers | grep Signed-off-by >expect && | |
743 | test_cmp expect actual | |
744 | ' | |
745 | ||
746 | test_expect_success 'pretty format %(trailers:key=foo,only=no) also includes nontrailer lines' ' | |
747 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,only=no)" >actual && | |
748 | { | |
749 | echo "Acked-by: A U Thor <author@example.com>" && | |
750 | grep patch.description <trailers | |
751 | } >expect && | |
752 | test_cmp expect actual | |
753 | ' | |
754 | ||
755 | test_expect_success '%(trailers:key) without value is error' ' | |
756 | git log --no-walk --pretty="tformat:%(trailers:key)" >actual && | |
757 | echo "%(trailers:key)" >expect && | |
758 | test_cmp expect actual | |
759 | ' | |
760 | ||
9d87d5ae ÆAB |
761 | test_expect_success '%(trailers:keyonly) shows only keys' ' |
762 | git log --no-walk --pretty="format:%(trailers:keyonly)" >actual && | |
763 | test_write_lines \ | |
764 | "Signed-off-by" \ | |
765 | "Acked-by" \ | |
766 | "[ v2 updated patch description ]" \ | |
767 | "Signed-off-by" >expect && | |
768 | test_cmp expect actual | |
769 | ' | |
770 | ||
771 | test_expect_success '%(trailers:key=foo,keyonly) shows only key' ' | |
772 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly)" >actual && | |
773 | echo "Acked-by" >expect && | |
774 | test_cmp expect actual | |
775 | ' | |
776 | ||
d9b936db AW |
777 | test_expect_success '%(trailers:key=foo,valueonly) shows only value' ' |
778 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,valueonly)" >actual && | |
779 | echo "A U Thor <author@example.com>" >expect && | |
780 | test_cmp expect actual | |
781 | ' | |
782 | ||
8b966a05 ÆAB |
783 | test_expect_success '%(trailers:valueonly) shows only values' ' |
784 | git log --no-walk --pretty="format:%(trailers:valueonly)" >actual && | |
785 | test_write_lines \ | |
786 | "A U Thor <author@example.com>" \ | |
787 | "A U Thor <author@example.com>" \ | |
788 | "[ v2 updated patch description ]" \ | |
789 | "A U Thor" \ | |
790 | " <author@example.com>" >expect && | |
791 | test_cmp expect actual | |
792 | ' | |
793 | ||
9d87d5ae ÆAB |
794 | test_expect_success '%(trailers:key=foo,keyonly,valueonly) shows nothing' ' |
795 | git log --no-walk --pretty="format:%(trailers:key=Acked-by,keyonly,valueonly)" >actual && | |
796 | echo >expect && | |
797 | test_cmp expect actual | |
798 | ' | |
799 | ||
0b691d86 | 800 | test_expect_success 'pretty format %(trailers:separator) changes separator' ' |
8b966a05 ÆAB |
801 | git log --no-walk --pretty=format:"X%(trailers:separator=%x00)X" >actual && |
802 | ( | |
803 | printf "XSigned-off-by: A U Thor <author@example.com>\0" && | |
804 | printf "Acked-by: A U Thor <author@example.com>\0" && | |
805 | printf "[ v2 updated patch description ]\0" && | |
806 | printf "Signed-off-by: A U Thor\n <author@example.com>X" | |
807 | ) >expect && | |
808 | test_cmp expect actual | |
809 | ' | |
810 | ||
811 | test_expect_success 'pretty format %(trailers:separator=X,unfold) changes separator' ' | |
0b691d86 | 812 | git log --no-walk --pretty=format:"X%(trailers:separator=%x00,unfold)X" >actual && |
7c1f79fc ÆAB |
813 | ( |
814 | printf "XSigned-off-by: A U Thor <author@example.com>\0" && | |
815 | printf "Acked-by: A U Thor <author@example.com>\0" && | |
816 | printf "[ v2 updated patch description ]\0" && | |
817 | printf "Signed-off-by: A U Thor <author@example.com>X" | |
818 | ) >expect && | |
0b691d86 | 819 | test_cmp expect actual |
058761f1 ÆAB |
820 | ' |
821 | ||
822 | test_expect_success 'pretty format %(trailers:key_value_separator) changes key-value separator' ' | |
823 | git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00)X" >actual && | |
824 | ( | |
825 | printf "XSigned-off-by\0A U Thor <author@example.com>\n" && | |
826 | printf "Acked-by\0A U Thor <author@example.com>\n" && | |
827 | printf "[ v2 updated patch description ]\n" && | |
828 | printf "Signed-off-by\0A U Thor\n <author@example.com>\nX" | |
829 | ) >expect && | |
830 | test_cmp expect actual | |
831 | ' | |
832 | ||
833 | test_expect_success 'pretty format %(trailers:key_value_separator,unfold) changes key-value separator' ' | |
834 | git log --no-walk --pretty=format:"X%(trailers:key_value_separator=%x00,unfold)X" >actual && | |
835 | ( | |
836 | printf "XSigned-off-by\0A U Thor <author@example.com>\n" && | |
837 | printf "Acked-by\0A U Thor <author@example.com>\n" && | |
838 | printf "[ v2 updated patch description ]\n" && | |
839 | printf "Signed-off-by\0A U Thor <author@example.com>\nX" | |
840 | ) >expect && | |
841 | test_cmp expect actual | |
842 | ' | |
843 | ||
844 | test_expect_success 'pretty format %(trailers:separator,key_value_separator) changes both separators' ' | |
845 | git log --no-walk --pretty=format:"%(trailers:separator=%x00,key_value_separator=%x00%x00,unfold)" >actual && | |
846 | ( | |
847 | printf "Signed-off-by\0\0A U Thor <author@example.com>\0" && | |
848 | printf "Acked-by\0\0A U Thor <author@example.com>\0" && | |
849 | printf "[ v2 updated patch description ]\0" && | |
850 | printf "Signed-off-by\0\0A U Thor <author@example.com>" | |
851 | ) >expect && | |
852 | test_cmp expect actual | |
0b691d86 AW |
853 | ' |
854 | ||
9d87d5ae | 855 | test_expect_success 'pretty format %(trailers) combining separator/key/keyonly/valueonly' ' |
0b691d86 AW |
856 | git commit --allow-empty -F - <<-\EOF && |
857 | Important fix | |
858 | ||
859 | The fix is explained here | |
860 | ||
861 | Closes: #1234 | |
862 | EOF | |
863 | ||
864 | git commit --allow-empty -F - <<-\EOF && | |
865 | Another fix | |
866 | ||
867 | The fix is explained here | |
868 | ||
869 | Closes: #567 | |
870 | Closes: #890 | |
871 | EOF | |
872 | ||
873 | git commit --allow-empty -F - <<-\EOF && | |
874 | Does not close any tickets | |
875 | EOF | |
876 | ||
877 | git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,valueonly)" HEAD~3.. >actual && | |
878 | test_write_lines \ | |
879 | "Does not close any tickets" \ | |
880 | "Another fix #567, #890" \ | |
881 | "Important fix #1234" >expect && | |
9d87d5ae ÆAB |
882 | test_cmp expect actual && |
883 | ||
884 | git log --pretty="%s% (trailers:separator=%x2c%x20,key=Closes,keyonly)" HEAD~3.. >actual && | |
885 | test_write_lines \ | |
886 | "Does not close any tickets" \ | |
887 | "Another fix Closes, Closes" \ | |
888 | "Important fix Closes" >expect && | |
0b691d86 AW |
889 | test_cmp expect actual |
890 | ' | |
891 | ||
e5fba5d5 JK |
892 | test_expect_success 'trailer parsing not fooled by --- line' ' |
893 | git commit --allow-empty -F - <<-\EOF && | |
894 | this is the subject | |
895 | ||
896 | This is the body. The message has a "---" line which would confuse a | |
897 | message+patch parser. But here we know we have only a commit message, | |
898 | so we get it right. | |
899 | ||
900 | trailer: wrong | |
901 | --- | |
902 | This is more body. | |
903 | ||
904 | trailer: right | |
905 | EOF | |
906 | ||
907 | { | |
908 | echo "trailer: right" && | |
909 | echo | |
910 | } >expect && | |
911 | git log --no-walk --format="%(trailers)" >actual && | |
912 | test_cmp expect actual | |
913 | ' | |
914 | ||
ad6f028f IT |
915 | test_expect_success 'set up %S tests' ' |
916 | git checkout --orphan source-a && | |
917 | test_commit one && | |
918 | test_commit two && | |
919 | git checkout -b source-b HEAD^ && | |
920 | test_commit three | |
921 | ' | |
922 | ||
923 | test_expect_success 'log --format=%S paints branch names' ' | |
924 | cat >expect <<-\EOF && | |
925 | source-b | |
926 | source-a | |
927 | source-b | |
928 | EOF | |
929 | git log --format=%S source-a source-b >actual && | |
930 | test_cmp expect actual | |
931 | ' | |
932 | ||
933 | test_expect_success 'log --format=%S paints tag names' ' | |
934 | git tag -m tagged source-tag && | |
935 | cat >expect <<-\EOF && | |
936 | source-tag | |
937 | source-a | |
938 | source-tag | |
939 | EOF | |
940 | git log --format=%S source-tag source-a >actual && | |
941 | test_cmp expect actual | |
942 | ' | |
943 | ||
944 | test_expect_success 'log --format=%S paints symmetric ranges' ' | |
945 | cat >expect <<-\EOF && | |
946 | source-b | |
947 | source-a | |
948 | EOF | |
949 | git log --format=%S source-a...source-b >actual && | |
950 | test_cmp expect actual | |
951 | ' | |
952 | ||
953 | test_expect_success '%S in git log --format works with other placeholders (part 1)' ' | |
954 | git log --format="source-b %h" source-b >expect && | |
955 | git log --format="%S %h" source-b >actual && | |
956 | test_cmp expect actual | |
957 | ' | |
958 | ||
959 | test_expect_success '%S in git log --format works with other placeholders (part 2)' ' | |
960 | git log --format="%h source-b" source-b >expect && | |
961 | git log --format="%h %S" source-b >actual && | |
962 | test_cmp expect actual | |
963 | ' | |
964 | ||
5305474e VD |
965 | test_expect_success 'setup more commits for %S with --bisect' ' |
966 | test_commit four && | |
967 | test_commit five && | |
968 | ||
969 | head1=$(git rev-parse --verify HEAD~0) && | |
970 | head2=$(git rev-parse --verify HEAD~1) && | |
971 | head3=$(git rev-parse --verify HEAD~2) && | |
972 | head4=$(git rev-parse --verify HEAD~3) | |
973 | ' | |
974 | ||
975 | test_expect_success '%S with --bisect labels commits with refs/bisect/bad ref' ' | |
976 | git update-ref refs/bisect/bad-$head1 $head1 && | |
977 | git update-ref refs/bisect/go $head1 && | |
978 | git update-ref refs/bisect/bad-$head2 $head2 && | |
979 | git update-ref refs/bisect/b $head3 && | |
980 | git update-ref refs/bisect/bad-$head4 $head4 && | |
981 | git update-ref refs/bisect/good-$head4 $head4 && | |
982 | ||
983 | # We expect to see the range of commits betwee refs/bisect/good-$head4 | |
984 | # and refs/bisect/bad-$head1. The "source" ref is the nearest bisect ref | |
985 | # from which the commit is reachable. | |
986 | cat >expect <<-EOF && | |
987 | $head1 refs/bisect/bad-$head1 | |
988 | $head2 refs/bisect/bad-$head2 | |
989 | $head3 refs/bisect/bad-$head2 | |
990 | EOF | |
991 | git log --bisect --format="%H %S" >actual && | |
992 | test_cmp expect actual | |
993 | ' | |
994 | ||
1f0fc1db DL |
995 | test_expect_success 'log --pretty=reference' ' |
996 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
997 | git log --pretty=reference >actual && | |
998 | test_cmp expect actual | |
999 | ' | |
1000 | ||
1001 | test_expect_success 'log --pretty=reference with log.date is overridden by short date' ' | |
1002 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
1003 | test_config log.date rfc && | |
1004 | git log --pretty=reference >actual && | |
1005 | test_cmp expect actual | |
1006 | ' | |
1007 | ||
1008 | test_expect_success 'log --pretty=reference with explicit date overrides short date' ' | |
1009 | git log --date=rfc --pretty="tformat:%h (%s, %ad)" >expect && | |
1010 | git log --date=rfc --pretty=reference >actual && | |
1011 | test_cmp expect actual | |
1012 | ' | |
1013 | ||
1014 | test_expect_success 'log --pretty=reference is never unabbreviated' ' | |
1015 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
1016 | git log --no-abbrev-commit --pretty=reference >actual && | |
1017 | test_cmp expect actual | |
1018 | ' | |
1019 | ||
1020 | test_expect_success 'log --pretty=reference is never decorated' ' | |
1021 | git log --pretty="tformat:%h (%s, %as)" >expect && | |
1022 | git log --decorate=short --pretty=reference >actual && | |
1023 | test_cmp expect actual | |
1024 | ' | |
1025 | ||
1026 | test_expect_success 'log --pretty=reference does not output reflog info' ' | |
1027 | git log --walk-reflogs --pretty="tformat:%h (%s, %as)" >expect && | |
1028 | git log --walk-reflogs --pretty=reference >actual && | |
1029 | test_cmp expect actual | |
1030 | ' | |
1031 | ||
1032 | test_expect_success 'log --pretty=reference is colored appropriately' ' | |
1033 | git log --color=always --pretty="tformat:%C(auto)%h (%s, %as)" >expect && | |
1034 | git log --color=always --pretty=reference >actual && | |
1035 | test_cmp expect actual | |
1036 | ' | |
1037 | ||
15ae82d5 RS |
1038 | test_expect_success '%(describe) vs git describe' ' |
1039 | git log --format="%H" | while read hash | |
1040 | do | |
09fe8ca9 RS |
1041 | if desc=$(git describe $hash) |
1042 | then | |
1043 | : >expect-contains-good | |
1044 | else | |
1045 | : >expect-contains-bad | |
1046 | fi && | |
cbe1d9d6 | 1047 | echo "$hash $desc" || return 1 |
15ae82d5 | 1048 | done >expect && |
09fe8ca9 RS |
1049 | test_path_exists expect-contains-good && |
1050 | test_path_exists expect-contains-bad && | |
1051 | ||
15ae82d5 RS |
1052 | git log --format="%H %(describe)" >actual 2>err && |
1053 | test_cmp expect actual && | |
1054 | test_must_be_empty err | |
1055 | ' | |
1056 | ||
b081547e RS |
1057 | test_expect_success '%(describe:match=...) vs git describe --match ...' ' |
1058 | test_when_finished "git tag -d tag-match" && | |
52ff891c | 1059 | git tag -a -m tagged tag-match && |
b081547e RS |
1060 | git describe --match "*-match" >expect && |
1061 | git log -1 --format="%(describe:match=*-match)" >actual && | |
1062 | test_cmp expect actual | |
1063 | ' | |
1064 | ||
1065 | test_expect_success '%(describe:exclude=...) vs git describe --exclude ...' ' | |
1066 | test_when_finished "git tag -d tag-exclude" && | |
1067 | git tag -a -m tagged tag-exclude && | |
1068 | git describe --exclude "*-exclude" >expect && | |
1069 | git log -1 --format="%(describe:exclude=*-exclude)" >actual && | |
1070 | test_cmp expect actual | |
1071 | ' | |
1072 | ||
1d517cea ES |
1073 | test_expect_success '%(describe:tags) vs git describe --tags' ' |
1074 | test_when_finished "git tag -d tagname" && | |
1075 | git tag tagname && | |
1076 | git describe --tags >expect && | |
1077 | git log -1 --format="%(describe:tags)" >actual && | |
1078 | test_cmp expect actual | |
1079 | ' | |
1080 | ||
eccd97d0 ES |
1081 | test_expect_success '%(describe:abbrev=...) vs git describe --abbrev=...' ' |
1082 | test_when_finished "git tag -d tagname" && | |
1876a5ae KS |
1083 | |
1084 | # Case 1: We have commits between HEAD and the most recent tag | |
1085 | # reachable from it | |
1086 | test_commit --no-tag file && | |
1087 | git describe --abbrev=15 >expect && | |
1088 | git log -1 --format="%(describe:abbrev=15)" >actual && | |
1089 | test_cmp expect actual && | |
1090 | ||
1091 | # Make sure the hash used is at least 15 digits long | |
1092 | sed -e "s/^.*-g\([0-9a-f]*\)$/\1/" <actual >hexpart && | |
1093 | test 16 -le $(wc -c <hexpart) && | |
1094 | ||
1095 | # Case 2: We have a tag at HEAD, describe directly gives the | |
1096 | # name of the tag | |
eccd97d0 ES |
1097 | git tag -a -m tagged tagname && |
1098 | git describe --abbrev=15 >expect && | |
1099 | git log -1 --format="%(describe:abbrev=15)" >actual && | |
1876a5ae KS |
1100 | test_cmp expect actual && |
1101 | test tagname = $(cat actual) | |
eccd97d0 ES |
1102 | ' |
1103 | ||
b49f309a PS |
1104 | test_expect_success 'log --pretty with space stealing' ' |
1105 | printf mm0 >expect && | |
1106 | git log -1 --pretty="format:mm%>>|(1)%x30" >actual && | |
1107 | test_cmp expect actual | |
1108 | ' | |
1109 | ||
f6e0b9f3 PS |
1110 | test_expect_success 'log --pretty with invalid padding format' ' |
1111 | printf "%s%%<(20" "$(git rev-parse HEAD)" >expect && | |
1112 | git log -1 --pretty="format:%H%<(20" >actual && | |
1113 | test_cmp expect actual | |
1114 | ' | |
1115 | ||
1de69c0c PS |
1116 | test_expect_success 'log --pretty with magical wrapping directives' ' |
1117 | commit_id=$(git commit-tree HEAD^{tree} -m "describe me") && | |
1118 | git tag describe-me $commit_id && | |
1119 | printf "\n(tag:\ndescribe-me)%%+w(2)" >expect && | |
1120 | git log -1 --pretty="format:%w(1)%+d%+w(2)" $commit_id >actual && | |
1121 | test_cmp expect actual | |
1122 | ' | |
1123 | ||
48050c42 | 1124 | test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing wrapping directive' ' |
304a50ad PS |
1125 | printf "%%w(2147483649,1,1)0" >expect && |
1126 | git log -1 --pretty="format:%w(2147483649,1,1)%x30" >actual && | |
1127 | test_cmp expect actual && | |
1128 | printf "%%w(1,2147483649,1)0" >expect && | |
1129 | git log -1 --pretty="format:%w(1,2147483649,1)%x30" >actual && | |
1130 | test_cmp expect actual && | |
1131 | printf "%%w(1,1,2147483649)0" >expect && | |
1132 | git log -1 --pretty="format:%w(1,1,2147483649)%x30" >actual && | |
1133 | test_cmp expect actual | |
1134 | ' | |
1135 | ||
1136 | test_expect_success SIZE_T_IS_64BIT 'log --pretty with overflowing padding directive' ' | |
1137 | printf "%%<(2147483649)0" >expect && | |
1138 | git log -1 --pretty="format:%<(2147483649)%x30" >actual && | |
1139 | test_cmp expect actual | |
48050c42 PS |
1140 | ' |
1141 | ||
17d23e8a PS |
1142 | test_expect_success 'log --pretty with padding and preceding control chars' ' |
1143 | printf "\20\20 0" >expect && | |
1144 | git log -1 --pretty="format:%x10%x10%>|(4)%x30" >actual && | |
1145 | test_cmp expect actual | |
81c2d4c3 PS |
1146 | ' |
1147 | ||
1148 | test_expect_success 'log --pretty truncation with control chars' ' | |
1149 | test_commit "$(printf "\20\20\20\20xxxx")" file contents commit-with-control-chars && | |
1150 | printf "\20\20\20\20x.." >expect && | |
1151 | git log -1 --pretty="format:%<(3,trunc)%s" commit-with-control-chars >actual && | |
1152 | test_cmp expect actual | |
17d23e8a PS |
1153 | ' |
1154 | ||
81dc898d PS |
1155 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' |
1156 | # We only assert that this command does not crash. This needs to be | |
1157 | # executed with the address sanitizer to demonstrate failure. | |
1158 | git log -1 --pretty="format:%>(2147483646)%x41%41%>(2147483646)%x41" >/dev/null | |
1159 | ' | |
1160 | ||
1161 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'set up huge commit' ' | |
1162 | test-tool genzeros 2147483649 | tr "\000" "1" >expect && | |
1163 | huge_commit=$(git commit-tree -F expect HEAD^{tree}) | |
1164 | ' | |
1165 | ||
1166 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message' ' | |
1167 | git log -1 --format="%B%<(1)%x30" $huge_commit >actual && | |
1168 | echo 0 >>expect && | |
1169 | test_cmp expect actual | |
1170 | ' | |
1171 | ||
937b71cc PS |
1172 | test_expect_success EXPENSIVE,SIZE_T_IS_64BIT 'log --pretty with huge commit message does not cause allocation failure' ' |
1173 | test_must_fail git log -1 --format="%<(1)%B" $huge_commit 2>error && | |
1174 | cat >expect <<-EOF && | |
1175 | fatal: number too large to represent as int on this platform: 2147483649 | |
1176 | EOF | |
1177 | test_cmp expect error | |
1178 | ' | |
1179 | ||
540e7bc4 PO |
1180 | # pretty-formats note wide char limitations, and add tests |
1181 | test_expect_failure 'wide and decomposed characters column counting' ' | |
1182 | ||
1183 | # from t/lib-unicode-nfc-nfd.sh hex values converted to octal | |
1184 | utf8_nfc=$(printf "\303\251") && # e acute combined. | |
1185 | utf8_nfd=$(printf "\145\314\201") && # e with a combining acute (i.e. decomposed) | |
1186 | utf8_emoji=$(printf "\360\237\221\250") && | |
1187 | ||
1188 | # replacement character when requesting a wide char fits in a single display colum. | |
1189 | # "half wide" alternative could be a plain ASCII dot `.` | |
1190 | utf8_vert_ell=$(printf "\342\213\256") && | |
1191 | ||
1192 | # use ${xxx} here! | |
1193 | nfc10="${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}${utf8_nfc}" && | |
1194 | nfd10="${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}${utf8_nfd}" && | |
1195 | emoji5="${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}${utf8_emoji}" && | |
1196 | # emoji5 uses 10 display columns | |
1197 | ||
1198 | test_commit "abcdefghij" && | |
1199 | test_commit --no-tag "${nfc10}" && | |
1200 | test_commit --no-tag "${nfd10}" && | |
1201 | test_commit --no-tag "${emoji5}" && | |
1202 | 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 && | |
1203 | git log --format="%<(5,mtrunc)%s" -4 >actual && | |
1204 | test_cmp expected actual | |
1205 | ' | |
1206 | ||
8028184e | 1207 | test_done |