]>
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 && |
b354f11b | 126 | test_i18ncmp expected actual |
fafd3829 JH |
127 | ' |
128 | ||
129 | test_expect_failure 'NUL termination with --stat' ' | |
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 && |
b354f11b | 134 | test_i18ncmp expected actual |
fafd3829 JH |
135 | ' |
136 | ||
a5752342 NTND |
137 | test_expect_success 'setup more commits' ' |
138 | test_commit "message one" one one message-one && | |
a742f2a0 AS |
139 | test_commit "message two" two two message-two && |
140 | head1=$(git rev-parse --verify --short HEAD~0) && | |
141 | head2=$(git rev-parse --verify --short HEAD~1) && | |
142 | head3=$(git rev-parse --verify --short HEAD~2) && | |
143 | head4=$(git rev-parse --verify --short HEAD~3) | |
a5752342 NTND |
144 | ' |
145 | ||
f3445f78 | 146 | test_expect_success 'left alignment formatting' ' |
c82134a9 | 147 | git log --pretty="tformat:%<(40)%s" >actual && |
f3445f78 | 148 | qz_to_tab_space <<EOF >expected && |
a5752342 NTND |
149 | message two Z |
150 | message one Z | |
151 | add bar Z | |
de6029a2 | 152 | $(commit_msg) Z |
a5752342 NTND |
153 | EOF |
154 | test_cmp expected actual | |
f3445f78 | 155 | ' |
a5752342 | 156 | |
d928d810 AS |
157 | test_expect_success 'left alignment formatting. i18n.logOutputEncoding' ' |
158 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(40)%s" >actual && | |
159 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
160 | message two Z | |
161 | message one Z | |
162 | add bar Z | |
163 | $(commit_msg) Z | |
164 | EOF | |
165 | test_cmp expected actual | |
166 | ' | |
167 | ||
f3445f78 | 168 | test_expect_success 'left alignment formatting at the nth column' ' |
c82134a9 | 169 | git log --pretty="tformat:%h %<|(40)%s" >actual && |
f3445f78 | 170 | qz_to_tab_space <<EOF >expected && |
a742f2a0 AS |
171 | $head1 message two Z |
172 | $head2 message one Z | |
173 | $head3 add bar Z | |
de6029a2 | 174 | $head4 $(commit_msg) Z |
a5752342 NTND |
175 | EOF |
176 | test_cmp expected actual | |
f3445f78 | 177 | ' |
a5752342 | 178 | |
d928d810 AS |
179 | test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' ' |
180 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual && | |
181 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
182 | $head1 message two Z | |
183 | $head2 message one Z | |
184 | $head3 add bar Z | |
185 | $head4 $(commit_msg) Z | |
186 | EOF | |
187 | test_cmp expected actual | |
188 | ' | |
189 | ||
f3445f78 | 190 | test_expect_success 'left alignment formatting with no padding' ' |
c82134a9 | 191 | git log --pretty="tformat:%<(1)%s" >actual && |
f3445f78 | 192 | cat <<EOF >expected && |
a5752342 NTND |
193 | message two |
194 | message one | |
195 | add bar | |
de6029a2 | 196 | $(commit_msg) |
a5752342 NTND |
197 | EOF |
198 | test_cmp expected actual | |
f3445f78 | 199 | ' |
a5752342 | 200 | |
d928d810 AS |
201 | test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' ' |
202 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual && | |
203 | cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
204 | message two | |
205 | message one | |
206 | add bar | |
207 | $(commit_msg) | |
208 | EOF | |
209 | test_cmp expected actual | |
210 | ' | |
211 | ||
f3445f78 | 212 | test_expect_success 'left alignment formatting with trunc' ' |
c82134a9 | 213 | git log --pretty="tformat:%<(10,trunc)%s" >actual && |
f3445f78 | 214 | qz_to_tab_space <<EOF >expected && |
a7f01c6b NTND |
215 | message .. |
216 | message .. | |
217 | add bar Z | |
37eb772e | 218 | initial... |
a7f01c6b NTND |
219 | EOF |
220 | test_cmp expected actual | |
f3445f78 | 221 | ' |
a7f01c6b | 222 | |
7d509878 | 223 | test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' ' |
d928d810 AS |
224 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual && |
225 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
226 | message .. | |
227 | message .. | |
228 | add bar Z | |
229 | initial... | |
230 | EOF | |
231 | test_cmp expected actual | |
232 | ' | |
233 | ||
f3445f78 | 234 | test_expect_success 'left alignment formatting with ltrunc' ' |
c82134a9 | 235 | git log --pretty="tformat:%<(10,ltrunc)%s" >actual && |
f3445f78 | 236 | qz_to_tab_space <<EOF >expected && |
a7f01c6b NTND |
237 | ..sage two |
238 | ..sage one | |
239 | add bar Z | |
37eb772e | 240 | ..${sample_utf8_part}lich |
a7f01c6b NTND |
241 | EOF |
242 | test_cmp expected actual | |
f3445f78 | 243 | ' |
a7f01c6b | 244 | |
7d509878 | 245 | test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' ' |
d928d810 AS |
246 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual && |
247 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
248 | ..sage two | |
249 | ..sage one | |
250 | add bar Z | |
251 | ..${sample_utf8_part}lich | |
252 | EOF | |
253 | test_cmp expected actual | |
254 | ' | |
255 | ||
f3445f78 | 256 | test_expect_success 'left alignment formatting with mtrunc' ' |
c82134a9 | 257 | git log --pretty="tformat:%<(10,mtrunc)%s" >actual && |
f3445f78 | 258 | qz_to_tab_space <<EOF >expected && |
a7f01c6b NTND |
259 | mess.. two |
260 | mess.. one | |
261 | add bar Z | |
37eb772e | 262 | init..lich |
a7f01c6b NTND |
263 | EOF |
264 | test_cmp expected actual | |
f3445f78 | 265 | ' |
a7f01c6b | 266 | |
7d509878 | 267 | test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' ' |
d928d810 AS |
268 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual && |
269 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
270 | mess.. two | |
271 | mess.. one | |
272 | add bar Z | |
273 | init..lich | |
274 | EOF | |
275 | test_cmp expected actual | |
276 | ' | |
277 | ||
f3445f78 | 278 | test_expect_success 'right alignment formatting' ' |
c82134a9 | 279 | git log --pretty="tformat:%>(40)%s" >actual && |
f3445f78 | 280 | qz_to_tab_space <<EOF >expected && |
a5752342 NTND |
281 | Z message two |
282 | Z message one | |
283 | Z add bar | |
de6029a2 | 284 | Z $(commit_msg) |
a5752342 NTND |
285 | EOF |
286 | test_cmp expected actual | |
f3445f78 | 287 | ' |
a5752342 | 288 | |
d928d810 AS |
289 | test_expect_success 'right alignment formatting. i18n.logOutputEncoding' ' |
290 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual && | |
291 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
292 | Z message two | |
293 | Z message one | |
294 | Z add bar | |
295 | Z $(commit_msg) | |
296 | EOF | |
297 | test_cmp expected actual | |
298 | ' | |
299 | ||
f3445f78 | 300 | test_expect_success 'right alignment formatting at the nth column' ' |
c82134a9 | 301 | git log --pretty="tformat:%h %>|(40)%s" >actual && |
f3445f78 | 302 | qz_to_tab_space <<EOF >expected && |
a742f2a0 AS |
303 | $head1 message two |
304 | $head2 message one | |
305 | $head3 add bar | |
de6029a2 | 306 | $head4 $(commit_msg) |
a5752342 NTND |
307 | EOF |
308 | test_cmp expected actual | |
f3445f78 | 309 | ' |
a5752342 | 310 | |
d928d810 AS |
311 | test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' ' |
312 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual && | |
313 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
314 | $head1 message two | |
315 | $head2 message one | |
316 | $head3 add bar | |
317 | $head4 $(commit_msg) | |
318 | EOF | |
319 | test_cmp expected actual | |
320 | ' | |
321 | ||
f3445f78 | 322 | test_expect_success 'right alignment formatting with no padding' ' |
c82134a9 | 323 | git log --pretty="tformat:%>(1)%s" >actual && |
f3445f78 | 324 | cat <<EOF >expected && |
a5752342 NTND |
325 | message two |
326 | message one | |
327 | add bar | |
de6029a2 | 328 | $(commit_msg) |
a5752342 NTND |
329 | EOF |
330 | test_cmp expected actual | |
f3445f78 | 331 | ' |
a5752342 | 332 | |
d928d810 AS |
333 | test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' ' |
334 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual && | |
335 | cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
336 | message two | |
337 | message one | |
338 | add bar | |
339 | $(commit_msg) | |
340 | EOF | |
341 | test_cmp expected actual | |
342 | ' | |
343 | ||
f3445f78 | 344 | test_expect_success 'center alignment formatting' ' |
c82134a9 | 345 | git log --pretty="tformat:%><(40)%s" >actual && |
f3445f78 | 346 | qz_to_tab_space <<EOF >expected && |
a5752342 NTND |
347 | Z message two Z |
348 | Z message one Z | |
349 | Z add bar Z | |
de6029a2 | 350 | Z $(commit_msg) Z |
a5752342 NTND |
351 | EOF |
352 | test_cmp expected actual | |
f3445f78 | 353 | ' |
a5752342 | 354 | |
d928d810 AS |
355 | test_expect_success 'center alignment formatting. i18n.logOutputEncoding' ' |
356 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual && | |
357 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
358 | Z message two Z | |
359 | Z message one Z | |
360 | Z add bar Z | |
361 | Z $(commit_msg) Z | |
362 | EOF | |
363 | test_cmp expected actual | |
364 | ' | |
f3445f78 | 365 | test_expect_success 'center alignment formatting at the nth column' ' |
c82134a9 | 366 | git log --pretty="tformat:%h %><|(40)%s" >actual && |
f3445f78 | 367 | qz_to_tab_space <<EOF >expected && |
a742f2a0 AS |
368 | $head1 message two Z |
369 | $head2 message one Z | |
370 | $head3 add bar Z | |
de6029a2 | 371 | $head4 $(commit_msg) Z |
a5752342 NTND |
372 | EOF |
373 | test_cmp expected actual | |
f3445f78 | 374 | ' |
a5752342 | 375 | |
d928d810 AS |
376 | test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' ' |
377 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual && | |
378 | qz_to_tab_space <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
379 | $head1 message two Z | |
380 | $head2 message one Z | |
381 | $head3 add bar Z | |
382 | $head4 $(commit_msg) Z | |
383 | EOF | |
384 | test_cmp expected actual | |
385 | ' | |
386 | ||
f3445f78 | 387 | test_expect_success 'center alignment formatting with no padding' ' |
c82134a9 | 388 | git log --pretty="tformat:%><(1)%s" >actual && |
f3445f78 | 389 | cat <<EOF >expected && |
a5752342 NTND |
390 | message two |
391 | message one | |
392 | add bar | |
de6029a2 | 393 | $(commit_msg) |
a5752342 NTND |
394 | EOF |
395 | test_cmp expected actual | |
f3445f78 | 396 | ' |
a5752342 | 397 | |
496a6980 AS |
398 | # save HEAD's SHA-1 digest (with no abbreviations) to use it below |
399 | # as far as the next test amends HEAD | |
400 | old_head1=$(git rev-parse --verify HEAD~0) | |
d928d810 AS |
401 | test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' ' |
402 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual && | |
403 | cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
404 | message two | |
405 | message one | |
406 | add bar | |
407 | $(commit_msg) | |
408 | EOF | |
409 | test_cmp expected actual | |
410 | ' | |
496a6980 | 411 | |
f3445f78 AS |
412 | test_expect_success 'left/right alignment formatting with stealing' ' |
413 | git commit --amend -m short --author "long long long <long@me.com>" && | |
c82134a9 | 414 | git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && |
f3445f78 | 415 | cat <<EOF >expected && |
1640632b NTND |
416 | short long long long |
417 | message .. A U Thor | |
418 | add bar A U Thor | |
37eb772e | 419 | initial... A U Thor |
1640632b NTND |
420 | EOF |
421 | test_cmp expected actual | |
f3445f78 | 422 | ' |
7d509878 | 423 | test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' ' |
d928d810 AS |
424 | git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && |
425 | cat <<EOF | iconv -f utf-8 -t $test_encoding >expected && | |
426 | short long long long | |
427 | message .. A U Thor | |
428 | add bar A U Thor | |
429 | initial... A U Thor | |
430 | EOF | |
431 | test_cmp expected actual | |
432 | ' | |
1640632b | 433 | |
496a6980 AS |
434 | # get new digests (with no abbreviations) |
435 | head1=$(git rev-parse --verify HEAD~0) && | |
436 | head2=$(git rev-parse --verify HEAD~1) && | |
437 | ||
5e1361cc | 438 | test_expect_success 'log decoration properly follows tag chain' ' |
439 | git tag -a tag1 -m tag1 && | |
440 | git tag -a tag2 -m tag2 tag1 && | |
441 | git tag -d tag1 && | |
442 | git commit --amend -m shorter && | |
443 | git log --no-walk --tags --pretty="%H %d" --decorate=full >actual && | |
444 | cat <<EOF >expected && | |
496a6980 AS |
445 | $head1 (tag: refs/tags/tag2) |
446 | $head2 (tag: refs/tags/message-one) | |
447 | $old_head1 (tag: refs/tags/message-two) | |
5e1361cc | 448 | EOF |
449 | sort actual >actual1 && | |
450 | test_cmp expected actual1 | |
451 | ' | |
452 | ||
9271095c HJ |
453 | test_expect_success 'clean log decoration' ' |
454 | git log --no-walk --tags --pretty="%H %D" --decorate=full >actual && | |
455 | cat >expected <<EOF && | |
456 | $head1 tag: refs/tags/tag2 | |
457 | $head2 tag: refs/tags/message-one | |
458 | $old_head1 tag: refs/tags/message-two | |
459 | EOF | |
460 | sort actual >actual1 && | |
461 | test_cmp expected actual1 | |
462 | ' | |
463 | ||
8028184e | 464 | test_done |