3 # Copyright (c) 2010, Will Palmer
4 # Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
7 test_description='Test pretty formats'
10 # Tested non-UTF-8 encoding
11 test_encoding="ISO8859-1"
13 sample_utf8_part=$(printf "f\303\244ng")
16 # String "initial. initial" partly in German
17 # (translated with Google Translate),
18 # encoded in UTF-8, used as a commit log message below.
19 msg="initial. an${sample_utf8_part}lich\n"
22 printf "$msg" | iconv -f utf-8 -t "$1"
28 test_expect_success 'set up basic repos' '
33 git config i18n.commitEncoding $test_encoding &&
34 commit_msg $test_encoding | git commit -F - &&
37 git commit -m "add bar" &&
38 git config --unset i18n.commitEncoding
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
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
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
62 test_expect_success 'alias user-defined tformat with %s (ISO8859-1 encoding)' '
63 git config i18n.logOutputEncoding $test_encoding &&
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
70 test_expect_success 'alias user-defined tformat with %s (utf-8 encoding)' '
71 git log --oneline >expected-s &&
72 git log --pretty="tformat:%h %s" >actual-s &&
73 test_cmp expected-s actual-s
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
83 test_expect_success 'alias non-existent format' '
84 git config pretty.test-alias format-that-will-never-exist &&
85 test_must_fail git log --pretty=test-alias
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
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
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
109 test_expect_success 'NUL separation' '
110 printf "add bar\0$(commit_msg)" >expected &&
111 git log -z --pretty="format:%s" >actual &&
112 test_cmp expected actual
115 test_expect_success 'NUL termination' '
116 printf "add bar\0$(commit_msg)\0" >expected &&
117 git log -z --pretty="tformat:%s" >actual &&
118 test_cmp expected actual
121 test_expect_success 'NUL separation with --stat' '
122 stat0_part=$(git diff --stat HEAD^ HEAD) &&
123 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
124 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
125 git log -z --stat --pretty="format:%s" >actual &&
126 test_i18ncmp expected actual
129 test_expect_failure C_LOCALE_OUTPUT 'NUL termination with --stat' '
130 stat0_part=$(git diff --stat HEAD^ HEAD) &&
131 stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
132 printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
133 git log -z --stat --pretty="tformat:%s" >actual &&
134 test_cmp expected actual
137 test_expect_success 'setup more commits' '
138 test_commit "message one" one one message-one &&
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)
146 test_expect_success 'left alignment formatting' '
147 git log --pretty="tformat:%<(40)%s" >actual &&
148 qz_to_tab_space <<-EOF >expected &&
154 test_cmp expected actual
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 &&
165 test_cmp expected actual
168 test_expect_success 'left alignment formatting at the nth column' '
169 git log --pretty="tformat:%h %<|(40)%s" >actual &&
170 qz_to_tab_space <<-EOF >expected &&
174 $head4 $(commit_msg) Z
176 test_cmp expected actual
179 test_expect_success 'left alignment formatting at the nth column' '
180 COLUMNS=50 git log --pretty="tformat:%h %<|(-10)%s" >actual &&
181 qz_to_tab_space <<-EOF >expected &&
185 $head4 $(commit_msg) Z
187 test_cmp expected actual
190 test_expect_success 'left alignment formatting at the nth column. i18n.logOutputEncoding' '
191 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %<|(40)%s" >actual &&
192 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
196 $head4 $(commit_msg) Z
198 test_cmp expected actual
201 test_expect_success 'left alignment formatting with no padding' '
202 git log --pretty="tformat:%<(1)%s" >actual &&
203 cat <<-EOF >expected &&
209 test_cmp expected actual
212 test_expect_success 'left alignment formatting with no padding. i18n.logOutputEncoding' '
213 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(1)%s" >actual &&
214 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
220 test_cmp expected actual
223 test_expect_success 'left alignment formatting with trunc' '
224 git log --pretty="tformat:%<(10,trunc)%s" >actual &&
225 qz_to_tab_space <<-\EOF >expected &&
231 test_cmp expected actual
234 test_expect_success 'left alignment formatting with trunc. i18n.logOutputEncoding' '
235 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s" >actual &&
236 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
242 test_cmp expected actual
245 test_expect_success 'left alignment formatting with ltrunc' '
246 git log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
247 qz_to_tab_space <<-EOF >expected &&
251 ..${sample_utf8_part}lich
253 test_cmp expected actual
256 test_expect_success 'left alignment formatting with ltrunc. i18n.logOutputEncoding' '
257 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,ltrunc)%s" >actual &&
258 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
262 ..${sample_utf8_part}lich
264 test_cmp expected actual
267 test_expect_success 'left alignment formatting with mtrunc' '
268 git log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
269 qz_to_tab_space <<-\EOF >expected &&
275 test_cmp expected actual
278 test_expect_success 'left alignment formatting with mtrunc. i18n.logOutputEncoding' '
279 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,mtrunc)%s" >actual &&
280 qz_to_tab_space <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
286 test_cmp expected actual
289 test_expect_success 'right alignment formatting' '
290 git log --pretty="tformat:%>(40)%s" >actual &&
291 qz_to_tab_space <<-EOF >expected &&
297 test_cmp expected actual
300 test_expect_success 'right alignment formatting. i18n.logOutputEncoding' '
301 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(40)%s" >actual &&
302 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
308 test_cmp expected actual
311 test_expect_success 'right alignment formatting at the nth column' '
312 git log --pretty="tformat:%h %>|(40)%s" >actual &&
313 qz_to_tab_space <<-EOF >expected &&
319 test_cmp expected actual
322 test_expect_success 'right alignment formatting at the nth column' '
323 COLUMNS=50 git log --pretty="tformat:%h %>|(-10)%s" >actual &&
324 qz_to_tab_space <<-EOF >expected &&
330 test_cmp expected actual
333 test_expect_success 'right alignment formatting at the nth column. i18n.logOutputEncoding' '
334 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %>|(40)%s" >actual &&
335 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
341 test_cmp expected actual
344 # Note: Space between 'message' and 'two' should be in the same column
345 # as in previous test.
346 test_expect_success 'right alignment formatting at the nth column with --graph. i18n.logOutputEncoding' '
347 git -c i18n.logOutputEncoding=$test_encoding log --graph --pretty="tformat:%h %>|(40)%s" >actual &&
348 iconv -f utf-8 -t $test_encoding >expected <<-EOF &&
352 * $head4 $(commit_msg)
354 test_cmp expected actual
357 test_expect_success 'right alignment formatting with no padding' '
358 git log --pretty="tformat:%>(1)%s" >actual &&
359 cat <<-EOF >expected &&
365 test_cmp expected actual
368 test_expect_success 'right alignment formatting with no padding and with --graph' '
369 git log --graph --pretty="tformat:%>(1)%s" >actual &&
370 cat <<-EOF >expected &&
376 test_cmp expected actual
379 test_expect_success 'right alignment formatting with no padding. i18n.logOutputEncoding' '
380 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%>(1)%s" >actual &&
381 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
387 test_cmp expected actual
390 test_expect_success 'center alignment formatting' '
391 git log --pretty="tformat:%><(40)%s" >actual &&
392 qz_to_tab_space <<-EOF >expected &&
398 test_cmp expected actual
401 test_expect_success 'center alignment formatting. i18n.logOutputEncoding' '
402 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(40)%s" >actual &&
403 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
409 test_cmp expected actual
411 test_expect_success 'center alignment formatting at the nth column' '
412 git log --pretty="tformat:%h %><|(40)%s" >actual &&
413 qz_to_tab_space <<-EOF >expected &&
417 $head4 $(commit_msg) Z
419 test_cmp expected actual
422 test_expect_success 'center alignment formatting at the nth column' '
423 COLUMNS=70 git log --pretty="tformat:%h %><|(-30)%s" >actual &&
424 qz_to_tab_space <<-EOF >expected &&
428 $head4 $(commit_msg) Z
430 test_cmp expected actual
433 test_expect_success 'center alignment formatting at the nth column. i18n.logOutputEncoding' '
434 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%h %><|(40)%s" >actual &&
435 qz_to_tab_space <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
439 $head4 $(commit_msg) Z
441 test_cmp expected actual
444 test_expect_success 'center alignment formatting with no padding' '
445 git log --pretty="tformat:%><(1)%s" >actual &&
446 cat <<-EOF >expected &&
452 test_cmp expected actual
455 # save HEAD's SHA-1 digest (with no abbreviations) to use it below
456 # as far as the next test amends HEAD
457 old_head1=$(git rev-parse --verify HEAD~0)
458 test_expect_success 'center alignment formatting with no padding. i18n.logOutputEncoding' '
459 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%><(1)%s" >actual &&
460 cat <<-EOF | iconv -f utf-8 -t $test_encoding >expected &&
466 test_cmp expected actual
469 test_expect_success 'left/right alignment formatting with stealing' '
470 git commit --amend -m short --author "long long long <long@me.com>" &&
471 git log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
472 cat <<-\EOF >expected &&
478 test_cmp expected actual
480 test_expect_success 'left/right alignment formatting with stealing. i18n.logOutputEncoding' '
481 git -c i18n.logOutputEncoding=$test_encoding log --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
482 cat <<-\EOF | iconv -f utf-8 -t $test_encoding >expected &&
488 test_cmp expected actual
491 test_expect_success 'strbuf_utf8_replace() not producing NUL' '
492 git log --color --pretty="tformat:%<(10,trunc)%s%>>(10,ltrunc)%C(auto)%d" |
498 # ISO strict date format
499 test_expect_success 'ISO and ISO-strict date formats display the same values' '
500 git log --format=%ai%n%ci |
501 sed -e "s/ /T/; s/ //; s/..\$/:&/" >expected &&
502 git log --format=%aI%n%cI >actual &&
503 test_cmp expected actual
506 # get new digests (with no abbreviations)
507 test_expect_success 'set up log decoration tests' '
508 head1=$(git rev-parse --verify HEAD~0) &&
509 head2=$(git rev-parse --verify HEAD~1)
512 test_expect_success 'log decoration properly follows tag chain' '
513 git tag -a tag1 -m tag1 &&
514 git tag -a tag2 -m tag2 tag1 &&
516 git commit --amend -m shorter &&
517 git log --no-walk --tags --pretty="%H %d" --decorate=full >actual &&
518 cat <<-EOF >expected &&
519 $head1 (tag: refs/tags/tag2)
520 $head2 (tag: refs/tags/message-one)
521 $old_head1 (tag: refs/tags/message-two)
523 sort actual >actual1 &&
524 test_cmp expected actual1
527 test_expect_success 'clean log decoration' '
528 git log --no-walk --tags --pretty="%H %D" --decorate=full >actual &&
529 cat >expected <<-EOF &&
530 $head1 tag: refs/tags/tag2
531 $head2 tag: refs/tags/message-one
532 $old_head1 tag: refs/tags/message-two
534 sort actual >actual1 &&
535 test_cmp expected actual1
539 Signed-off-by: A U Thor <author@example.com>
540 Acked-by: A U Thor <author@example.com>
541 [ v2 updated patch description ]
542 Signed-off-by: A U Thor
547 perl -0pe 's/\n\s+/ /g'
550 test_expect_success 'set up trailer tests' '
551 echo "Some contents" >trailerfile &&
552 git add trailerfile &&
553 git commit -F - <<-EOF
554 trailers: this commit message has trailers
556 This commit is a test commit with trailers at the end. We parse this
557 message and display the trailers using %(trailers).
563 test_expect_success 'pretty format %(trailers) shows trailers' '
564 git log --no-walk --pretty="%(trailers)" >actual &&
569 test_cmp expect actual
572 test_expect_success '%(trailers:only) shows only "key: value" trailers' '
573 git log --no-walk --pretty="%(trailers:only)" >actual &&
575 grep -v patch.description <trailers &&
578 test_cmp expect actual
581 test_expect_success '%(trailers:unfold) unfolds trailers' '
582 git log --no-walk --pretty="%(trailers:unfold)" >actual &&
587 test_cmp expect actual
590 test_expect_success ':only and :unfold work together' '
591 git log --no-walk --pretty="%(trailers:only,unfold)" >actual &&
592 git log --no-walk --pretty="%(trailers:unfold,only)" >reverse &&
593 test_cmp actual reverse &&
595 grep -v patch.description <trailers | unfold &&
598 test_cmp expect actual