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