Merge branch 'as/log-output-encoding-in-user-format'

"log --format=" did not honor i18n.logoutputencoding configuration
and this attempts to fix it.

* as/log-output-encoding-in-user-format:
  t4205 (log-pretty-formats): avoid using `sed`
  t6006 (rev-list-format): add tests for "%b" and "%s" for the case i18n.commitEncoding is not set
  t4205, t6006, t7102: make functions better readable
  t4205 (log-pretty-formats): revert back single quotes
  t4041, t4205, t6006, t7102: use iso8859-1 rather than iso-8859-1
  t4205: replace .\+ with ..* in sed commands
  pretty: --format output should honor logOutputEncoding
  pretty: Add failing tests: --format output should honor logOutputEncoding
  t4205 (log-pretty-formats): don't hardcode SHA-1 in expected outputs
  t7102 (reset): don't hardcode SHA-1 in expected outputs
  t6006 (rev-list-format): don't hardcode SHA-1 in expected outputs
This commit is contained in:
Junio C Hamano 2013-07-12 12:04:01 -07:00
commit 8a6482227c
9 changed files with 265 additions and 136 deletions

View File

@ -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) static void print_new_head_line(struct commit *commit)
{ {
const char *hex, *body; const char *hex, *body;
char *msg;
hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV); hex = find_unique_abbrev(commit->object.sha1, DEFAULT_ABBREV);
printf(_("HEAD is now at %s"), hex); 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) { if (body) {
const char *eol; const char *eol;
size_t len; size_t len;
@ -107,6 +109,7 @@ static void print_new_head_line(struct commit *commit)
} }
else else
printf("\n"); printf("\n");
logmsg_free(msg, commit);
} }
static void update_index_from_diff(struct diff_queue_struct *q, static void update_index_from_diff(struct diff_queue_struct *q,

View File

@ -111,6 +111,7 @@ static void show_commit(struct commit *commit, void *data)
ctx.date_mode = revs->date_mode; ctx.date_mode = revs->date_mode;
ctx.date_mode_explicit = revs->date_mode_explicit; ctx.date_mode_explicit = revs->date_mode_explicit;
ctx.fmt = revs->commit_format; ctx.fmt = revs->commit_format;
ctx.output_encoding = get_log_output_encoding();
pretty_print_commit(&ctx, commit, &buf); pretty_print_commit(&ctx, commit, &buf);
if (revs->graph) { if (revs->graph) {
if (buf.len) { if (buf.len) {

View File

@ -137,6 +137,7 @@ void shortlog_add_commit(struct shortlog *log, struct commit *commit)
ctx.subject = ""; ctx.subject = "";
ctx.after_subject = ""; ctx.after_subject = "";
ctx.date_mode = DATE_NORMAL; ctx.date_mode = DATE_NORMAL;
ctx.output_encoding = get_log_output_encoding();
pretty_print_commit(&ctx, commit, &ufbuf); pretty_print_commit(&ctx, commit, &ufbuf);
buffer = ufbuf.buf; buffer = ufbuf.buf;
} else if (*buffer) { } else if (*buffer) {

View File

@ -617,6 +617,7 @@ void show_log(struct rev_info *opt)
ctx.fmt = opt->commit_format; ctx.fmt = opt->commit_format;
ctx.mailmap = opt->mailmap; ctx.mailmap = opt->mailmap;
ctx.color = opt->diffopt.use_color; ctx.color = opt->diffopt.use_color;
ctx.output_encoding = get_log_output_encoding();
pretty_print_commit(&ctx, commit, &msgbuf); pretty_print_commit(&ctx, commit, &msgbuf);
if (opt->add_signoff) if (opt->add_signoff)

View File

@ -226,6 +226,7 @@ static void print_submodule_summary(struct rev_info *rev, FILE *f,
while ((commit = get_revision(rev))) { while ((commit = get_revision(rev))) {
struct pretty_print_context ctx = {0}; struct pretty_print_context ctx = {0};
ctx.date_mode = rev->date_mode; ctx.date_mode = rev->date_mode;
ctx.output_encoding = get_log_output_encoding();
strbuf_setlen(&sb, 0); strbuf_setlen(&sb, 0);
strbuf_addstr(&sb, line_prefix); strbuf_addstr(&sb, line_prefix);
if (commit->object.flags & SYMMETRIC_LEFT) { if (commit->object.flags & SYMMETRIC_LEFT) {

View File

@ -1,6 +1,7 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2009 Jens Lehmann, based on t7401 by Ping Yin # 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 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 . ./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 () { add_file () {
( (
cd "$1" && cd "$1" &&
@ -19,7 +23,8 @@ add_file () {
echo "$name" >"$name" && echo "$name" >"$name" &&
git add "$name" && git add "$name" &&
test_tick && test_tick &&
git commit -m "Add $name" || exit 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 && done >/dev/null &&
git rev-parse --short --verify HEAD git rev-parse --short --verify HEAD
) )
@ -93,7 +98,7 @@ test_expect_success 'modified submodule(forward)' '
git diff-index -p --submodule=log HEAD >actual && git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF && cat >expected <<-EOF &&
Submodule sm1 $head1..$head2: Submodule sm1 $head1..$head2:
> Add foo3 > Add foo3 ($added foo3)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -102,7 +107,7 @@ test_expect_success 'modified submodule(forward)' '
git diff --submodule=log >actual && git diff --submodule=log >actual &&
cat >expected <<-EOF && cat >expected <<-EOF &&
Submodule sm1 $head1..$head2: Submodule sm1 $head1..$head2:
> Add foo3 > Add foo3 ($added foo3)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -111,7 +116,7 @@ test_expect_success 'modified submodule(forward) --submodule' '
git diff --submodule >actual && git diff --submodule >actual &&
cat >expected <<-EOF && cat >expected <<-EOF &&
Submodule sm1 $head1..$head2: Submodule sm1 $head1..$head2:
> Add foo3 > Add foo3 ($added foo3)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -142,8 +147,8 @@ test_expect_success 'modified submodule(backward)' '
git diff-index -p --submodule=log HEAD >actual && git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF && cat >expected <<-EOF &&
Submodule sm1 $head2..$head3 (rewind): Submodule sm1 $head2..$head3 (rewind):
< Add foo3 < Add foo3 ($added foo3)
< Add foo2 < Add foo2 ($added foo2)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -153,10 +158,10 @@ test_expect_success 'modified submodule(backward and forward)' '
git diff-index -p --submodule=log HEAD >actual && git diff-index -p --submodule=log HEAD >actual &&
cat >expected <<-EOF && cat >expected <<-EOF &&
Submodule sm1 $head2...$head4: Submodule sm1 $head2...$head4:
> Add foo5 > Add foo5 ($added foo5)
> Add foo4 > Add foo4 ($added foo4)
< Add foo3 < Add foo3 ($added foo3)
< Add foo2 < Add foo2 ($added foo2)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '

View File

@ -1,20 +1,38 @@
#!/bin/sh #!/bin/sh
# #
# Copyright (c) 2010, Will Palmer # Copyright (c) 2010, Will Palmer
# Copyright (c) 2011, Alexey Shumkin (+ non-UTF-8 commit encoding tests)
# #
test_description='Test pretty formats' test_description='Test pretty formats'
. ./test-lib.sh . ./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="initial. an${sample_utf8_part}lich\n"
if test -n "$1"
then
printf "$msg" | iconv -f utf-8 -t "$1"
else
printf "$msg"
fi
}
test_expect_success 'set up basic repos' ' test_expect_success 'set up basic repos' '
>foo && >foo &&
>bar && >bar &&
git add foo && git add foo &&
test_tick && test_tick &&
git commit -m initial && git config i18n.commitEncoding iso8859-1 &&
git commit -m "$(commit_msg iso8859-1)" &&
git add bar && git add bar &&
test_tick && test_tick &&
git commit -m "add bar" git commit -m "add bar" &&
git config --unset i18n.commitEncoding
' '
test_expect_success 'alias builtin format' ' test_expect_success 'alias builtin format' '
@ -38,6 +56,20 @@ test_expect_success 'alias user-defined format' '
test_cmp expected actual test_cmp expected actual
' '
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 &&
test_cmp expected-s actual-s
'
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
'
test_expect_success 'alias user-defined tformat' ' test_expect_success 'alias user-defined tformat' '
git log --pretty="tformat:%h" >expected && git log --pretty="tformat:%h" >expected &&
git config pretty.test-alias "tformat:%h" && git config pretty.test-alias "tformat:%h" &&
@ -72,13 +104,13 @@ test_expect_success 'alias loop' '
' '
test_expect_success 'NUL separation' ' test_expect_success 'NUL separation' '
printf "add bar\0initial" >expected && printf "add bar\0$(commit_msg)" >expected &&
git log -z --pretty="format:%s" >actual && git log -z --pretty="format:%s" >actual &&
test_cmp expected actual test_cmp expected actual
' '
test_expect_success 'NUL termination' ' test_expect_success 'NUL termination' '
printf "add bar\0initial\0" >expected && printf "add bar\0$(commit_msg)\0" >expected &&
git log -z --pretty="tformat:%s" >actual && git log -z --pretty="tformat:%s" >actual &&
test_cmp expected actual test_cmp expected actual
' '
@ -86,7 +118,7 @@ test_expect_success 'NUL termination' '
test_expect_success 'NUL separation with --stat' ' test_expect_success 'NUL separation with --stat' '
stat0_part=$(git diff --stat HEAD^ HEAD) && stat0_part=$(git diff --stat HEAD^ HEAD) &&
stat1_part=$(git diff-tree --no-commit-id --stat --root 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 && git log -z --stat --pretty="format:%s" >actual &&
test_i18ncmp expected actual test_i18ncmp expected actual
' '
@ -94,25 +126,29 @@ test_expect_success 'NUL separation with --stat' '
test_expect_failure 'NUL termination with --stat' ' test_expect_failure 'NUL termination with --stat' '
stat0_part=$(git diff --stat HEAD^ HEAD) && stat0_part=$(git diff --stat HEAD^ HEAD) &&
stat1_part=$(git diff-tree --no-commit-id --stat --root 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 && git log -z --stat --pretty="tformat:%s" >actual &&
test_i18ncmp expected actual test_i18ncmp expected actual
' '
test_expect_success 'setup more commits' ' test_expect_success 'setup more commits' '
test_commit "message one" one one message-one && 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' ' test_expect_success 'left alignment formatting' '
git log --pretty="format:%<(40)%s" >actual && git log --pretty="format:%<(40)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
message two Z message two Z
message one Z message one Z
add bar Z add bar Z
initial Z $(commit_msg) Z
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -121,11 +157,11 @@ test_expect_success 'left alignment formatting at the nth column' '
git log --pretty="format:%h %<|(40)%s" >actual && git log --pretty="format:%h %<|(40)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
fa33ab1 message two Z $head1 message two Z
7cd6c63 message one Z $head2 message one Z
1711bf9 add bar Z $head3 add bar Z
af20c06 initial Z $head4 $(commit_msg) Z
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -134,11 +170,11 @@ test_expect_success 'left alignment formatting with no padding' '
git log --pretty="format:%<(1)%s" >actual && git log --pretty="format:%<(1)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
cat <<\EOF >expected && cat <<EOF >expected &&
message two message two
message one message one
add bar add bar
initial $(commit_msg)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -147,11 +183,11 @@ test_expect_success 'left alignment formatting with trunc' '
git log --pretty="format:%<(10,trunc)%s" >actual && git log --pretty="format:%<(10,trunc)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
message .. message ..
message .. message ..
add bar Z add bar Z
initial Z initial...
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -160,11 +196,11 @@ test_expect_success 'left alignment formatting with ltrunc' '
git log --pretty="format:%<(10,ltrunc)%s" >actual && git log --pretty="format:%<(10,ltrunc)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
..sage two ..sage two
..sage one ..sage one
add bar Z add bar Z
initial Z ..${sample_utf8_part}lich
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -173,11 +209,11 @@ test_expect_success 'left alignment formatting with mtrunc' '
git log --pretty="format:%<(10,mtrunc)%s" >actual && git log --pretty="format:%<(10,mtrunc)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
mess.. two mess.. two
mess.. one mess.. one
add bar Z add bar Z
initial Z init..lich
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -186,11 +222,11 @@ test_expect_success 'right alignment formatting' '
git log --pretty="format:%>(40)%s" >actual && git log --pretty="format:%>(40)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
Z message two Z message two
Z message one Z message one
Z add bar Z add bar
Z initial Z $(commit_msg)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -199,11 +235,11 @@ test_expect_success 'right alignment formatting at the nth column' '
git log --pretty="format:%h %>|(40)%s" >actual && git log --pretty="format:%h %>|(40)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
fa33ab1 message two $head1 message two
7cd6c63 message one $head2 message one
1711bf9 add bar $head3 add bar
af20c06 initial $head4 $(commit_msg)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -212,11 +248,11 @@ test_expect_success 'right alignment formatting with no padding' '
git log --pretty="format:%>(1)%s" >actual && git log --pretty="format:%>(1)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
cat <<\EOF >expected && cat <<EOF >expected &&
message two message two
message one message one
add bar add bar
initial $(commit_msg)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -225,11 +261,11 @@ test_expect_success 'center alignment formatting' '
git log --pretty="format:%><(40)%s" >actual && git log --pretty="format:%><(40)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
Z message two Z Z message two Z
Z message one Z Z message one Z
Z add bar Z Z add bar Z
Z initial Z Z $(commit_msg) Z
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -238,11 +274,11 @@ test_expect_success 'center alignment formatting at the nth column' '
git log --pretty="format:%h %><|(40)%s" >actual && git log --pretty="format:%h %><|(40)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
qz_to_tab_space <<\EOF >expected && qz_to_tab_space <<EOF >expected &&
fa33ab1 message two Z $head1 message two Z
7cd6c63 message one Z $head2 message one Z
1711bf9 add bar Z $head3 add bar Z
af20c06 initial Z $head4 $(commit_msg) Z
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -251,11 +287,11 @@ test_expect_success 'center alignment formatting with no padding' '
git log --pretty="format:%><(1)%s" >actual && git log --pretty="format:%><(1)%s" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
cat <<\EOF >expected && cat <<EOF >expected &&
message two message two
message one message one
add bar add bar
initial $(commit_msg)
EOF EOF
test_cmp expected actual test_cmp expected actual
' '
@ -265,11 +301,11 @@ test_expect_success 'left/right alignment formatting with stealing' '
git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual && git log --pretty="format:%<(10,trunc)%s%>>(10,ltrunc)% an" >actual &&
# complete the incomplete line at the end # complete the incomplete line at the end
echo >>actual && echo >>actual &&
cat <<\EOF >expected && cat <<EOF >expected &&
short long long long short long long long
message .. A U Thor message .. A U Thor
add bar A U Thor add bar A U Thor
initial A U Thor initial... A U Thor
EOF EOF
test_cmp expected actual test_cmp expected actual
' '

View File

@ -1,20 +1,45 @@
#!/bin/sh #!/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_description='git rev-list --pretty=format test'
. ./test-lib.sh . ./test-lib.sh
. "$TEST_DIRECTORY"/lib-terminal.sh . "$TEST_DIRECTORY"/lib-terminal.sh
test_tick 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 iso8859-1)
# same but "changed"
changed=$(printf "changed (ge\303\244ndert) foo")
changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t iso8859-1)
test_expect_success 'setup' ' test_expect_success 'setup' '
touch foo && git add foo && git commit -m "added foo" && : >foo &&
echo changed >foo && git commit -a -m "changed foo" git add foo &&
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) &&
tree1=$(git rev-parse --verify HEAD:) &&
tree1_short=$(git rev-parse --verify --short $tree1) &&
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 <expected_output # usage: test_format name format_string [failure] <expected_output
test_format () { test_format () {
cat >expect.$1 cat >expect.$1
test_expect_success "format $1" " test_expect_${3:-success} "format $1" "
git rev-list --pretty=format:'$2' master >output.$1 && git rev-list --pretty=format:'$2' master >output.$1 &&
test_cmp expect.$1 output.$1 test_cmp expect.$1 output.$1
" "
@ -32,49 +57,49 @@ has_no_color () {
test_cmp expect "$1" test_cmp expect "$1"
} }
test_format percent %%h <<'EOF' test_format percent %%h <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
%h %h
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
%h %h
EOF EOF
test_format hash %H%n%h <<'EOF' test_format hash %H%n%h <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
131a310eb913d107dd3c09a65d1651175898735d $head2
131a310 $head2_short
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
86c75cfd708a0e5868dc876ed5b8bb66c80b4873 $head1
86c75cf $head1_short
EOF EOF
test_format tree %T%n%t <<'EOF' test_format tree %T%n%t <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
fe722612f26da5064c32ca3843aa154bdb0b08a0 $tree2
fe72261 $tree2_short
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
4d5fcadc293a348e88f777dc0920f11e7d71441c $tree1
4d5fcad $tree1_short
EOF EOF
test_format parents %P%n%p <<'EOF' test_format parents %P%n%p <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
86c75cfd708a0e5868dc876ed5b8bb66c80b4873 $head1
86c75cf $head1_short
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
EOF EOF
# we don't test relative here # we don't test relative here
test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF' test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
A U Thor A U Thor
author@example.com author@example.com
Thu Apr 7 15:13:13 2005 -0700 Thu Apr 7 15:13:13 2005 -0700
Thu, 7 Apr 2005 15:13:13 -0700 Thu, 7 Apr 2005 15:13:13 -0700
1112911993 1112911993
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
A U Thor A U Thor
author@example.com author@example.com
Thu Apr 7 15:13:13 2005 -0700 Thu Apr 7 15:13:13 2005 -0700
@ -82,14 +107,14 @@ Thu, 7 Apr 2005 15:13:13 -0700
1112911993 1112911993
EOF EOF
test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF' test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
C O Mitter C O Mitter
committer@example.com committer@example.com
Thu Apr 7 15:13:13 2005 -0700 Thu Apr 7 15:13:13 2005 -0700
Thu, 7 Apr 2005 15:13:13 -0700 Thu, 7 Apr 2005 15:13:13 -0700
1112911993 1112911993
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
C O Mitter C O Mitter
committer@example.com committer@example.com
Thu Apr 7 15:13:13 2005 -0700 Thu Apr 7 15:13:13 2005 -0700
@ -97,43 +122,45 @@ Thu, 7 Apr 2005 15:13:13 -0700
1112911993 1112911993
EOF EOF
test_format encoding %e <<'EOF' test_format encoding %e <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 iso8859-1
commit $head1
iso8859-1
EOF EOF
test_format subject %s <<'EOF' test_format subject %s <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
changed foo $changed
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
added foo $added
EOF EOF
test_format body %b <<'EOF' test_format body %b <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
EOF EOF
test_format raw-body %B <<'EOF' test_format raw-body %B <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
changed foo $changed
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
added foo $added
EOF EOF
test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF' test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
foobarbazxyzzy foobarbazxyzzy
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
foobarbazxyzzy foobarbazxyzzy
EOF EOF
test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF' test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
foo foo
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
foo foo
EOF EOF
@ -179,46 +206,71 @@ test_expect_success '%C(auto) respects --color=auto (stdout not tty)' '
) )
' '
cat >commit-msg <<'EOF' iconv -f utf-8 -t iso8859-1 > commit-msg <<EOF
Test printing of complex bodies Test printing of complex bodies
This commit message is much longer than the others, This commit message is much longer than the others,
and it will be encoded in iso8859-1. We should therefore and it will be encoded in iso8859-1. We should therefore
include an iso8859 character: ¡bueno! include an iso8859 character: ¡bueno!
EOF EOF
test_expect_success 'setup complex body' ' test_expect_success 'setup complex body' '
git config i18n.commitencoding iso8859-1 && git config i18n.commitencoding iso8859-1 &&
echo change2 >foo && git commit -a -F commit-msg 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' test_format complex-encoding %e <<EOF
commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 commit $head3
iso8859-1
commit $head2
iso8859-1
commit $head1
iso8859-1 iso8859-1
commit 131a310eb913d107dd3c09a65d1651175898735d
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
EOF EOF
test_format complex-subject %s <<'EOF' test_format complex-subject %s <<EOF
commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 commit $head3
Test printing of complex bodies Test printing of complex bodies
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
changed foo $changed_iso88591
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
added foo $added_iso88591
EOF EOF
test_format complex-body %b <<'EOF' test_expect_success 'prepare expected messages (for test %b)' '
commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 cat <<-EOF >expected.utf-8 &&
This commit message is much longer than the others, commit $head3
and it will be encoded in iso8859-1. We should therefore This commit message is much longer than the others,
include an iso8859 character: ¡bueno! and it will be encoded in iso8859-1. We should therefore
include an iso8859 character: ¡bueno!
commit 131a310eb913d107dd3c09a65d1651175898735d commit $head2
commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 commit $head1
EOF
iconv -f utf-8 -t iso8859-1 expected.utf-8 >expected.iso8859-1
'
test_format complex-body %b <expected.iso8859-1
# Git uses i18n.commitEncoding if no i18n.logOutputEncoding set
# so unset i18n.commitEncoding to test encoding conversion
git config --unset i18n.commitEncoding
test_format complex-subject-commitencoding-unset %s <<EOF
commit $head3
Test printing of complex bodies
commit $head2
$changed
commit $head1
$added
EOF EOF
test_format complex-body-commitencoding-unset %b <expected.utf-8
test_expect_success '%x00 shows NUL' ' test_expect_success '%x00 shows NUL' '
echo >expect commit 1ed88da4a5b5ed8c449114ac131efc62178734c3 && echo >expect commit $head3 &&
echo >>expect fooQbar && echo >>expect fooQbar &&
git rev-list -1 --format=foo%x00bar HEAD >actual.nul && git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
nul_to_q <actual.nul >actual && nul_to_q <actual.nul >actual &&
@ -265,12 +317,12 @@ test_expect_success 'add LF before non-empty (2)' '
test_expect_success 'add SP before non-empty (1)' ' test_expect_success 'add SP before non-empty (1)' '
git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual && git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
test $(wc -w <actual) = 2 test $(wc -w <actual) = 3
' '
test_expect_success 'add SP before non-empty (2)' ' test_expect_success 'add SP before non-empty (2)' '
git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual && git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
test $(wc -w <actual) = 4 test $(wc -w <actual) = 6
' '
test_expect_success '--abbrev' ' test_expect_success '--abbrev' '

View File

@ -9,6 +9,19 @@ Documented tests for git reset'
. ./test-lib.sh . ./test-lib.sh
commit_msg () {
# String "modify 2nd file (changed)" partly in German
# (translated with Google Translate),
# encoded in UTF-8, used as a commit log message below.
msg="modify 2nd file (ge\303\244ndert)\n"
if test -n "$1"
then
printf "$msg" | iconv -f utf-8 -t "$1"
else
printf "$msg"
fi
}
test_expect_success 'creating initial files and commits' ' test_expect_success 'creating initial files and commits' '
test_tick && test_tick &&
echo "1st file" >first && echo "1st file" >first &&
@ -28,7 +41,7 @@ test_expect_success 'creating initial files and commits' '
echo "1st line 2nd file" >secondfile && echo "1st line 2nd file" >secondfile &&
echo "2nd line 2nd file" >>secondfile && echo "2nd line 2nd file" >>secondfile &&
git commit -a -m "modify 2nd file" && git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
head5=$(git rev-parse --verify HEAD) head5=$(git rev-parse --verify HEAD)
' '
# git log --pretty=oneline # to see those SHA1 involved # git log --pretty=oneline # to see those SHA1 involved
@ -44,6 +57,20 @@ check_changes () {
done | test_cmp .cat_expect - done | test_cmp .cat_expect -
} }
test_expect_success '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 (iso8859-1 logoutputencoding)' '
hex=$(git log -1 --format="%h") &&
git -c "i18n.logOutputEncoding=iso8859-1" reset --hard > .actual &&
echo HEAD is now at $hex $(commit_msg iso8859-1) > .expected &&
test_cmp .expected .actual
'
>.diff_expect >.diff_expect
>.cached_expect >.cached_expect
cat >.cat_expect <<EOF cat >.cat_expect <<EOF
@ -192,7 +219,8 @@ test_expect_success \
'changing files and redo the last commit should succeed' ' 'changing files and redo the last commit should succeed' '
echo "3rd line 2nd file" >>secondfile && echo "3rd line 2nd file" >>secondfile &&
git commit -a -C ORIG_HEAD && git commit -a -C ORIG_HEAD &&
check_changes 3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d && head4=$(git rev-parse --verify HEAD) &&
check_changes $head4 &&
test "$(git rev-parse ORIG_HEAD)" = \ test "$(git rev-parse ORIG_HEAD)" = \
$head5 $head5
' '
@ -211,7 +239,7 @@ test_expect_success \
git reset --hard HEAD~2 && git reset --hard HEAD~2 &&
check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e && check_changes ddaefe00f1da16864591c61fdc7adb5d7cd6b74e &&
test "$(git rev-parse ORIG_HEAD)" = \ test "$(git rev-parse ORIG_HEAD)" = \
3d3b7be011a58ca0c179ae45d94e6c83c0b0cd0d $head4
' '
>.diff_expect >.diff_expect
@ -303,7 +331,7 @@ test_expect_success 'redoing the last two commits should succeed' '
echo "1st line 2nd file" >secondfile && echo "1st line 2nd file" >secondfile &&
echo "2nd line 2nd file" >>secondfile && echo "2nd line 2nd file" >>secondfile &&
git commit -a -m "modify 2nd file" && git -c "i18n.commitEncoding=iso8859-1" commit -a -m "$(commit_msg iso8859-1)" &&
check_changes $head5 check_changes $head5
' '
@ -326,10 +354,11 @@ test_expect_success '--hard reset to HEAD should clear a failed merge' '
git checkout branch2 && git checkout branch2 &&
echo "3rd line in branch2" >>secondfile && echo "3rd line in branch2" >>secondfile &&
git commit -a -m "change in branch2" && git commit -a -m "change in branch2" &&
head3=$(git rev-parse --verify HEAD) &&
test_must_fail git pull . branch1 && test_must_fail git pull . branch1 &&
git reset --hard && git reset --hard &&
check_changes 77abb337073fb4369a7ad69ff6f5ec0e4d6b54bb check_changes $head3
' '
>.diff_expect >.diff_expect