Skip to content

Commit

Permalink
pretty: Add failing tests: --format output should honor logOutputEnco…
Browse files Browse the repository at this point in the history
…ding

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>
  • Loading branch information
Alexey Shumkin authored and Junio C Hamano committed Jun 26, 2013
1 parent a742f2a commit de6029a
Show file tree
Hide file tree
Showing 4 changed files with 199 additions and 97 deletions.
35 changes: 20 additions & 15 deletions t/t4041-diff-submodule-option.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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" &&
Expand All @@ -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
)
Expand Down Expand Up @@ -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
'
Expand All @@ -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
'
Expand Down
Loading

0 comments on commit de6029a

Please sign in to comment.