From: Alexey Shumkin Date: Thu, 24 Jan 2013 09:10:27 GMT Subject: [PATCH v4 3/4] pretty: Add failing tests: user format ignores i18n.logOutputEncoding setting Message-ID: <6de583a2d281b1614c69d5e7b6f5c4495488f6a3.1359018188.git.Alex.Crezoff@gmail.com> In-Reply-To: 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 format "%s". Log messages written in an encoding i18n.commitEncoding which differs from terminal encoding are shown corrupted with the latter even when i18n.logOutputEncoding and terminal encoding are the same. The same corruption is true for $ git diff --submodule=log and $ git rev-list --pretty=format:%s HEAD and $ git reset --hard Signed-off-by: Alexey Shumkin --- t/t4041-diff-submodule-option.sh | 33 ++++++++------- t/t4205-log-pretty-formats.sh | 43 +++++++++++++++---- t/t6006-rev-list-format.sh | 90 ++++++++++++++++++++++++++-------------- t/t7102-reset.sh | 32 +++++++++++--- 4 files changed, 138 insertions(+), 60 deletions(-) diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 32d4a60..e7d6363 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -1,6 +1,7 @@ #!/bin/sh # # Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin +# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests) # test_description='Support for verbose submodule differences in git diff @@ -10,6 +11,7 @@ This test tries to verify the sanity of the --submodule option of git diff. . ./test-lib.sh +added=$(printf "\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275") add_file () { ( cd "$1" && @@ -19,7 +21,8 @@ add_file () { echo "$name" >"$name" && git add "$name" && test_tick && - git commit -m "Add $name" || exit + msg_added_cp1251=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t cp1251) && + git -c 'i18n.commitEncoding=cp1251' commit -m "$msg_added_cp1251" done >/dev/null && git rev-parse --short --verify HEAD ) @@ -89,29 +92,29 @@ test_expect_success 'diff.submodule does not affect plumbing' ' commit_file sm1 && head2=$(add_file sm1 foo3) -test_expect_success 'modified submodule(forward)' ' +test_expect_failure 'modified submodule(forward)' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: - > Add foo3 + > Add foo3 ($added foo3) EOF test_cmp expected actual ' -test_expect_success 'modified submodule(forward)' ' +test_expect_failure 'modified submodule(forward)' ' git diff --submodule=log >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: - > Add foo3 + > Add foo3 ($added foo3) EOF test_cmp expected actual ' -test_expect_success 'modified submodule(forward) --submodule' ' +test_expect_failure 'modified submodule(forward) --submodule' ' git diff --submodule >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: - > Add foo3 + > Add foo3 ($added foo3) EOF test_cmp expected actual ' @@ -138,25 +141,25 @@ head3=$( git rev-parse --short --verify HEAD ) -test_expect_success 'modified submodule(backward)' ' +test_expect_failure 'modified submodule(backward)' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2..$head3 (rewind): - < Add foo3 - < Add foo2 + < Add foo3 ($added foo3) + < Add foo2 ($added foo2) EOF test_cmp expected actual ' head4=$(add_file sm1 foo4 foo5) -test_expect_success 'modified submodule(backward and forward)' ' +test_expect_failure 'modified submodule(backward and forward)' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2...$head4: - > Add foo5 - > Add foo4 - < Add foo3 - < Add foo2 + > Add foo5 ($added foo5) + > Add foo4 ($added foo4) + < Add foo3 ($added foo3) + < Add foo2 ($added foo2) EOF test_cmp expected actual ' diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 98a43d4..76ffa0d 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -1,20 +1,31 @@ #!/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() { + msg=$(printf "initial \320\272\320\276\320\274\320\274\320\270\321\202") + if test -n "$1"; then + msg=$(echo $msg | iconv -f utf-8 -t $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 cp1251 && + git commit -m "$(commit_msg cp1251)" && 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 +49,20 @@ test_expect_success 'alias user-defined format' ' test_cmp expected actual ' +test_expect_success 'alias user-defined tformat with %s (cp1251 encoding)' ' + git config i18n.logOutputEncoding cp1251 && + 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 +96,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 +119,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 ' diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index c248509..4db43a4 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -1,33 +1,54 @@ #!/bin/sh +# Copyright (c) 2009 Jens Lehmann +# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests) + test_description='git rev-list --pretty=format test' . ./test-lib.sh test_tick +added=$(printf "added (\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275) foo") +added_cp1251=$(echo "$added" | iconv -f utf-8 -t cp1251) +changed=$(printf "changed (\320\264\320\276\320\261\320\260\320\262\320\273\320\265\320\275) foo") +changed_cp1251=$(echo "$changed" | iconv -f utf-8 -t cp1251) + test_expect_success 'setup' ' touch foo && git add foo && - git commit -m "added foo" && + git config i18n.commitEncoding cp1251 && + git commit -m "$added_cp1251" && head1=$(git rev-parse --verify HEAD) && head1_7=$(echo $head1 | cut -c1-7) && - echo changed >foo && - git commit -a -m "changed foo" && + echo "$changed" > foo && + git commit -a -m "$changed_cp1251" && head2=$(git rev-parse --verify HEAD) && head2_7=$(echo $head2 | cut -c1-7) && + tree2=$(git cat-file -p HEAD | grep tree | cut -f 2 -d" ") && + tree2_7=$(echo $tree2 | cut -c1-7) && head2_parent=$(git cat-file -p HEAD | grep parent | cut -f 2 -d" ") && head2_parent_7=$(echo $head2_parent | cut -c1-7) && - tree2=$(git cat-file -p HEAD | grep tree | cut -f 2 -d" ") && - tree2_7=$(echo $tree2 | cut -c1-7) + git config --unset i18n.commitEncoding ' # usage: test_format name format_string expect.$1 - test_expect_success "format $1" " -git rev-list --pretty=format:'$2' master >output.$1 && -test_cmp expect.$1 output.$1 -" + name="format $1" + command="git rev-list --pretty=format:'$2' master >output.$1 && +test_cmp expect.$1 output.$1" + if [ $must_fail -eq 1 ]; then + test_expect_failure "$name" "$command" + else + test_expect_success "$name" "$command" + fi } test_format percent %%h <commit-msg <<'EOF' +iconv -f utf-8 -t cp1251 > commit-msg <foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && head3_7=$(echo $head3 | cut -c1-7) @@ -152,25 +173,32 @@ test_expect_success 'setup complex body' ' test_format complex-encoding %e <actual && - test $(wc -w actual && - test $(wc -w first && @@ -28,7 +36,7 @@ test_expect_success 'creating initial files and commits' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git commit -a -m "modify 2nd file" && + git -c "i18n.commitEncoding=cp1251" commit -a -m "$(commit_msg cp1251)" && head5=$(git rev-parse --verify HEAD) ' # git log --pretty=oneline # to see those SHA1 involved @@ -44,6 +52,20 @@ check_changes () { done | test_cmp .cat_expect - } +test_expect_failure 'reset --hard message' ' + hex=$(git log -1 --format="%h") && + git reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg) > .expected && + test_cmp .actual .expected +' + +test_expect_success 'reset --hard message (cp1251 logoutencoding)' ' + hex=$(git log -1 --format="%h") && + git -c "i18n.logOutputEncoding=cp1251" reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg cp1251) > .expected && + test_cmp .actual .expected +' + >.diff_expect >.cached_expect cat >.cat_expect <>secondfile && git commit -a -C ORIG_HEAD && - check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d && + check_changes f06f78b8dd468c722952b77569dd0db212442c25 && test "$(git rev-parse ORIG_HEAD)" = \ $head5 ' @@ -211,7 +233,7 @@ test_expect_success \ git reset --hard HEAD~2 && check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && test "$(git rev-parse ORIG_HEAD)" = \ - 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d + f06f78b8dd468c722952b77569dd0db212442c25 ' >.diff_expect @@ -303,7 +325,7 @@ test_expect_success 'redoing the last two commits should succeed' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git commit -a -m "modify 2nd file" && + git -c "i18n.commitEncoding=cp1251" commit -a -m "$(commit_msg cp1251)" && check_changes $head5 ' @@ -329,7 +351,7 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' ' test_must_fail git pull . branch1 && git reset --hard && - check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb + check_changes f26fb896db2344fe158ce3720249e1df4d26174b ' >.diff_expect -- 1.8.1.1.10.g9255f3f