Git fork

builtin/config: do not spawn pager when printing color codes

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, which means that the string
may be written to the pager instead of directly to the terminal. This
behaviour is problematic for two reasons:

- Color codes are meant for direct terminal output; writing them into
a pager does not seem like a sensible thing to do without additional
text.

- It is inconsistent with `git config --get-color`, which never uses a
pager, despite the fact that we claim `git config get --type=color`
to be a drop-in replacement in git-config(1).

Fix this by disabling the pager when outputting color sequences.

Signed-off-by: Patrick Steinhardt <ps@pks.im>
Signed-off-by: Junio C Hamano <gitster@pobox.com>

authored by

Patrick Steinhardt and committed by
Junio C Hamano
e4dabf4f 54b24b10

+11 -1
+2 -1
builtin/config.c
··· 919 919 location_options_init(&location_opts, prefix); 920 920 display_options_init(&display_opts); 921 921 922 - setup_auto_pager("config", 1); 922 + if (display_opts.type != TYPE_COLOR) 923 + setup_auto_pager("config", 1); 923 924 924 925 if (url) 925 926 ret = get_urlmatch(&location_opts, &display_opts, argv[0], url);
+9
t/t1300-config.sh
··· 9 9 export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME 10 10 11 11 . ./test-lib.sh 12 + . "$TEST_DIRECTORY"/lib-terminal.sh 12 13 13 14 for mode in legacy subcommands 14 15 do ··· 1097 1098 test_cmp expect actual && 1098 1099 git config get --type=color --default="red" "" >actual-subcommand.raw && 1099 1100 test_cmp actual.raw actual-subcommand.raw 1101 + ' 1102 + 1103 + test_expect_success TTY 'get --type=color does not use a pager' ' 1104 + test_config core.pager "echo foobar" && 1105 + test_terminal git config get --type=color --default="red" "" >actual.raw && 1106 + test_decode_color <actual.raw >actual && 1107 + echo "<RED>" >expect && 1108 + test_cmp expect actual 1100 1109 ' 1101 1110 1102 1111 test_expect_success 'set --type=color' '