diff options
Diffstat (limited to 't/t6006-rev-list-format.sh')
-rwxr-xr-x | t/t6006-rev-list-format.sh | 372 |
1 files changed, 282 insertions, 90 deletions
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh index 444279077e..a02a45afd2 100755 --- a/t/t6006-rev-list-format.sh +++ b/t/t6006-rev-list-format.sh @@ -1,67 +1,118 @@ #!/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 +# Tested non-UTF-8 encoding +test_encoding="ISO8859-1" + +# String "added" in German +# (translated with Google Translate), +# encoded in UTF-8, used as a commit log message below. +added_utf8_part=$(printf "\303\274") +added_utf8_part_iso88591=$(echo "$added_utf8_part" | iconv -f utf-8 -t $test_encoding) +added=$(printf "added (hinzugef${added_utf8_part}gt) foo") +added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding) +# same but "changed" +changed_utf8_part=$(printf "\303\244") +changed_utf8_part_iso88591=$(echo "$changed_utf8_part" | iconv -f utf-8 -t $test_encoding) +changed=$(printf "changed (ge${changed_utf8_part}ndert) foo") +changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding) + +# Count of char to truncate +# Number is chosen so, that non-ACSII characters +# (see $added_utf8_part and $changed_utf8_part) +# fall into truncated parts of appropriate words both from left and right +truncate_count=20 + 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 config i18n.commitEncoding $test_encoding && + echo "$added_iso88591" | git commit -F - && + 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 && + echo "$changed_iso88591" | git commit -a -F - && + 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 -test_format() { +# usage: test_format name format_string [failure] <expected_output +test_format () { cat >expect.$1 - test_expect_success "format $1" " -git rev-list --pretty=format:'$2' master >output.$1 && -test_cmp expect.$1 output.$1 -" + 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. +AUTO_COLOR='%C(auto,red)foo%C(auto,reset)' +has_color () { + printf '\033[31mfoo\033[m\n' >expect && + test_cmp expect "$1" +} + +has_no_color () { + echo foo >expect && + test_cmp expect "$1" } -test_format percent %%h <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d +test_format percent %%h <<EOF +commit $head2 %h -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +commit $head1 %h EOF -test_format hash %H%n%h <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -131a310eb913d107dd3c09a65d1651175898735d -131a310 -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cf +test_format hash %H%n%h <<EOF +commit $head2 +$head2 +$head2_short +commit $head1 +$head1 +$head1_short EOF -test_format tree %T%n%t <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -fe722612f26da5064c32ca3843aa154bdb0b08a0 -fe72261 -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -4d5fcadc293a348e88f777dc0920f11e7d71441c -4d5fcad +test_format tree %T%n%t <<EOF +commit $head2 +$tree2 +$tree2_short +commit $head1 +$tree1 +$tree1_short EOF -test_format parents %P%n%p <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -86c75cf -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +test_format parents %P%n%p <<EOF +commit $head2 +$head1 +$head1_short +commit $head1 EOF # we don't test relative here -test_format author %an%n%ae%n%ad%n%aD%n%at <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d +test_format author %an%n%ae%n%ad%n%aD%n%at <<EOF +commit $head2 A U Thor author@example.com Thu Apr 7 15:13:13 2005 -0700 Thu, 7 Apr 2005 15:13:13 -0700 1112911993 -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +commit $head1 A U Thor author@example.com Thu Apr 7 15:13:13 2005 -0700 @@ -69,14 +120,14 @@ Thu, 7 Apr 2005 15:13:13 -0700 1112911993 EOF -test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d +test_format committer %cn%n%ce%n%cd%n%cD%n%ct <<EOF +commit $head2 C O Mitter committer@example.com Thu Apr 7 15:13:13 2005 -0700 Thu, 7 Apr 2005 15:13:13 -0700 1112911993 -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +commit $head1 C O Mitter committer@example.com Thu Apr 7 15:13:13 2005 -0700 @@ -84,86 +135,213 @@ Thu, 7 Apr 2005 15:13:13 -0700 1112911993 EOF -test_format encoding %e <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +test_format encoding %e <<EOF +commit $head2 +$test_encoding +commit $head1 +$test_encoding EOF -test_format subject %s <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -changed foo -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -added foo +test_format subject %s <<EOF +commit $head2 +$changed +commit $head1 +$added EOF -test_format body %b <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +test_format subject-truncated "%<($truncate_count,trunc)%s" <<EOF +commit $head2 +changed (ge${changed_utf8_part}ndert).. +commit $head1 +added (hinzugef${added_utf8_part}gt.. EOF -test_format raw-body %B <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d -changed foo +test_format body %b <<EOF +commit $head2 +commit $head1 +EOF + +test_format raw-body %B <<EOF +commit $head2 +$changed -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -added foo +commit $head1 +$added EOF -test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d +test_format colors %Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy <<EOF +commit $head2 [31mfoo[32mbar[34mbaz[mxyzzy -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +commit $head1 [31mfoo[32mbar[34mbaz[mxyzzy EOF -test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<'EOF' -commit 131a310eb913d107dd3c09a65d1651175898735d +test_format advanced-colors '%C(red yellow bold)foo%C(reset)' <<EOF +commit $head2 [1;31;43mfoo[m -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +commit $head1 [1;31;43mfoo[m EOF -cat >commit-msg <<'EOF' +test_expect_success '%C(auto) does not enable color by default' ' + git log --format=$AUTO_COLOR -1 >actual && + has_no_color actual +' + +test_expect_success '%C(auto) enables colors for color.diff' ' + git -c color.diff=always log --format=$AUTO_COLOR -1 >actual && + has_color actual +' + +test_expect_success '%C(auto) enables colors for color.ui' ' + git -c color.ui=always log --format=$AUTO_COLOR -1 >actual && + has_color actual +' + +test_expect_success '%C(auto) respects --color' ' + git log --format=$AUTO_COLOR -1 --color >actual && + has_color actual +' + +test_expect_success '%C(auto) respects --no-color' ' + git -c color.ui=always log --format=$AUTO_COLOR -1 --no-color >actual && + has_no_color actual +' + +test_expect_success TTY '%C(auto) respects --color=auto (stdout is tty)' ' + test_terminal env TERM=vt100 \ + git log --format=$AUTO_COLOR -1 --color=auto >actual && + has_color actual +' + +test_expect_success '%C(auto) respects --color=auto (stdout not tty)' ' + ( + TERM=vt100 && export TERM && + git log --format=$AUTO_COLOR -1 --color=auto >actual && + has_no_color actual + ) +' + +iconv -f utf-8 -t $test_encoding > commit-msg <<EOF Test printing of complex bodies 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! +and it will be encoded in $test_encoding. We should therefore +include an ISO8859 character: ¡bueno! EOF + test_expect_success 'setup complex body' ' -git config i18n.commitencoding iso8859-1 && - echo change2 >foo && git commit -a -F commit-msg + git config i18n.commitencoding $test_encoding && + 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 f58db70b055c5718631e5c61528b28b12090cdea -iso8859-1 -commit 131a310eb913d107dd3c09a65d1651175898735d -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +test_format complex-encoding %e <<EOF +commit $head3 +$test_encoding +commit $head2 +$test_encoding +commit $head1 +$test_encoding EOF -test_format complex-subject %s <<'EOF' -commit f58db70b055c5718631e5c61528b28b12090cdea +test_format complex-subject %s <<EOF +commit $head3 Test printing of complex bodies -commit 131a310eb913d107dd3c09a65d1651175898735d -changed foo -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 -added foo +commit $head2 +$changed_iso88591 +commit $head1 +$added_iso88591 EOF -test_format complex-body %b <<'EOF' -commit f58db70b055c5718631e5c61528b28b12090cdea -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! +test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF +commit $head3 +Test printing of c.. +commit $head2 +changed (ge${changed_utf8_part_iso88591}ndert).. +commit $head1 +added (hinzugef${added_utf8_part_iso88591}gt.. +EOF + +test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF +commit $head3 +Test prin..ex bodies +commit $head2 +changed (..dert) foo +commit $head1 +added (hi..f${added_utf8_part_iso88591}gt) foo +EOF + +test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF +commit $head3 +.. of complex bodies +commit $head2 +..ged (ge${changed_utf8_part_iso88591}ndert) foo +commit $head1 +.. (hinzugef${added_utf8_part_iso88591}gt) foo +EOF + +test_expect_success 'prepare expected messages (for test %b)' ' + cat <<-EOF >expected.utf-8 && + commit $head3 + This commit message is much longer than the others, + and it will be encoded in $test_encoding. We should therefore + include an ISO8859 character: ¡bueno! + + commit $head2 + commit $head1 + EOF + iconv -f utf-8 -t $test_encoding 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 -commit 131a310eb913d107dd3c09a65d1651175898735d -commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873 +test_format complex-subject-commitencoding-unset-trunc "%<($truncate_count,trunc)%s" <<EOF +commit $head3 +Test printing of c.. +commit $head2 +changed (ge${changed_utf8_part}ndert).. +commit $head1 +added (hinzugef${added_utf8_part}gt.. EOF +test_format complex-subject-commitencoding-unset-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF +commit $head3 +Test prin..ex bodies +commit $head2 +changed (..dert) foo +commit $head1 +added (hi..f${added_utf8_part}gt) foo +EOF + +test_format complex-subject-commitencoding-unset-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF +commit $head3 +.. of complex bodies +commit $head2 +..ged (ge${changed_utf8_part}ndert) foo +commit $head1 +.. (hinzugef${added_utf8_part}gt) foo +EOF + +test_format complex-body-commitencoding-unset %b <expected.utf-8 + test_expect_success '%x00 shows NUL' ' - echo >expect commit f58db70b055c5718631e5c61528b28b12090cdea && + echo >expect commit $head3 && echo >>expect fooQbar && git rev-list -1 --format=foo%x00bar HEAD >actual.nul && nul_to_q <actual.nul >actual && @@ -188,34 +366,34 @@ test_expect_success 'empty email' ' test_expect_success 'del LF before empty (1)' ' git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual && - test $(wc -l <actual) = 2 + test_line_count = 2 actual ' test_expect_success 'del LF before empty (2)' ' git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual && - test $(wc -l <actual) = 6 && + test_line_count = 6 actual && grep "^$" actual ' test_expect_success 'add LF before non-empty (1)' ' git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual && - test $(wc -l <actual) = 2 + test_line_count = 2 actual ' test_expect_success 'add LF before non-empty (2)' ' git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual && - test $(wc -l <actual) = 6 && + test_line_count = 6 actual && grep "^$" actual ' test_expect_success 'add SP before non-empty (1)' ' 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)' ' git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual && - test $(wc -w <actual) = 4 + test $(wc -w <actual) = 6 ' test_expect_success '--abbrev' ' @@ -278,8 +456,22 @@ test_expect_success 'oneline with empty message' ' git commit -m "dummy" --allow-empty && git filter-branch --msg-filter "sed -e s/dummy//" HEAD^^.. && git rev-list --oneline HEAD >test.txt && - test $(git rev-list --oneline HEAD | wc -l) -eq 5 && - test $(git rev-list --oneline --graph HEAD | wc -l) -eq 5 + test_line_count = 5 test.txt && + git rev-list --oneline --graph HEAD >testg.txt && + test_line_count = 5 testg.txt +' + +test_expect_success 'single-character name is parsed correctly' ' + git commit --author="a <a@example.com>" --allow-empty -m foo && + echo "a <a@example.com>" >expect && + git log -1 --format="%an <%ae>" >actual && + test_cmp expect actual +' + +test_expect_success 'unused %G placeholders are passed through' ' + echo "%GX %G" >expect && + git log -1 --format="%GX %G" >actual && + test_cmp expect actual ' test_done |