2007-03-28 02:08:28 +02:00
|
|
|
#!/bin/sh
|
|
|
|
|
2013-06-26 12:19:49 +02:00
|
|
|
# Copyright (c) 2009 Jens Lehmann
|
|
|
|
# Copyright (c) 2011 Alexey Shumkin (+ non-UTF-8 commit encoding tests)
|
|
|
|
|
2007-07-03 07:52:14 +02:00
|
|
|
test_description='git rev-list --pretty=format test'
|
2007-03-28 02:08:28 +02:00
|
|
|
|
2020-11-19 00:44:36 +01:00
|
|
|
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
|
tests: mark tests relying on the current default for `init.defaultBranch`
In addition to the manual adjustment to let the `linux-gcc` CI job run
the test suite with `master` and then with `main`, this patch makes sure
that GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME is set in all test scripts
that currently rely on the initial branch name being `master by default.
To determine which test scripts to mark up, the first step was to
force-set the default branch name to `master` in
- all test scripts that contain the keyword `master`,
- t4211, which expects `t/t4211/history.export` with a hard-coded ref to
initialize the default branch,
- t5560 because it sources `t/t556x_common` which uses `master`,
- t8002 and t8012 because both source `t/annotate-tests.sh` which also
uses `master`)
This trick was performed by this command:
$ sed -i '/^ *\. \.\/\(test-lib\|lib-\(bash\|cvs\|git-svn\)\|gitweb-lib\)\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' $(git grep -l master t/t[0-9]*.sh) \
t/t4211*.sh t/t5560*.sh t/t8002*.sh t/t8012*.sh
After that, careful, manual inspection revealed that some of the test
scripts containing the needle `master` do not actually rely on a
specific default branch name: either they mention `master` only in a
comment, or they initialize that branch specificially, or they do not
actually refer to the current default branch. Therefore, the
aforementioned modification was undone in those test scripts thusly:
$ git checkout HEAD -- \
t/t0027-auto-crlf.sh t/t0060-path-utils.sh \
t/t1011-read-tree-sparse-checkout.sh \
t/t1305-config-include.sh t/t1309-early-config.sh \
t/t1402-check-ref-format.sh t/t1450-fsck.sh \
t/t2024-checkout-dwim.sh \
t/t2106-update-index-assume-unchanged.sh \
t/t3040-subprojects-basic.sh t/t3301-notes.sh \
t/t3308-notes-merge.sh t/t3423-rebase-reword.sh \
t/t3436-rebase-more-options.sh \
t/t4015-diff-whitespace.sh t/t4257-am-interactive.sh \
t/t5323-pack-redundant.sh t/t5401-update-hooks.sh \
t/t5511-refspec.sh t/t5526-fetch-submodules.sh \
t/t5529-push-errors.sh t/t5530-upload-pack-error.sh \
t/t5548-push-porcelain.sh \
t/t5552-skipping-fetch-negotiator.sh \
t/t5572-pull-submodule.sh t/t5608-clone-2gb.sh \
t/t5614-clone-submodules-shallow.sh \
t/t7508-status.sh t/t7606-merge-custom.sh \
t/t9302-fast-import-unpack-limit.sh
We excluded one set of test scripts in these commands, though: the range
of `git p4` tests. The reason? `git p4` stores the (foreign) remote
branch in the branch called `p4/master`, which is obviously not the
default branch. Manual analysis revealed that only five of these tests
actually require a specific default branch name to pass; They were
modified thusly:
$ sed -i '/^ *\. \.\/lib-git-p4\.sh$/i\
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=master\
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME\
' t/t980[0167]*.sh t/t9811*.sh
Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2020-11-19 00:44:19 +01:00
|
|
|
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
|
|
|
|
|
2007-03-28 02:08:28 +02:00
|
|
|
. ./test-lib.sh
|
2012-12-17 23:56:49 +01:00
|
|
|
. "$TEST_DIRECTORY"/lib-terminal.sh
|
2007-03-28 02:08:28 +02:00
|
|
|
|
|
|
|
test_tick
|
2014-05-21 15:20:04 +02:00
|
|
|
# Tested non-UTF-8 encoding
|
|
|
|
test_encoding="ISO8859-1"
|
|
|
|
|
2013-07-05 14:01:48 +02:00
|
|
|
# String "added" in German
|
|
|
|
# (translated with Google Translate),
|
|
|
|
# encoded in UTF-8, used as a commit log message below.
|
2014-05-21 15:20:06 +02:00
|
|
|
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")
|
2014-05-21 15:20:04 +02:00
|
|
|
added_iso88591=$(echo "$added" | iconv -f utf-8 -t $test_encoding)
|
2013-06-26 12:19:49 +02:00
|
|
|
# same but "changed"
|
2014-05-21 15:20:06 +02:00
|
|
|
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")
|
2014-05-21 15:20:04 +02:00
|
|
|
changed_iso88591=$(echo "$changed" | iconv -f utf-8 -t $test_encoding)
|
2013-06-26 12:19:49 +02:00
|
|
|
|
2014-05-21 15:20:06 +02:00
|
|
|
# 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
|
|
|
|
|
2007-03-28 02:08:28 +02:00
|
|
|
test_expect_success 'setup' '
|
2013-06-26 12:19:46 +02:00
|
|
|
: >foo &&
|
|
|
|
git add foo &&
|
2014-05-21 15:20:04 +02:00
|
|
|
git config i18n.commitEncoding $test_encoding &&
|
2013-09-02 16:44:54 +02:00
|
|
|
echo "$added_iso88591" | git commit -F - &&
|
2013-06-26 12:19:46 +02:00
|
|
|
head1=$(git rev-parse --verify HEAD) &&
|
|
|
|
head1_short=$(git rev-parse --verify --short $head1) &&
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
head1_short4=$(git rev-parse --verify --short=4 $head1) &&
|
2013-06-26 12:19:46 +02:00
|
|
|
tree1=$(git rev-parse --verify HEAD:) &&
|
|
|
|
tree1_short=$(git rev-parse --verify --short $tree1) &&
|
2013-06-26 12:19:49 +02:00
|
|
|
echo "$changed" > foo &&
|
2013-09-02 16:44:54 +02:00
|
|
|
echo "$changed_iso88591" | git commit -a -F - &&
|
2013-06-26 12:19:46 +02:00
|
|
|
head2=$(git rev-parse --verify HEAD) &&
|
|
|
|
head2_short=$(git rev-parse --verify --short $head2) &&
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
head2_short4=$(git rev-parse --verify --short=4 $head2) &&
|
2013-06-26 12:19:46 +02:00
|
|
|
tree2=$(git rev-parse --verify HEAD:) &&
|
2015-03-20 11:07:15 +01:00
|
|
|
tree2_short=$(git rev-parse --verify --short $tree2) &&
|
2013-06-26 12:19:49 +02:00
|
|
|
git config --unset i18n.commitEncoding
|
2007-03-28 02:08:28 +02:00
|
|
|
'
|
|
|
|
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
# usage: test_format [argument...] name format_string [failure] <expected_output
|
2012-12-17 23:56:23 +01:00
|
|
|
test_format () {
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
local args=
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
--*)
|
|
|
|
args="$args $1"
|
|
|
|
shift;;
|
|
|
|
*)
|
|
|
|
break;;
|
|
|
|
esac
|
|
|
|
done
|
2007-03-28 02:08:28 +02:00
|
|
|
cat >expect.$1
|
2013-07-05 14:01:48 +02:00
|
|
|
test_expect_${3:-success} "format $1" "
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
git rev-list $args --pretty=format:'$2' main >output.$1 &&
|
|
|
|
test_cmp expect.$1 output.$1
|
|
|
|
"
|
|
|
|
}
|
|
|
|
|
|
|
|
# usage: test_pretty [argument...] name format_name [failure] <expected_output
|
|
|
|
test_pretty () {
|
|
|
|
local args=
|
|
|
|
while true
|
|
|
|
do
|
|
|
|
case "$1" in
|
|
|
|
--*)
|
|
|
|
args="$args $1"
|
|
|
|
shift;;
|
|
|
|
*)
|
|
|
|
break;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
cat >expect.$1
|
|
|
|
test_expect_${3:-success} "pretty $1 (without --no-commit-header)" "
|
|
|
|
git rev-list $args --pretty='$2' main >output.$1 &&
|
|
|
|
test_cmp expect.$1 output.$1
|
|
|
|
"
|
|
|
|
test_expect_${3:-success} "pretty $1 (with --no-commit-header)" "
|
|
|
|
git rev-list $args --no-commit-header --pretty='$2' main >output.$1 &&
|
2013-07-05 14:01:48 +02:00
|
|
|
test_cmp expect.$1 output.$1
|
|
|
|
"
|
2007-03-28 02:08:28 +02:00
|
|
|
}
|
|
|
|
|
2012-12-17 23:56:49 +01:00
|
|
|
# Feed to --format to provide predictable colored sequences.
|
pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.
In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.
However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.
So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 17:08:46 +02:00
|
|
|
BASIC_COLOR='%Credfoo%Creset'
|
|
|
|
COLOR='%C(red)foo%C(reset)'
|
2012-12-17 23:56:49 +01:00
|
|
|
AUTO_COLOR='%C(auto,red)foo%C(auto,reset)'
|
pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.
In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.
However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.
So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 17:08:46 +02:00
|
|
|
ALWAYS_COLOR='%C(always,red)foo%C(always,reset)'
|
2012-12-17 23:56:49 +01:00
|
|
|
has_color () {
|
2017-07-13 16:58:41 +02:00
|
|
|
test_decode_color <"$1" >decoded &&
|
|
|
|
echo "<RED>foo<RESET>" >expect &&
|
|
|
|
test_cmp expect decoded
|
2012-12-17 23:56:49 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
has_no_color () {
|
|
|
|
echo foo >expect &&
|
|
|
|
test_cmp expect "$1"
|
|
|
|
}
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format percent %%h <<EOF
|
|
|
|
commit $head2
|
2010-01-13 18:35:31 +01:00
|
|
|
%h
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2010-01-13 18:35:31 +01:00
|
|
|
%h
|
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format hash %H%n%h <<EOF
|
|
|
|
commit $head2
|
|
|
|
$head2
|
|
|
|
$head2_short
|
|
|
|
commit $head1
|
|
|
|
$head1
|
|
|
|
$head1_short
|
2007-03-28 02:08:28 +02:00
|
|
|
EOF
|
|
|
|
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
test_format --no-commit-header hash-no-header %H%n%h <<EOF
|
|
|
|
$head2
|
|
|
|
$head2_short
|
|
|
|
$head1
|
|
|
|
$head1_short
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_format --abbrev-commit --abbrev=0 --no-commit-header hash-no-header-abbrev %H%n%h <<EOF
|
|
|
|
$head2
|
|
|
|
$head2_short4
|
|
|
|
$head1
|
|
|
|
$head1_short4
|
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format tree %T%n%t <<EOF
|
|
|
|
commit $head2
|
|
|
|
$tree2
|
|
|
|
$tree2_short
|
|
|
|
commit $head1
|
|
|
|
$tree1
|
|
|
|
$tree1_short
|
2007-03-28 02:08:28 +02:00
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format parents %P%n%p <<EOF
|
|
|
|
commit $head2
|
|
|
|
$head1
|
|
|
|
$head1_short
|
|
|
|
commit $head1
|
2007-03-28 22:33:37 +02:00
|
|
|
|
|
|
|
|
2007-03-28 02:08:28 +02:00
|
|
|
EOF
|
|
|
|
|
|
|
|
# we don't test relative here
|
2019-10-29 13:09:14 +01:00
|
|
|
test_format author %an%n%ae%n%al%n%ad%n%aD%n%at <<EOF
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2019-10-25 01:36:15 +02:00
|
|
|
$GIT_AUTHOR_NAME
|
|
|
|
$GIT_AUTHOR_EMAIL
|
2019-10-29 13:09:14 +01:00
|
|
|
$TEST_AUTHOR_LOCALNAME
|
2007-03-28 02:08:28 +02:00
|
|
|
Thu Apr 7 15:13:13 2005 -0700
|
|
|
|
Thu, 7 Apr 2005 15:13:13 -0700
|
|
|
|
1112911993
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2019-10-25 01:36:15 +02:00
|
|
|
$GIT_AUTHOR_NAME
|
|
|
|
$GIT_AUTHOR_EMAIL
|
2019-10-29 13:09:14 +01:00
|
|
|
$TEST_AUTHOR_LOCALNAME
|
2007-03-28 02:08:28 +02:00
|
|
|
Thu Apr 7 15:13:13 2005 -0700
|
|
|
|
Thu, 7 Apr 2005 15:13:13 -0700
|
|
|
|
1112911993
|
|
|
|
EOF
|
|
|
|
|
2019-10-29 13:09:14 +01:00
|
|
|
test_format committer %cn%n%ce%n%cl%n%cd%n%cD%n%ct <<EOF
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2019-10-25 01:36:15 +02:00
|
|
|
$GIT_COMMITTER_NAME
|
|
|
|
$GIT_COMMITTER_EMAIL
|
2019-10-29 13:09:14 +01:00
|
|
|
$TEST_COMMITTER_LOCALNAME
|
2007-03-28 02:08:28 +02:00
|
|
|
Thu Apr 7 15:13:13 2005 -0700
|
|
|
|
Thu, 7 Apr 2005 15:13:13 -0700
|
|
|
|
1112911993
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2019-10-25 01:36:15 +02:00
|
|
|
$GIT_COMMITTER_NAME
|
|
|
|
$GIT_COMMITTER_EMAIL
|
2019-10-29 13:09:14 +01:00
|
|
|
$TEST_COMMITTER_LOCALNAME
|
2007-03-28 02:08:28 +02:00
|
|
|
Thu Apr 7 15:13:13 2005 -0700
|
|
|
|
Thu, 7 Apr 2005 15:13:13 -0700
|
|
|
|
1112911993
|
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format encoding %e <<EOF
|
|
|
|
commit $head2
|
2014-05-21 15:20:04 +02:00
|
|
|
$test_encoding
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2014-05-21 15:20:04 +02:00
|
|
|
$test_encoding
|
2007-03-28 02:08:28 +02:00
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:50 +02:00
|
|
|
test_format subject %s <<EOF
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2013-06-26 12:19:49 +02:00
|
|
|
$changed
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2013-06-26 12:19:49 +02:00
|
|
|
$added
|
2007-03-28 02:08:28 +02:00
|
|
|
EOF
|
|
|
|
|
2014-05-21 15:20:06 +02:00
|
|
|
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
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format body %b <<EOF
|
|
|
|
commit $head2
|
|
|
|
commit $head1
|
2007-03-28 02:08:28 +02:00
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:50 +02:00
|
|
|
test_format raw-body %B <<EOF
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2013-06-26 12:19:49 +02:00
|
|
|
$changed
|
2010-03-25 03:51:52 +01:00
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2013-06-26 12:19:49 +02:00
|
|
|
$added
|
2010-03-25 03:51:52 +01:00
|
|
|
|
|
|
|
EOF
|
|
|
|
|
rev-list: add option for --pretty=format without header
In general, we encourage users to use plumbing commands, like git
rev-list, over porcelain commands, like git log, when scripting.
However, git rev-list has one glaring problem that prevents it from
being used in certain cases: when --pretty is used with a custom format,
it always prints out a line containing "commit" and the object ID. This
makes it unsuitable for many scripting needs, and forces users to use
git log instead.
While we can't change this behavior for backwards compatibility, we can
add an option to suppress this behavior, so let's do so, and call it
"--no-commit-header". Additionally, add the corresponding positive
option to switch it back on.
Note that this option doesn't affect the built-in formats, only custom
formats. This is exactly the same behavior as users already have from
git log and is what most users will be used to.
Signed-off-by: brian m. carlson <sandals@crustytoothpaste.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2021-07-11 23:55:10 +02:00
|
|
|
test_format --no-commit-header raw-body-no-header %B <<EOF
|
|
|
|
$changed
|
|
|
|
|
|
|
|
$added
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_pretty oneline oneline <<EOF
|
|
|
|
$head2 $changed
|
|
|
|
$head1 $added
|
|
|
|
EOF
|
|
|
|
|
|
|
|
test_pretty short short <<EOF
|
|
|
|
commit $head2
|
|
|
|
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
|
|
|
|
|
|
|
|
$changed
|
|
|
|
|
|
|
|
commit $head1
|
|
|
|
Author: $GIT_AUTHOR_NAME <$GIT_AUTHOR_EMAIL>
|
|
|
|
|
|
|
|
$added
|
|
|
|
|
|
|
|
EOF
|
|
|
|
|
2017-07-13 16:58:41 +02:00
|
|
|
test_expect_success 'basic colors' '
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
commit $head2
|
|
|
|
<RED>foo<GREEN>bar<BLUE>baz<RESET>xyzzy
|
|
|
|
EOF
|
|
|
|
format="%Credfoo%Cgreenbar%Cbluebaz%Cresetxyzzy" &&
|
2020-11-19 00:44:36 +01:00
|
|
|
git rev-list --color --format="$format" -1 main >actual.raw &&
|
2017-07-13 16:58:41 +02:00
|
|
|
test_decode_color <actual.raw >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
2007-03-28 02:08:28 +02:00
|
|
|
|
2019-01-11 07:30:46 +01:00
|
|
|
test_expect_success '%S is not a placeholder for rev-list yet' '
|
2020-11-19 00:44:36 +01:00
|
|
|
git rev-list --format="%S" -1 main | grep "%S"
|
2019-01-11 07:30:46 +01:00
|
|
|
'
|
|
|
|
|
2017-07-13 16:58:41 +02:00
|
|
|
test_expect_success 'advanced colors' '
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
commit $head2
|
|
|
|
<BOLD;RED;BYELLOW>foo<RESET>
|
|
|
|
EOF
|
|
|
|
format="%C(red yellow bold)foo%C(reset)" &&
|
2020-11-19 00:44:36 +01:00
|
|
|
git rev-list --color --format="$format" -1 main >actual.raw &&
|
2017-07-13 16:58:41 +02:00
|
|
|
test_decode_color <actual.raw >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
expand --pretty=format color options
Currently, the only colors available to --pretty=format
users are red, green, and blue. Rather than expand it with a
few new colors, this patch makes the usual config color
syntax available, including more colors, backgrounds, and
attributes.
Because colors are no longer bounded to a single word (e.g.,
%Cred), this uses a more advanced syntax that features a
beginning and end delimiter (but the old syntax still
works). So you can now do:
git log --pretty=tformat:'%C(yellow)%h%C(reset) %s'
to emulate --pretty=oneline, or even
git log --pretty=tformat:'%C(cyan magenta bold)%s%C(reset)'
if you want to relive the awesomeness of 4-color CGA.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2009-01-17 16:38:46 +01:00
|
|
|
|
pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.
In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.
However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.
So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 17:08:46 +02:00
|
|
|
for spec in \
|
|
|
|
"%Cred:$BASIC_COLOR" \
|
|
|
|
"%C(...):$COLOR" \
|
|
|
|
"%C(auto,...):$AUTO_COLOR"
|
|
|
|
do
|
|
|
|
desc=${spec%%:*}
|
|
|
|
color=${spec#*:}
|
|
|
|
test_expect_success "$desc does not enable color by default" '
|
|
|
|
git log --format=$color -1 >actual &&
|
|
|
|
has_no_color actual
|
|
|
|
'
|
2012-12-17 23:56:49 +01:00
|
|
|
|
2017-10-13 19:23:41 +02:00
|
|
|
test_expect_success "$desc enables colors for color.diff" '
|
|
|
|
git -c color.diff=always log --format=$color -1 >actual &&
|
|
|
|
has_color actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$desc enables colors for color.ui" '
|
|
|
|
git -c color.ui=always log --format=$color -1 >actual &&
|
|
|
|
has_color actual
|
|
|
|
'
|
|
|
|
|
pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.
In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.
However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.
So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 17:08:46 +02:00
|
|
|
test_expect_success "$desc respects --color" '
|
|
|
|
git log --format=$color -1 --color >actual &&
|
|
|
|
has_color actual
|
|
|
|
'
|
2012-12-17 23:56:49 +01:00
|
|
|
|
2017-10-13 19:23:41 +02:00
|
|
|
test_expect_success "$desc respects --no-color" '
|
|
|
|
git -c color.ui=always log --format=$color -1 --no-color >actual &&
|
|
|
|
has_no_color actual
|
|
|
|
'
|
|
|
|
|
pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.
In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.
However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.
So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 17:08:46 +02:00
|
|
|
test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
|
2017-10-03 15:39:34 +02:00
|
|
|
test_terminal git log --format=$color -1 --color=auto >actual &&
|
pretty: respect color settings for %C placeholders
The color placeholders have traditionally been
unconditional, showing colors even when git is not otherwise
configured to do so. This was not so bad for their original
use, which was on the command-line (and the user could
decide at that moment whether to add colors or not). But
these days we have configured formats via pretty.*, and
those should operate correctly in multiple contexts.
In 3082517 (log --format: teach %C(auto,black) to respect
color config, 2012-12-17), we gave an extended placeholder
that could be used to accomplish this. But it's rather
clunky to use, because you have to specify it individually
for each color (and their matching resets) in the format.
We shied away from just switching the default to auto,
because it is technically breaking backwards compatibility.
However, there's not really a use case for unconditional
colors. The most plausible reason you would want them is to
redirect "git log" output to a file. But there, the right
answer is --color=always, as it does the right thing both
with custom user-format colors and git-generated colors.
So let's switch to the more useful default. In the
off-chance that somebody really does find a use for
unconditional colors without wanting to enable the rest of
git's colors, we provide a new %C(always,...) to enable the
old behavior. And we can remind them of --color=always in
the documentation.
Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2017-07-13 17:08:46 +02:00
|
|
|
has_color actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success "$desc respects --color=auto (stdout not tty)" '
|
|
|
|
(
|
|
|
|
TERM=vt100 && export TERM &&
|
|
|
|
git log --format=$color -1 --color=auto >actual &&
|
|
|
|
has_no_color actual
|
|
|
|
)
|
|
|
|
'
|
|
|
|
done
|
|
|
|
|
|
|
|
test_expect_success '%C(always,...) enables color even without tty' '
|
|
|
|
git log --format=$ALWAYS_COLOR -1 >actual &&
|
|
|
|
has_color actual
|
2012-12-17 23:56:49 +01:00
|
|
|
'
|
|
|
|
|
2016-05-27 05:46:10 +02:00
|
|
|
test_expect_success '%C(auto) respects --color' '
|
2017-07-13 16:58:41 +02:00
|
|
|
git log --color --format="%C(auto)%H" -1 >actual.raw &&
|
|
|
|
test_decode_color <actual.raw >actual &&
|
|
|
|
echo "<YELLOW>$(git rev-parse HEAD)<RESET>" >expect &&
|
2016-05-27 05:46:10 +02:00
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '%C(auto) respects --no-color' '
|
|
|
|
git log --no-color --format="%C(auto)%H" -1 >actual &&
|
|
|
|
git rev-parse HEAD >expect &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2017-07-13 17:07:30 +02:00
|
|
|
test_expect_success 'rev-list %C(auto,...) respects --color' '
|
|
|
|
git rev-list --color --format="%C(auto,green)foo%C(auto,reset)" \
|
|
|
|
-1 HEAD >actual.raw &&
|
|
|
|
test_decode_color <actual.raw >actual &&
|
|
|
|
cat >expect <<-EOF &&
|
|
|
|
commit $(git rev-parse HEAD)
|
|
|
|
<GREEN>foo<RESET>
|
|
|
|
EOF
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2014-05-21 15:20:04 +02:00
|
|
|
iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
|
2007-03-28 23:08:36 +02:00
|
|
|
Test printing of complex bodies
|
|
|
|
|
|
|
|
This commit message is much longer than the others,
|
2014-05-21 15:20:04 +02:00
|
|
|
and it will be encoded in $test_encoding. We should therefore
|
|
|
|
include an ISO8859 character: ¡bueno!
|
2007-03-28 23:08:36 +02:00
|
|
|
EOF
|
2013-06-26 12:19:46 +02:00
|
|
|
|
2007-03-28 23:08:36 +02:00
|
|
|
test_expect_success 'setup complex body' '
|
2014-05-21 15:20:04 +02:00
|
|
|
git config i18n.commitencoding $test_encoding &&
|
2013-06-26 12:19:46 +02:00
|
|
|
echo change2 >foo && git commit -a -F commit-msg &&
|
|
|
|
head3=$(git rev-parse --verify HEAD) &&
|
2013-07-05 14:01:49 +02:00
|
|
|
head3_short=$(git rev-parse --short $head3)
|
2007-03-28 23:08:36 +02:00
|
|
|
'
|
|
|
|
|
2013-06-26 12:19:46 +02:00
|
|
|
test_format complex-encoding %e <<EOF
|
|
|
|
commit $head3
|
2014-05-21 15:20:04 +02:00
|
|
|
$test_encoding
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2014-05-21 15:20:04 +02:00
|
|
|
$test_encoding
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2014-05-21 15:20:04 +02:00
|
|
|
$test_encoding
|
2007-03-28 23:08:36 +02:00
|
|
|
EOF
|
|
|
|
|
2013-06-26 12:19:50 +02:00
|
|
|
test_format complex-subject %s <<EOF
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head3
|
2007-03-28 23:08:36 +02:00
|
|
|
Test printing of complex bodies
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2013-07-05 14:01:49 +02:00
|
|
|
$changed_iso88591
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2013-07-05 14:01:49 +02:00
|
|
|
$added_iso88591
|
2007-03-28 23:08:36 +02:00
|
|
|
EOF
|
|
|
|
|
2014-05-21 15:20:07 +02:00
|
|
|
test_format complex-subject-trunc "%<($truncate_count,trunc)%s" <<EOF
|
2014-05-21 15:20:06 +02:00
|
|
|
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
|
|
|
|
|
2014-05-21 15:20:07 +02:00
|
|
|
test_format complex-subject-mtrunc "%<($truncate_count,mtrunc)%s" <<EOF
|
2014-05-21 15:20:06 +02:00
|
|
|
commit $head3
|
|
|
|
Test prin..ex bodies
|
|
|
|
commit $head2
|
|
|
|
changed (..dert) foo
|
|
|
|
commit $head1
|
|
|
|
added (hi..f${added_utf8_part_iso88591}gt) foo
|
|
|
|
EOF
|
|
|
|
|
2014-05-21 15:20:07 +02:00
|
|
|
test_format complex-subject-ltrunc "%<($truncate_count,ltrunc)%s" <<EOF
|
2014-05-21 15:20:06 +02:00
|
|
|
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
|
|
|
|
|
2020-10-18 02:23:46 +02:00
|
|
|
test_expect_success 'setup expected messages (for test %b)' '
|
2013-07-05 14:01:49 +02:00
|
|
|
cat <<-EOF >expected.utf-8 &&
|
|
|
|
commit $head3
|
|
|
|
This commit message is much longer than the others,
|
2014-05-21 15:20:04 +02:00
|
|
|
and it will be encoded in $test_encoding. We should therefore
|
|
|
|
include an ISO8859 character: ¡bueno!
|
2013-07-05 14:01:49 +02:00
|
|
|
|
|
|
|
commit $head2
|
|
|
|
commit $head1
|
|
|
|
EOF
|
2014-05-21 15:20:04 +02:00
|
|
|
iconv -f utf-8 -t $test_encoding expected.utf-8 >expected.ISO8859-1
|
2013-07-05 14:01:49 +02:00
|
|
|
'
|
|
|
|
|
2014-05-21 15:20:04 +02:00
|
|
|
test_format complex-body %b <expected.ISO8859-1
|
2007-03-28 23:08:36 +02:00
|
|
|
|
2013-07-05 14:01:49 +02:00
|
|
|
# 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
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head2
|
2013-07-05 14:01:49 +02:00
|
|
|
$changed
|
2013-06-26 12:19:46 +02:00
|
|
|
commit $head1
|
2013-07-05 14:01:49 +02:00
|
|
|
$added
|
2007-03-28 23:08:36 +02:00
|
|
|
EOF
|
|
|
|
|
2014-05-21 15:20:06 +02:00
|
|
|
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
|
|
|
|
|
2013-07-05 14:01:49 +02:00
|
|
|
test_format complex-body-commitencoding-unset %b <expected.utf-8
|
|
|
|
|
2010-10-07 20:25:43 +02:00
|
|
|
test_expect_success '%x00 shows NUL' '
|
2013-06-26 12:19:46 +02:00
|
|
|
echo >expect commit $head3 &&
|
2010-10-07 20:25:43 +02:00
|
|
|
echo >>expect fooQbar &&
|
|
|
|
git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
|
|
|
|
nul_to_q <actual.nul >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2008-08-29 02:54:59 +02:00
|
|
|
test_expect_success '%ad respects --date=' '
|
|
|
|
echo 2005-04-07 >expect.ad-short &&
|
2020-11-19 00:44:36 +01:00
|
|
|
git log -1 --date=short --pretty=tformat:%ad >output.ad-short main &&
|
2008-08-29 02:54:59 +02:00
|
|
|
test_cmp expect.ad-short output.ad-short
|
|
|
|
'
|
|
|
|
|
2008-01-06 13:21:07 +01:00
|
|
|
test_expect_success 'empty email' '
|
|
|
|
test_tick &&
|
|
|
|
C=$(GIT_AUTHOR_EMAIL= git commit-tree HEAD^{tree} </dev/null) &&
|
|
|
|
A=$(git show --pretty=format:%an,%ae,%ad%n -s $C) &&
|
2019-10-25 01:36:15 +02:00
|
|
|
verbose test "$A" = "$GIT_AUTHOR_NAME,,Thu Apr 7 15:14:13 2005 -0700"
|
2008-01-06 13:21:07 +01:00
|
|
|
'
|
|
|
|
|
2009-10-05 08:43:32 +02:00
|
|
|
test_expect_success 'del LF before empty (1)' '
|
|
|
|
git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD^^ >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 2 actual
|
2009-10-05 08:43:32 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'del LF before empty (2)' '
|
|
|
|
git show -s --pretty=format:"%s%n%-b%nThanks%n" HEAD >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 6 actual &&
|
2009-10-05 08:43:32 +02:00
|
|
|
grep "^$" actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add LF before non-empty (1)' '
|
|
|
|
git show -s --pretty=format:"%s%+b%nThanks%n" HEAD^^ >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 2 actual
|
2009-10-05 08:43:32 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add LF before non-empty (2)' '
|
|
|
|
git show -s --pretty=format:"%s%+b%nThanks%n" HEAD >actual &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 6 actual &&
|
2009-10-05 08:43:32 +02:00
|
|
|
grep "^$" actual
|
|
|
|
'
|
|
|
|
|
2010-06-14 18:12:29 +02:00
|
|
|
test_expect_success 'add SP before non-empty (1)' '
|
|
|
|
git show -s --pretty=format:"%s% bThanks" HEAD^^ >actual &&
|
2013-06-26 12:19:49 +02:00
|
|
|
test $(wc -w <actual) = 3
|
2010-06-14 18:12:29 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success 'add SP before non-empty (2)' '
|
|
|
|
git show -s --pretty=format:"%s% sThanks" HEAD^^ >actual &&
|
2013-06-26 12:19:49 +02:00
|
|
|
test $(wc -w <actual) = 6
|
2010-06-14 18:12:29 +02:00
|
|
|
'
|
|
|
|
|
2010-05-04 05:18:57 +02:00
|
|
|
test_expect_success '--abbrev' '
|
|
|
|
echo SHORT SHORT SHORT >expect2 &&
|
|
|
|
echo LONG LONG LONG >expect3 &&
|
|
|
|
git log -1 --format="%h %h %h" HEAD >actual1 &&
|
|
|
|
git log -1 --abbrev=5 --format="%h %h %h" HEAD >actual2 &&
|
|
|
|
git log -1 --abbrev=5 --format="%H %H %H" HEAD >actual3 &&
|
2018-05-13 04:24:15 +02:00
|
|
|
sed -e "s/$OID_REGEX/LONG/g" -e "s/$_x05/SHORT/g" <actual2 >fuzzy2 &&
|
|
|
|
sed -e "s/$OID_REGEX/LONG/g" -e "s/$_x05/SHORT/g" <actual3 >fuzzy3 &&
|
2010-05-04 05:18:57 +02:00
|
|
|
test_cmp expect2 fuzzy2 &&
|
|
|
|
test_cmp expect3 fuzzy3 &&
|
|
|
|
! test_cmp actual1 actual2
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '%H is not affected by --abbrev-commit' '
|
2020-02-07 01:52:53 +01:00
|
|
|
expected=$(($(test_oid hexsz) + 1)) &&
|
2010-05-04 05:18:57 +02:00
|
|
|
git log -1 --format=%H --abbrev-commit --abbrev=20 HEAD >actual &&
|
|
|
|
len=$(wc -c <actual) &&
|
2020-02-07 01:52:53 +01:00
|
|
|
test $len = $expected
|
2010-05-04 05:18:57 +02:00
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '%h is not affected by --abbrev-commit' '
|
|
|
|
git log -1 --format=%h --abbrev-commit --abbrev=20 HEAD >actual &&
|
|
|
|
len=$(wc -c <actual) &&
|
|
|
|
test $len = 21
|
|
|
|
'
|
|
|
|
|
2009-10-19 17:48:10 +02:00
|
|
|
test_expect_success '"%h %gD: %gs" is same as git-reflog' '
|
|
|
|
git reflog >expect &&
|
|
|
|
git log -g --format="%h %gD: %gs" >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
|
|
|
test_expect_success '"%h %gD: %gs" is same as git-reflog (with date)' '
|
|
|
|
git reflog --date=raw >expect &&
|
|
|
|
git log -g --format="%h %gD: %gs" --date=raw >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-05-04 05:18:57 +02:00
|
|
|
test_expect_success '"%h %gD: %gs" is same as git-reflog (with --abbrev)' '
|
|
|
|
git reflog --abbrev=13 --date=raw >expect &&
|
|
|
|
git log -g --abbrev=13 --format="%h %gD: %gs" --date=raw >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2009-10-19 17:48:10 +02:00
|
|
|
test_expect_success '%gd shortens ref name' '
|
2020-11-19 00:44:36 +01:00
|
|
|
echo "main@{0}" >expect.gd-short &&
|
|
|
|
git log -g -1 --format=%gd refs/heads/main >actual.gd-short &&
|
2009-10-19 17:48:10 +02:00
|
|
|
test_cmp expect.gd-short actual.gd-short
|
|
|
|
'
|
|
|
|
|
2011-12-16 12:40:24 +01:00
|
|
|
test_expect_success 'reflog identity' '
|
2019-10-25 01:36:15 +02:00
|
|
|
echo "$GIT_COMMITTER_NAME:$GIT_COMMITTER_EMAIL" >expect &&
|
2011-12-16 12:40:24 +01:00
|
|
|
git log -g -1 --format="%gn:%ge" >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2010-03-21 15:40:16 +01:00
|
|
|
test_expect_success 'oneline with empty message' '
|
t6006: simplify, fix, and optimize empty message test
Test t6006.71 ("oneline with empty message") was creating two commits
with simple commit messages, and then running filter-branch to rewrite
the commit messages to be "empty". This test was introduced in commit
1fb5fdd25f0 ("rev-list: fix --pretty=oneline with empty message",
2010-03-21) and written this way because the --allow-empty-message
option to git commit did not exist at the time.
However, the filter-branch invocation used differed slightly from
--allow-empty-message in that it would have a commit message consisting
solely of a single newline, and as such was not testing what the
original commit intended to test. Since both a truly empty commit
message and a commit message with a single linefeed could trigger the
original bug, modify the test slightly to include an example of each.
Despite only being one piece of the 71st test and there being 73 tests
overall, this small change to just this one test speeds up the overall
execution time of t6006 (as measured by the best of 3 runs of `time
./t6006-rev-list-format.sh`) by about 11% on Linux, 13% on Mac, and
about 15% on Windows.
Signed-off-by: Elijah Newren <newren@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
2019-09-05 00:32:37 +02:00
|
|
|
git commit --allow-empty --cleanup=verbatim -m "$LF" &&
|
|
|
|
git commit --allow-empty --allow-empty-message &&
|
2010-04-17 04:29:18 +02:00
|
|
|
git rev-list --oneline HEAD >test.txt &&
|
2012-04-11 13:24:01 +02:00
|
|
|
test_line_count = 5 test.txt &&
|
|
|
|
git rev-list --oneline --graph HEAD >testg.txt &&
|
|
|
|
test_line_count = 5 testg.txt
|
2010-03-21 15:40:16 +01:00
|
|
|
'
|
|
|
|
|
2012-05-22 08:12:20 +02:00
|
|
|
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
|
|
|
|
'
|
|
|
|
|
2014-06-25 23:42:17 +02:00
|
|
|
test_expect_success 'unused %G placeholders are passed through' '
|
|
|
|
echo "%GX %G" >expect &&
|
|
|
|
git log -1 --format="%GX %G" >actual &&
|
|
|
|
test_cmp expect actual
|
|
|
|
'
|
|
|
|
|
2007-03-28 02:08:28 +02:00
|
|
|
test_done
|