From 77a6815d7d5be7031324788f9935587bdb00de60 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:46 +0400 Subject: t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs The expected SHA-1 digests are always available in variables. Use them instead of hardcoding. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 140 +++++++++++++++++++++++++-------------------- 1 file changed, 77 insertions(+), 63 deletions(-) diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 0393c9fd0b..cc1008d024 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -7,8 +7,19 @@ test_description='git rev-list --pretty=format test' test_tick test_expect_success 'setup' ' -touch foo && git add foo && git commit -m "added foo" && - echo changed >foo && git commit -a -m "changed foo" + : >foo && + git add foo && + git commit -m "added foo" && + head1=$(git rev-parse --verify HEAD) && + head1_short=$(git rev-parse --verify --short $head1) && + tree1=$(git rev-parse --verify HEAD:) && + tree1_short=$(git rev-parse --verify --short $tree1) && + echo changed >foo && + git commit -a -m "changed foo" && + head2=$(git rev-parse --verify HEAD) && + head2_short=$(git rev-parse --verify --short $head2) && + tree2=$(git rev-parse --verify HEAD:) && + tree2_short=$(git rev-parse --verify --short $tree2) ' # usage: test_format name format_string foo && git commit -a -F commit-msg + git config i18n.commitencoding iso8859-1 && + echo change2 >foo && git commit -a -F commit-msg && + head3=$(git rev-parse --verify HEAD) && + head3_short=$(git rev-parse --short $head3) ' -test_format complex-encoding %e <<'EOF' -commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 +test_format complex-encoding %e <expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 && + echo >expect commit $head3 && echo >>expect fooQbar && git rev-list -1 --format=foo%x00bar HEAD >actual.nul && nul_to_q actual && -- cgit v1.2.1 From 375775bb1289a0b78f26b8ec08627fd133920ab9 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:47 +0400 Subject: t7102 (reset): don't hardcode SHA-1 in expected outputs The expected SHA-1 digests are always available in variables. Use them instead of hardcoding. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t7102-reset.sh | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index df82ec9dda..05dfb27cfa 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -192,7 +192,8 @@ test_expect_success \ 'changing files and redo the last commit should succeed' ' echo "3rd line 2nd file" >>secondfile && git commit -a -C ORIG_HEAD && - check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d && + head4=$(git rev-parse --verify HEAD) && + check_changes $head4 && test "$(git rev-parse ORIG_HEAD)" = \ $head5 ' @@ -211,7 +212,7 @@ test_expect_success \ git reset --hard HEAD~2 && check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && test "$(git rev-parse ORIG_HEAD)" = \ - 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d + $head4 ' >.diff_expect @@ -326,10 +327,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' ' git checkout branch2 && echo "3rd line in branch2" >>secondfile && git commit -a -m "change in branch2" && + head3=$(git rev-parse --verify HEAD) && test_must_fail git pull . branch1 && git reset --hard && - check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb + check_changes $head3 ' >.diff_expect -- cgit v1.2.1 From a742f2a0a7e57bb7d3f55cb8312c3f4cc4dc68fb Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:48 +0400 Subject: t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs The expected SHA-1 digests are always available in variables. Use them instead of hardcoding. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 48 +++++++++++++++++++++++-------------------- 1 file changed, 26 insertions(+), 22 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 26fbfde4a3..73ba5e8f0c 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -101,7 +101,11 @@ test_expect_failure 'NUL termination with --stat' ' test_expect_success 'setup more commits' ' test_commit "message one" one one message-one && - test_commit "message two" two two message-two + test_commit "message two" two two message-two && + head1=$(git rev-parse --verify --short HEAD~0) && + head2=$(git rev-parse --verify --short HEAD~1) && + head3=$(git rev-parse --verify --short HEAD~2) && + head4=$(git rev-parse --verify --short HEAD~3) ' test_expect_success 'left alignment formatting' ' @@ -117,18 +121,18 @@ EOF test_cmp expected actual ' -test_expect_success 'left alignment formatting at the nth column' ' - git log --pretty="format:%h %<|(40)%s" >actual && +test_expect_success 'left alignment formatting at the nth column' " + git log --pretty='format:%h %<|(40)%s' >actual && # complete the incomplete line at the end echo >>actual && qz_to_tab_space <<\EOF >expected && -fa33ab1 message two Z -7cd6c63 message one Z -1711bf9 add bar Z -af20c06 initial Z +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 initial Z EOF test_cmp expected actual -' +" test_expect_success 'left alignment formatting with no padding' ' git log --pretty="format:%<(1)%s" >actual && @@ -195,18 +199,18 @@ EOF test_cmp expected actual ' -test_expect_success 'right alignment formatting at the nth column' ' - git log --pretty="format:%h %>|(40)%s" >actual && +test_expect_success 'right alignment formatting at the nth column' " + git log --pretty='format:%h %>|(40)%s' >actual && # complete the incomplete line at the end echo >>actual && qz_to_tab_space <<\EOF >expected && -fa33ab1 message two -7cd6c63 message one -1711bf9 add bar -af20c06 initial +$head1 message two +$head2 message one +$head3 add bar +$head4 initial EOF test_cmp expected actual -' +" test_expect_success 'right alignment formatting with no padding' ' git log --pretty="format:%>(1)%s" >actual && @@ -234,18 +238,18 @@ EOF test_cmp expected actual ' -test_expect_success 'center alignment formatting at the nth column' ' - git log --pretty="format:%h %><|(40)%s" >actual && +test_expect_success 'center alignment formatting at the nth column' " + git log --pretty='format:%h %><|(40)%s' >actual && # complete the incomplete line at the end echo >>actual && qz_to_tab_space <<\EOF >expected && -fa33ab1 message two Z -7cd6c63 message one Z -1711bf9 add bar Z -af20c06 initial Z +$head1 message two Z +$head2 message one Z +$head3 add bar Z +$head4 initial Z EOF test_cmp expected actual -' +" test_expect_success 'center alignment formatting with no padding' ' git log --pretty="format:%><(1)%s" >actual && -- cgit v1.2.1 From de6029a2d7734a93a9e27b9c4471862a47dd8123 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:49 +0400 Subject: 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 Signed-off-by: Junio C Hamano --- t/t4041-diff-submodule-option.sh | 35 +++++---- t/t4205-log-pretty-formats.sh | 149 ++++++++++++++++++++++++--------------- t/t6006-rev-list-format.sh | 83 +++++++++++++++------- t/t7102-reset.sh | 29 +++++++- 4 files changed, 199 insertions(+), 97 deletions(-) diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 32d4a60425..2a7877d893 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,9 @@ This test tries to verify the sanity of the --submodule option of git diff. . ./test-lib.sh +# String "added" in German (translated with Google Translate), encoded in UTF-8, +# used in sample commit log messages in add_file() function below. +added=$(printf "hinzugef\303\274gt") add_file () { ( cd "$1" && @@ -19,7 +23,8 @@ add_file () { echo "$name" >"$name" && git add "$name" && test_tick && - git commit -m "Add $name" || exit + msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso-8859-1) && + git -c 'i18n.commitEncoding=iso-8859-1' commit -m "$msg_added_iso88591" done >/dev/null && git rev-parse --short --verify HEAD ) @@ -89,29 +94,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 +143,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 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 " && - 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 ' && + 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 diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index cc1008d024..c66a07f8da 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -1,34 +1,60 @@ #!/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_DIRECTORY"/lib-terminal.sh test_tick +# String "added" in German (translated with Google Translate), encoded in UTF-8, +# used as a commit log message below. +added=$(printf "added (hinzugef\303\274gt) foo") +added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso-8859-1) +# same but "changed" +changed=$(printf "changed (ge\303\244ndert) foo") +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1) + test_expect_success 'setup' ' : >foo && git add foo && - git commit -m "added foo" && + git config i18n.commitEncoding iso-8859-1 && + git commit -m "$added_iso88591" && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && tree1=$(git rev-parse --verify HEAD:) && tree1_short=$(git rev-parse --verify --short $tree1) && - echo changed >foo && - git commit -a -m "changed foo" && + echo "$changed" > foo && + git commit -a -m "$changed_iso88591" && head2=$(git rev-parse --verify HEAD) && head2_short=$(git rev-parse --verify --short $head2) && tree2=$(git rev-parse --verify HEAD:) && tree2_short=$(git rev-parse --verify --short $tree2) + 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 test $must_fail -eq 1 + then + test_expect_failure "$name" "$command" + else + test_expect_success "$name" "$command" + fi } # Feed to --format to provide predictable colored sequences. @@ -110,14 +136,16 @@ EOF test_format encoding %e <commit-msg <<'EOF' +iconv -f utf-8 -t iso8859-1 > commit-msg <foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && - head3_short=$(git rev-parse --short $head3) + head3_short=$(git rev-parse --short $head3) && + # unset commit encoding config + # otherwise %e does not print encoding value + # and following test fails + git config --unset i18n.commitEncoding + ' test_format complex-encoding %e <actual && - test $(wc -w actual && - test $(wc -w first && @@ -28,7 +39,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=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" && head5=$(git rev-parse --verify HEAD) ' # git log --pretty=oneline # to see those SHA1 involved @@ -44,6 +55,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 .expected .actual +' + +test_expect_success 'reset --hard message (iso-8859-1 logoutencoding)' ' + hex=$(git log -1 --format="%h") && + git -c "i18n.logOutputEncoding=iso-8859-1" reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg iso-8859-1) > .expected && + test_cmp .expected .actual +' + >.diff_expect >.cached_expect cat >.cat_expect <secondfile && echo "2nd line 2nd file" >>secondfile && - git commit -a -m "modify 2nd file" && + git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" && check_changes $head5 ' -- cgit v1.2.1 From ecaee8050cec23eb4cf082512e907e3e52c20b57 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Wed, 26 Jun 2013 14:19:50 +0400 Subject: pretty: --format output should honor logOutputEncoding One can set an alias $ git config [--global] 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 makes pretty --format honor logOutputEncoding when it formats log message. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- builtin/reset.c | 5 ++++- builtin/rev-list.c | 1 + builtin/shortlog.c | 1 + log-tree.c | 1 + submodule.c | 1 + t/t4041-diff-submodule-option.sh | 10 +++++----- t/t4205-log-pretty-formats.sh | 34 +++++++++++++++++----------------- t/t6006-rev-list-format.sh | 8 ++++---- t/t7102-reset.sh | 2 +- 9 files changed, 35 insertions(+), 28 deletions(-) diff --git a/builtin/reset.c b/builtin/reset.c index 6032131a90..afa6e020e8 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -93,10 +93,12 @@ static int reset_index(const unsigned char *sha1, int reset_type, int quiet) static void print_new_head_line(struct commit *commit) { const char *hex, *body; + char *msg; hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); printf(_("HEAD is now at %s"), hex); - body = strstr(commit->buffer, "\n\n"); + msg = logmsg_reencode(commit, NULL, get_log_output_encoding()); + body = strstr(msg, "\n\n"); if (body) { const char *eol; size_t len; @@ -107,6 +109,7 @@ static void print_new_head_line(struct commit *commit) } else printf("\n"); + logmsg_free(msg, commit); } static void update_index_from_diff(struct diff_queue_struct *q, diff --git a/builtin/rev-list.c b/builtin/rev-list.c index 67701be551..a5ec30d74e 100644 --- a/builtin/rev-list.c +++ b/builtin/rev-list.c @@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data) ctx.date_mode = revs->date_mode; ctx.date_mode_explicit = revs->date_mode_explicit; ctx.fmt = revs->commit_format; + ctx.output_encoding = get_log_output_encoding(); pretty_print_commit(&ctx, commit, &buf); if (revs->graph) { if (buf.len) { diff --git a/builtin/shortlog.c b/builtin/shortlog.c index 1fd6f8ac59..1434f8fee4 100644 --- a/builtin/shortlog.c +++ b/builtin/shortlog.c @@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit) ctx.subject = ""; ctx.after_subject = ""; ctx.date_mode = DATE_NORMAL; + ctx.output_encoding = get_log_output_encoding(); pretty_print_commit(&ctx, commit, &ufbuf); buffer = ufbuf.buf; } else if (*buffer) { diff --git a/log-tree.c b/log-tree.c index 1946e9ce8d..5277d3e8d0 100644 --- a/log-tree.c +++ b/log-tree.c @@ -616,6 +616,7 @@ void show_log(struct rev_info *opt) ctx.fmt = opt->commit_format; ctx.mailmap = opt->mailmap; ctx.color = opt->diffopt.use_color; + ctx.output_encoding = get_log_output_encoding(); pretty_print_commit(&ctx, commit, &msgbuf); if (opt->add_signoff) diff --git a/submodule.c b/submodule.c index 1821a5b316..78734e1486 100644 --- a/submodule.c +++ b/submodule.c @@ -226,6 +226,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f, while ((commit = get_revision(rev))) { struct pretty_print_context ctx = {0}; ctx.date_mode = rev->date_mode; + ctx.output_encoding = get_log_output_encoding(); strbuf_setlen(&sb, 0); strbuf_addstr(&sb, line_prefix); if (commit->object.flags & SYMMETRIC_LEFT) { diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 2a7877d893..0a4f4963e7 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -94,7 +94,7 @@ test_expect_success 'diff.submodule does not affect plumbing' ' commit_file sm1 && head2=$(add_file sm1 foo3) -test_expect_failure 'modified submodule(forward)' ' +test_expect_success 'modified submodule(forward)' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: @@ -103,7 +103,7 @@ test_expect_failure 'modified submodule(forward)' ' test_cmp expected actual ' -test_expect_failure 'modified submodule(forward)' ' +test_expect_success 'modified submodule(forward)' ' git diff --submodule=log >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: @@ -112,7 +112,7 @@ test_expect_failure 'modified submodule(forward)' ' test_cmp expected actual ' -test_expect_failure 'modified submodule(forward) --submodule' ' +test_expect_success 'modified submodule(forward) --submodule' ' git diff --submodule >actual && cat >expected <<-EOF && Submodule sm1 $head1..$head2: @@ -143,7 +143,7 @@ head3=$( git rev-parse --short --verify HEAD ) -test_expect_failure 'modified submodule(backward)' ' +test_expect_success 'modified submodule(backward)' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2..$head3 (rewind): @@ -154,7 +154,7 @@ test_expect_failure 'modified submodule(backward)' ' ' head4=$(add_file sm1 foo4 foo5) -test_expect_failure 'modified submodule(backward and forward)' ' +test_expect_success 'modified submodule(backward and forward)' ' git diff-index -p --submodule=log HEAD >actual && cat >expected <<-EOF && Submodule sm1 $head2...$head4: diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index d45aa994e6..719d132c6d 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -69,7 +69,7 @@ test_expect_success 'alias user-defined tformat with %s (iso-8859-1 encoding)' ' test_cmp expected-s actual-s ' -test_expect_failure 'alias user-defined tformat with %s (utf-8 encoding)' ' +test_expect_success '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 @@ -108,19 +108,19 @@ test_expect_success 'alias loop' ' test_must_fail git log --pretty=test-foo ' -test_expect_failure 'NUL separation' ' +test_expect_success 'NUL separation' ' printf "add bar\0$(commit_msg)" >expected && git log -z --pretty="format:%s" >actual && test_cmp expected actual ' -test_expect_failure 'NUL termination' ' +test_expect_success 'NUL termination' ' printf "add bar\0$(commit_msg)\0" >expected && git log -z --pretty="tformat:%s" >actual && test_cmp expected actual ' -test_expect_failure 'NUL separation with --stat' ' +test_expect_success '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\0$(commit_msg)\n$stat1_part\n" >expected && @@ -145,7 +145,7 @@ test_expect_success 'setup more commits' ' head4=$(git rev-parse --verify --short HEAD~3) ' -test_expect_failure 'left alignment formatting' " +test_expect_success 'left alignment formatting' " git log --pretty='format:%<(40)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -158,7 +158,7 @@ EOF test_cmp expected actual " -test_expect_failure 'left alignment formatting at the nth column' " +test_expect_success 'left alignment formatting at the nth column' " git log --pretty='format:%h %<|(40)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -171,7 +171,7 @@ EOF test_cmp expected actual " -test_expect_failure 'left alignment formatting with no padding' " +test_expect_success 'left alignment formatting with no padding' " git log --pretty='format:%<(1)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -184,7 +184,7 @@ EOF test_cmp expected actual " -test_expect_failure 'left alignment formatting with trunc' " +test_expect_success 'left alignment formatting with trunc' " git log --pretty='format:%<(10,trunc)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -197,7 +197,7 @@ EOF test_cmp expected actual " -test_expect_failure 'left alignment formatting with ltrunc' " +test_expect_success 'left alignment formatting with ltrunc' " git log --pretty='format:%<(10,ltrunc)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -210,7 +210,7 @@ EOF test_cmp expected actual " -test_expect_failure 'left alignment formatting with mtrunc' " +test_expect_success 'left alignment formatting with mtrunc' " git log --pretty='format:%<(10,mtrunc)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -223,7 +223,7 @@ EOF test_cmp expected actual " -test_expect_failure 'right alignment formatting' " +test_expect_success 'right alignment formatting' " git log --pretty='format:%>(40)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -236,7 +236,7 @@ EOF test_cmp expected actual " -test_expect_failure 'right alignment formatting at the nth column' " +test_expect_success 'right alignment formatting at the nth column' " git log --pretty='format:%h %>|(40)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -249,7 +249,7 @@ EOF test_cmp expected actual " -test_expect_failure 'right alignment formatting with no padding' " +test_expect_success 'right alignment formatting with no padding' " git log --pretty='format:%>(1)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -262,7 +262,7 @@ EOF test_cmp expected actual " -test_expect_failure 'center alignment formatting' " +test_expect_success 'center alignment formatting' " git log --pretty='format:%><(40)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -275,7 +275,7 @@ EOF test_cmp expected actual " -test_expect_failure 'center alignment formatting at the nth column' " +test_expect_success 'center alignment formatting at the nth column' " git log --pretty='format:%h %><|(40)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -288,7 +288,7 @@ EOF test_cmp expected actual " -test_expect_failure 'center alignment formatting with no padding' " +test_expect_success 'center alignment formatting with no padding' " git log --pretty='format:%><(1)%s' >actual && # complete the incomplete line at the end echo >>actual && @@ -301,7 +301,7 @@ EOF test_cmp expected actual " -test_expect_failure 'left/right alignment formatting with stealing' " +test_expect_success 'left/right alignment formatting with stealing' " git commit --amend -m short --author 'long long long ' && git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual && # complete the incomplete line at the end diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index c66a07f8da..380c85bf12 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -141,7 +141,7 @@ commit $head1 iso-8859-1 EOF -test_format failure subject %s < .actual && echo HEAD is now at $hex $(commit_msg) > .expected && -- cgit v1.2.1 From 7c37521487332fd700e2fa58bd2547d275e4f4d2 Mon Sep 17 00:00:00 2001 From: Brian Gernhardt Date: Mon, 1 Jul 2013 14:59:59 -0400 Subject: t4205: replace .\+ with ..* in sed commands OS X's sed only accepts basic regular expressions, which does not allow the + quantifier. However '..*' (anything, followed by zero or more anything) is the same as '.\+' (one or more anything) and valid in any regular expression language. Signed-off-by: Brian Gernhardt Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 719d132c6d..3cfb744017 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -192,7 +192,7 @@ test_expect_success 'left alignment formatting with trunc' " message .. message .. add bar Z -$(commit_msg "" "8" ".\+$") +$(commit_msg "" "8" "..*$") EOF test_cmp expected actual " @@ -310,7 +310,7 @@ test_expect_success 'left/right alignment formatting with stealing' " short long long long message .. A U Thor add bar A U Thor -$(commit_msg "" "8" ".\+$") A U Thor +$(commit_msg "" "8" "..*$") A U Thor EOF test_cmp expected actual " -- cgit v1.2.1 From 14332bccc1d88e89fa8950b92c034432e1585bd4 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Thu, 4 Jul 2013 16:45:46 +0400 Subject: t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1 Both "iso8859-1" and "iso-8859-1" are understood as latin-1 by modern platforms, but the latter is not understood by older platforms;update tests to use the former. This is in line with 3994e8a9 (t4201: use ISO8859-1 rather than ISO-8859-1, 2009-12-03), which did the same. Signed-off-by: Alexey Shumkin Reviewed-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t4041-diff-submodule-option.sh | 4 ++-- t/t4205-log-pretty-formats.sh | 8 ++++---- t/t6006-rev-list-format.sh | 14 +++++++------- t/t7102-reset.sh | 10 +++++----- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/t/t4041-diff-submodule-option.sh b/t/t4041-diff-submodule-option.sh index 0a4f4963e7..1751c83307 100755 --- a/t/t4041-diff-submodule-option.sh +++ b/t/t4041-diff-submodule-option.sh @@ -23,8 +23,8 @@ add_file () { echo "$name" >"$name" && git add "$name" && test_tick && - msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso-8859-1) && - git -c 'i18n.commitEncoding=iso-8859-1' commit -m "$msg_added_iso88591" + msg_added_iso88591=$(echo "Add $name ($added $name)" | iconv -f utf-8 -t iso8859-1) && + git -c 'i18n.commitEncoding=iso8859-1' commit -m "$msg_added_iso88591" done >/dev/null && git rev-parse --short --verify HEAD ) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 3cfb744017..c2838427d3 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -32,8 +32,8 @@ test_expect_success 'set up basic repos' ' >bar && git add foo && test_tick && - git config i18n.commitEncoding iso-8859-1 && - git commit -m "$(commit_msg iso-8859-1)" && + git config i18n.commitEncoding iso8859-1 && + git commit -m "$(commit_msg iso8859-1)" && git add bar && test_tick && git commit -m "add bar" && @@ -61,8 +61,8 @@ 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 && +test_expect_success 'alias user-defined tformat with %s (iso8859-1 encoding)' ' + git config i18n.logOutputEncoding iso8859-1 && git log --oneline >expected-s && git log --pretty="tformat:%h %s" >actual-s && git config --unset i18n.logOutputEncoding && diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 380c85bf12..4751d22217 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -12,15 +12,15 @@ test_tick # String "added" in German (translated with Google Translate), encoded in UTF-8, # used as a commit log message below. added=$(printf "added (hinzugef\303\274gt) foo") -added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso-8859-1) +added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1) # same but "changed" changed=$(printf "changed (ge\303\244ndert) foo") -changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso-8859-1) +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1) test_expect_success 'setup' ' : >foo && git add foo && - git config i18n.commitEncoding iso-8859-1 && + git config i18n.commitEncoding iso8859-1 && git commit -m "$added_iso88591" && head1=$(git rev-parse --verify HEAD) && head1_short=$(git rev-parse --verify --short $head1) && @@ -136,9 +136,9 @@ EOF test_format encoding %e <secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" && + git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && head5=$(git rev-parse --verify HEAD) ' # git log --pretty=oneline # to see those SHA1 involved @@ -62,10 +62,10 @@ test_expect_success 'reset --hard message' ' test_cmp .expected .actual ' -test_expect_success 'reset --hard message (iso-8859-1 logoutencoding)' ' +test_expect_success 'reset --hard message (iso8859-1 logoutputencoding)' ' hex=$(git log -1 --format="%h") && - git -c "i18n.logOutputEncoding=iso-8859-1" reset --hard > .actual && - echo HEAD is now at $hex $(commit_msg iso-8859-1) > .expected && + git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual && + echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected && test_cmp .expected .actual ' @@ -329,7 +329,7 @@ test_expect_success 'redoing the last two commits should succeed' ' echo "1st line 2nd file" >secondfile && echo "2nd line 2nd file" >>secondfile && - git -c "i18n.commitEncoding=iso-8859-1" commit -a -m "$(commit_msg iso-8859-1)" && + git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" && check_changes $head5 ' -- cgit v1.2.1 From f3445f781f95ca4a7d59028aa7b7457fa925f577 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Fri, 5 Jul 2013 16:01:47 +0400 Subject: t4205 (log-pretty-formats): revert back single quotes In previuos commit de6029a (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26) single quotes were replaced with double quotes to make "$(commit_msg)" expression in heredoc to work. The same effect can be achieved by using "EOF" as a heredoc delimiter instead of "\EOF". Signed-off-by: Alexey Shumkin Suggested-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 106 +++++++++++++++++++++--------------------- 1 file changed, 53 insertions(+), 53 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index c2838427d3..ef9770a52b 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -145,174 +145,174 @@ 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_success '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 && + qz_to_tab_space <expected && message two Z message one Z add bar Z $(commit_msg) Z EOF test_cmp expected actual -" +' -test_expect_success 'left alignment formatting at the nth column' " - git log --pretty='format:%h %<|(40)%s' >actual && +test_expect_success 'left alignment formatting at the nth column' ' + git log --pretty="format:%h %<|(40)%s" >actual && # complete the incomplete line at the end echo >>actual && - qz_to_tab_space <<\EOF >expected && + qz_to_tab_space <expected && $head1 message two Z $head2 message one Z $head3 add bar 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_success '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 && + cat <expected && message two message one add bar $(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_success '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 && + qz_to_tab_space <expected && message .. message .. add bar 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_success '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 && + qz_to_tab_space <expected && ..sage two ..sage one add bar 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_success '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 && + qz_to_tab_space <expected && mess.. two mess.. one add bar 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_success '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 && + qz_to_tab_space <expected && Z message two Z message one Z add bar Z $(commit_msg) EOF test_cmp expected actual -" +' -test_expect_success 'right alignment formatting at the nth column' " - git log --pretty='format:%h %>|(40)%s' >actual && +test_expect_success 'right alignment formatting at the nth column' ' + git log --pretty="format:%h %>|(40)%s" >actual && # complete the incomplete line at the end echo >>actual && - qz_to_tab_space <<\EOF >expected && + qz_to_tab_space <expected && $head1 message two $head2 message one $head3 add bar $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_success '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 && + cat <expected && message two message one add bar $(commit_msg) EOF test_cmp expected actual -" +' -test_expect_success 'center alignment formatting' " - git log --pretty='format:%><(40)%s' >actual && +test_expect_success '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 && + qz_to_tab_space <expected && Z message two Z Z message one Z Z add bar Z Z $(commit_msg) Z EOF test_cmp expected actual -" +' -test_expect_success 'center alignment formatting at the nth column' " - git log --pretty='format:%h %><|(40)%s' >actual && +test_expect_success 'center alignment formatting at the nth column' ' + git log --pretty="format:%h %><|(40)%s" >actual && # complete the incomplete line at the end echo >>actual && - qz_to_tab_space <<\EOF >expected && + qz_to_tab_space <expected && $head1 message two Z $head2 message one Z $head3 add bar 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_success '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 && + cat <expected && message two message one add bar $(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 ' && - git log --pretty='format:%<(10,trunc)%s%>>(10,ltrunc)% an' >actual && +test_expect_success 'left/right alignment formatting with stealing' ' + git commit --amend -m short --author "long long long " && + git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && # complete the incomplete line at the end echo >>actual && - cat <<\EOF >expected && + cat <expected && short long long long message .. A U Thor add bar A U Thor $(commit_msg "" "8" "..*$") A U Thor EOF test_cmp expected actual -" +' test_done -- cgit v1.2.1 From 17cc2ef1c5f160056f5ca8cf4bd795ddd9b76bd3 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Fri, 5 Jul 2013 16:01:48 +0400 Subject: t4205, t6006, t7102: make functions better readable Function 'test_format' has become harder to read after its change in de6029a2 (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26). Simplify it by moving its "should we expect it to fail?" parameter to the end. Note, current code does not use this last parameter as far as there are no tests expected to fail. We can keep that for future use. Also, reformat comments. Signed-off-by: Alexey Shumkin Improved-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 3 ++- t/t6006-rev-list-format.sh | 28 ++++++++-------------------- t/t7102-reset.sh | 10 ++++++---- 3 files changed, 16 insertions(+), 25 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index ef9770a52b..2933c63709 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -8,7 +8,8 @@ test_description='Test pretty formats' . ./test-lib.sh commit_msg () { - # String "initial. initial" partly in German (translated with Google Translate), + # 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" diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 4751d22217..b32405a760 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -9,8 +9,9 @@ test_description='git rev-list --pretty=format test' . "$TEST_DIRECTORY"/lib-terminal.sh test_tick -# String "added" in German (translated with Google Translate), encoded in UTF-8, -# used as a commit log message below. +# String "added" in German +# (translated with Google Translate), +# encoded in UTF-8, used as a commit log message below. added=$(printf "added (hinzugef\303\274gt) foo") added_iso88591=$(echo "$added" | iconv -f utf-8 -t iso8859-1) # same but "changed" @@ -35,26 +36,13 @@ test_expect_success 'setup' ' git config --unset i18n.commitEncoding ' -# usage: test_format [failure] name format_string expect.$1 - name="format $1" - command="git rev-list --pretty=format:'$2' master >output.$1 && - test_cmp expect.$1 output.$1" - if test $must_fail -eq 1 - then - test_expect_failure "$name" "$command" - else - test_expect_success "$name" "$command" - fi + test_expect_${3:-success} "format $1" " + git rev-list --pretty=format:'$2' master >output.$1 && + test_cmp expect.$1 output.$1 + " } # Feed to --format to provide predictable colored sequences. diff --git a/t/t7102-reset.sh b/t/t7102-reset.sh index 2ef96e9240..4f1c9f9c7f 100755 --- a/t/t7102-reset.sh +++ b/t/t7102-reset.sh @@ -10,14 +10,16 @@ Documented tests for git reset' . ./test-lib.sh commit_msg () { - # String "modify 2nd file (changed)" partly in German(translated with Google Translate), + # String "modify 2nd file (changed)" partly in German + # (translated with Google Translate), # encoded in UTF-8, used as a commit log message below. - msg=$(printf "modify 2nd file (ge\303\244ndert)") + msg="modify 2nd file (ge\303\244ndert)\n" if test -n "$1" then - msg=$(echo $msg | iconv -f utf-8 -t $1) + printf "$msg" | iconv -f utf-8 -t "$1" + else + printf "$msg" fi - echo $msg } test_expect_success 'creating initial files and commits' ' -- cgit v1.2.1 From 0fe6df3ce8e6373536d1a9016cac9126a1aed0da Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Fri, 5 Jul 2013 16:01:49 +0400 Subject: t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set In de6029a (pretty: Add failing tests: --format output should honor logOutputEncoding, 2013-06-26) 'complex-subject' test was changed. Revert it back, because that change actually removed tests for "%b" and "%s" with i18n.commitEncoding set. Also, add two more tests for mentioned above "%b" and "%s" to test encoding conversions with no i18n.commitEncoding set. Signed-off-by: Alexey Shumkin Suggested-by: Johannes Sixt Signed-off-by: Junio C Hamano --- t/t6006-rev-list-format.sh | 41 ++++++++++++++++++++++++++++------------- 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index b32405a760..98744038ec 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -218,12 +218,7 @@ test_expect_success 'setup complex body' ' git config i18n.commitencoding iso8859-1 && echo change2 >foo && git commit -a -F commit-msg && head3=$(git rev-parse --verify HEAD) && - head3_short=$(git rev-parse --short $head3) && - # unset commit encoding config - # otherwise %e does not print encoding value - # and following test fails - git config --unset i18n.commitEncoding - + head3_short=$(git rev-parse --short $head3) ' test_format complex-encoding %e <expected.utf-8 && + commit $head3 + This commit message is much longer than the others, + and it will be encoded in iso8859-1. We should therefore + include an iso8859 character: ¡bueno! + + commit $head2 + commit $head1 + EOF + iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1 +' + +test_format complex-body %b expect commit $head3 && echo >>expect fooQbar && -- cgit v1.2.1 From 37eb772ef3a5da0b28d3759373d714b349306ea4 Mon Sep 17 00:00:00 2001 From: Alexey Shumkin Date: Fri, 5 Jul 2013 16:01:50 +0400 Subject: t4205 (log-pretty-formats): avoid using `sed` For testing truncated log messages 'commit_msg' function uses `sed` to cut a message. On various platforms `sed` behaves differently and results of its work depend on locales installed. So, avoid using `sed`. Use predefined expected outputs instead of calculated ones. Signed-off-by: Alexey Shumkin Signed-off-by: Junio C Hamano --- t/t4205-log-pretty-formats.sh | 26 ++++++++++---------------- 1 file changed, 10 insertions(+), 16 deletions(-) diff --git a/t/t4205-log-pretty-formats.sh b/t/t4205-log-pretty-formats.sh index 2933c63709..fb00041139 100755 --- a/t/t4205-log-pretty-formats.sh +++ b/t/t4205-log-pretty-formats.sh @@ -7,25 +7,19 @@ test_description='Test pretty formats' . ./test-lib.sh +sample_utf8_part=$(printf "f\303\244ng") + 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") + msg="initial. an${sample_utf8_part}lich\n" 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../") + printf "$msg" | iconv -f utf-8 -t "$1" + else + printf "$msg" fi - echo $msg } test_expect_success 'set up basic repos' ' @@ -193,7 +187,7 @@ test_expect_success 'left alignment formatting with trunc' ' message .. message .. add bar Z -$(commit_msg "" "8" "..*$") +initial... EOF test_cmp expected actual ' @@ -206,7 +200,7 @@ test_expect_success 'left alignment formatting with ltrunc' ' ..sage two ..sage one add bar Z -$(commit_msg "" "0" ".\{11\}") +..${sample_utf8_part}lich EOF test_cmp expected actual ' @@ -219,7 +213,7 @@ test_expect_success 'left alignment formatting with mtrunc' ' mess.. two mess.. one add bar Z -$(commit_msg "" "4" ".\{11\}") +init..lich EOF test_cmp expected actual ' @@ -311,7 +305,7 @@ test_expect_success 'left/right alignment formatting with stealing' ' short long long long message .. A U Thor add bar A U Thor -$(commit_msg "" "8" "..*$") A U Thor +initial... A U Thor EOF test_cmp expected actual ' -- cgit v1.2.1