summaryrefslogtreecommitdiff
path: root/t/t4205-log-pretty-formats.sh
diff options
context:
space:
mode:
authorLibravatar Alexey Shumkin <Alex.Crezoff@gmail.com>2013-06-26 14:19:49 +0400
committerLibravatar Junio C Hamano <gitster@pobox.com>2013-06-26 11:40:27 -0700
commitde6029a2d7734a93a9e27b9c4471862a47dd8123 (patch)
tree2932d4fa44ffdf809c9f85ea109bffdda7183ec1 /t/t4205-log-pretty-formats.sh
parentt4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs (diff)
downloadtgif-de6029a2d7734a93a9e27b9c4471862a47dd8123.tar.xz
pretty: Add failing tests: --format output should honor logOutputEncoding
One can set an alias $ git config alias.lg "log --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cd) %C(bold blue)<%an>%Creset' --abbrev-commit --date=local" to see the log as a pretty tree (like *gitk* but in a terminal). However, log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted even when i18n.logOutputEncoding and terminal encoding are the same (e.g. log messages committed on a Cygwin box with Windows-1251 encoding seen on a Linux box with a UTF-8 encoding and vice versa). To simplify an example we can say the following two commands are expected to give the same output to a terminal: $ git log --oneline --no-color $ git log --pretty=format:'%h %s' However, the former pays attention to i18n.logOutputEncoding configuration, while the latter does not when it formats "%s". The same corruption is true for $ git diff --submodule=log and $ git rev-list --pretty=format:%s HEAD and $ git reset --hard This patch adds failing tests for the next patch that fixes them. Signed-off-by: Alexey Shumkin <Alex.Crezoff@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 't/t4205-log-pretty-formats.sh')
-rwxr-xr-xt/t4205-log-pretty-formats.sh149
1 files changed, 93 insertions, 56 deletions
diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh
index 73ba5e8f0c..d45aa994e6 100755
--- a/t/t4205-log-pretty-formats.sh
+++ b/t/t4205-log-pretty-formats.sh
@@ -1,20 +1,43 @@
#!/bin/sh
#
# Copyright (c) 2010, Will Palmer
+# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
#
test_description='Test pretty formats'
. ./test-lib.sh
+commit_msg () {
+ # String "initial. initial" partly in German (translated with Google Translate),
+ # encoded in UTF-8, used as a commit log message below.
+ msg=$(printf "initial. anf\303\244nglich")
+ if test -n "$1"
+ then
+ msg=$(echo $msg | iconv -f utf-8 -t $1)
+ fi
+ if test -n "$2" -a -n "$3"
+ then
+ # cut string, replace cut part with two dots
+ # $2 - chars count from the beginning of the string
+ # $3 - "trailing" chars
+ # LC_ALL is set to make `sed` interpret "." as a UTF-8 char not a byte
+ # as it does with C locale
+ msg=$(echo $msg | LC_ALL=en_US.UTF-8 sed -e "s/^\(.\{$2\}\)$3/\1../")
+ fi
+ echo $msg
+}
+
test_expect_success 'set up basic repos' '
>foo &&
>bar &&
git add foo &&
test_tick &&
- git commit -m initial &&
+ git config i18n.commitEncoding iso-8859-1 &&
+ git commit -m "$(commit_msg iso-8859-1)" &&
git add bar &&
test_tick &&
- git commit -m "add bar"
+ git commit -m "add bar" &&
+ git config --unset i18n.commitEncoding
'
test_expect_success 'alias builtin format' '
@@ -38,6 +61,20 @@ test_expect_success 'alias user-defined format' '
test_cmp expected actual
'
+test_expect_success 'alias user-defined tformat with %s (iso-8859-1 encoding)' '
+ git config i18n.logOutputEncoding iso-8859-1 &&
+ git log --oneline >expected-s &&
+ git log --pretty="tformat:%h %s" >actual-s &&
+ git config --unset i18n.logOutputEncoding &&
+ test_cmp expected-s actual-s
+'
+
+test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' '
+ git log --oneline >expected-s &&
+ git log --pretty="tformat:%h %s" >actual-s &&
+ test_cmp expected-s actual-s
+'
+
test_expect_success 'alias user-defined tformat' '
git log --pretty="tformat:%h" >expected &&
git config pretty.test-alias "tformat:%h" &&
@@ -71,22 +108,22 @@ test_expect_success 'alias loop' '
test_must_fail git log --pretty=test-foo
'
-test_expect_success 'NUL separation' '
- printf "add bar\0initial" >expected &&
+test_expect_failure 'NUL separation' '
+ printf "add bar\0$(commit_msg)" >expected &&
git log -z --pretty="format:%s" >actual &&
test_cmp expected actual
'
-test_expect_success 'NUL termination' '
- printf "add bar\0initial\0" >expected &&
+test_expect_failure 'NUL termination' '
+ printf "add bar\0$(commit_msg)\0" >expected &&
git log -z --pretty="tformat:%s" >actual &&
test_cmp expected actual
'
-test_expect_success 'NUL separation with --stat' '
+test_expect_failure 'NUL separation with --stat' '
stat0_part=$(git diff --stat HEAD^ HEAD) &&
stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
- printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n" >expected &&
+ printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n" >expected &&
git log -z --stat --pretty="format:%s" >actual &&
test_i18ncmp expected actual
'
@@ -94,7 +131,7 @@ test_expect_success 'NUL separation with --stat' '
test_expect_failure 'NUL termination with --stat' '
stat0_part=$(git diff --stat HEAD^ HEAD) &&
stat1_part=$(git diff-tree --no-commit-id --stat --root HEAD^) &&
- printf "add bar\n$stat0_part\n\0initial\n$stat1_part\n\0" >expected &&
+ printf "add bar\n$stat0_part\n\0$(commit_msg)\n$stat1_part\n0" >expected &&
git log -z --stat --pretty="tformat:%s" >actual &&
test_i18ncmp expected actual
'
@@ -108,20 +145,20 @@ test_expect_success 'setup more commits' '
head4=$(git rev-parse --verify --short HEAD~3)
'
-test_expect_success 'left alignment formatting' '
- git log --pretty="format:%<(40)%s" >actual &&
+test_expect_failure 'left alignment formatting' "
+ git log --pretty='format:%<(40)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
qz_to_tab_space <<\EOF >expected &&
message two Z
message one Z
add bar Z
-initial Z
+$(commit_msg) Z
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'left alignment formatting at the nth column' "
+test_expect_failure 'left alignment formatting at the nth column' "
git log --pretty='format:%h %<|(40)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
@@ -129,77 +166,77 @@ test_expect_success 'left alignment formatting at the nth column' "
$head1 message two Z
$head2 message one Z
$head3 add bar Z
-$head4 initial Z
+$head4 $(commit_msg) Z
EOF
test_cmp expected actual
"
-test_expect_success 'left alignment formatting with no padding' '
- git log --pretty="format:%<(1)%s" >actual &&
+test_expect_failure 'left alignment formatting with no padding' "
+ git log --pretty='format:%<(1)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
cat <<\EOF >expected &&
message two
message one
add bar
-initial
+$(commit_msg)
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'left alignment formatting with trunc' '
- git log --pretty="format:%<(10,trunc)%s" >actual &&
+test_expect_failure 'left alignment formatting with trunc' "
+ git log --pretty='format:%<(10,trunc)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
qz_to_tab_space <<\EOF >expected &&
message ..
message ..
add bar Z
-initial Z
+$(commit_msg "" "8" ".\+$")
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'left alignment formatting with ltrunc' '
- git log --pretty="format:%<(10,ltrunc)%s" >actual &&
+test_expect_failure 'left alignment formatting with ltrunc' "
+ git log --pretty='format:%<(10,ltrunc)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
qz_to_tab_space <<\EOF >expected &&
..sage two
..sage one
add bar Z
-initial Z
+$(commit_msg "" "0" ".\{11\}")
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'left alignment formatting with mtrunc' '
- git log --pretty="format:%<(10,mtrunc)%s" >actual &&
+test_expect_failure 'left alignment formatting with mtrunc' "
+ git log --pretty='format:%<(10,mtrunc)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
qz_to_tab_space <<\EOF >expected &&
mess.. two
mess.. one
add bar Z
-initial Z
+$(commit_msg "" "4" ".\{11\}")
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'right alignment formatting' '
- git log --pretty="format:%>(40)%s" >actual &&
+test_expect_failure 'right alignment formatting' "
+ git log --pretty='format:%>(40)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
qz_to_tab_space <<\EOF >expected &&
Z message two
Z message one
Z add bar
-Z initial
+Z $(commit_msg)
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'right alignment formatting at the nth column' "
+test_expect_failure 'right alignment formatting at the nth column' "
git log --pretty='format:%h %>|(40)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
@@ -207,38 +244,38 @@ test_expect_success 'right alignment formatting at the nth column' "
$head1 message two
$head2 message one
$head3 add bar
-$head4 initial
+$head4 $(commit_msg)
EOF
test_cmp expected actual
"
-test_expect_success 'right alignment formatting with no padding' '
- git log --pretty="format:%>(1)%s" >actual &&
+test_expect_failure 'right alignment formatting with no padding' "
+ git log --pretty='format:%>(1)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
cat <<\EOF >expected &&
message two
message one
add bar
-initial
+$(commit_msg)
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'center alignment formatting' '
- git log --pretty="format:%><(40)%s" >actual &&
+test_expect_failure 'center alignment formatting' "
+ git log --pretty='format:%><(40)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
qz_to_tab_space <<\EOF >expected &&
Z message two Z
Z message one Z
Z add bar Z
-Z initial Z
+Z $(commit_msg) Z
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'center alignment formatting at the nth column' "
+test_expect_failure 'center alignment formatting at the nth column' "
git log --pretty='format:%h %><|(40)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
@@ -246,36 +283,36 @@ test_expect_success 'center alignment formatting at the nth column' "
$head1 message two Z
$head2 message one Z
$head3 add bar Z
-$head4 initial Z
+$head4 $(commit_msg) Z
EOF
test_cmp expected actual
"
-test_expect_success 'center alignment formatting with no padding' '
- git log --pretty="format:%><(1)%s" >actual &&
+test_expect_failure 'center alignment formatting with no padding' "
+ git log --pretty='format:%><(1)%s' >actual &&
# complete the incomplete line at the end
echo >>actual &&
cat <<\EOF >expected &&
message two
message one
add bar
-initial
+$(commit_msg)
EOF
test_cmp expected actual
-'
+"
-test_expect_success 'left/right alignment formatting with stealing' '
- git commit --amend -m short --author "long long long <long@me.com>" &&
- git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
+test_expect_failure 'left/right alignment formatting with stealing' "
+ git commit --amend -m short --author 'long long long <long@me.com>' &&
+ git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual &&
# complete the incomplete line at the end
echo >>actual &&
cat <<\EOF >expected &&
short long long long
message .. A U Thor
add bar A U Thor
-initial A U Thor
+$(commit_msg "" "8" ".\+$") A U Thor
EOF
test_cmp expected actual
-'
+"
test_done