With `git config get --type=color` the user asks us to parse a specific configuration key and turn the value into an ANSI color escape sequence. The printed string can then for example be used as part of shell scripts to reuse the same colors as Git. Right now though we set up the auto-pager though, which means that the string may instead be written to the pager command. This is of course quite nonsensical: there shouldn't be any use case where the color code should end up in the pager instead of in the TTY. Fix this by disabling the pager in case the user is asking us to print color sequences. Signed-off-by: Patrick Steinhardt <ps@xxxxxx> --- builtin/config.c | 3 ++- t/t1300-config.sh | 9 +++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/builtin/config.c b/builtin/config.c index f50c11df57..6708d91814 100644 --- a/builtin/config.c +++ b/builtin/config.c @@ -919,7 +919,8 @@ static int cmd_config_get(int argc, const char **argv, const char *prefix, location_options_init(&location_opts, prefix); display_options_init(&display_opts); - setup_auto_pager("config", 1); + if (display_opts.type != TYPE_COLOR) + setup_auto_pager("config", 1); if (url) ret = get_urlmatch(&location_opts, &display_opts, argv[0], url); diff --git a/t/t1300-config.sh b/t/t1300-config.sh index 40f170cf40..26111c175c 100755 --- a/t/t1300-config.sh +++ b/t/t1300-config.sh @@ -9,6 +9,7 @@ GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME . ./test-lib.sh +. "$TEST_DIRECTORY"/lib-terminal.sh for mode in legacy subcommands do @@ -1100,6 +1101,14 @@ test_expect_success 'get --type=color with default value only' ' test_cmp actual.raw actual-subcommand.raw ' +test_expect_success TTY 'get --type=color does not use a pager' ' + test_config core.pager "echo foobar" && + test_terminal git config get --type=color --default="red" "" >actual.raw && + test_decode_color <actual.raw >actual && + echo "<RED>" >expect && + test_cmp expect actual +' + test_expect_success 'set --type=color' ' cat >expect <<EOF && [foo] -- 2.51.0.450.g87641ccf93.dirty