git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 5/5] builtin/config: do not spawn pager when printing color codes

From
Patrick Steinhardt <ps@pks.im>
Date
Sep 18, 2025, 06:14 UTC
Message-ID
<20250918-pks-config-color-v3-5-08ea618cae26@pks.im>
In-Reply-To
<20250918-pks-config-color-v3-0-08ea618cae26@pks.im>

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>
---
 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 3cf5d17aba..358d636379 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
@@ -1099,6 +1100,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.534.gc79095c0ca.dirty
Previous: Junio C HamanoNext: Patrick Steinhardt
Message 30 of 36 in “builtin/config: bug fixes for "get" subcommand with "--type=color"”
  1. 0/5 builtin/config: bug fixes for "get" subcommand with "--type=color"Patrick Steinhardt, Sep 11, 2025
  2. 1/5 t1300: write test expectations in the test's bodyPatrick Steinhardt, Sep 11, 2025
  3. Kristoffer HaugsbakkSep 11, 2025
  4. Patrick SteinhardtSep 15, 2025
  5. 2/5 t1300: small style fixupsPatrick Steinhardt, Sep 11, 2025
  6. 3/5 builtin/config: do not die in `get_color()`Patrick Steinhardt, Sep 11, 2025
  7. 4/5 builtin/config: special-case retrieving colors without a keyPatrick Steinhardt, Sep 11, 2025
  8. Kristoffer HaugsbakkSep 11, 2025
  9. Patrick SteinhardtSep 15, 2025
  10. 5/5 builtin/config: do not spawn pager when printing color codesPatrick Steinhardt, Sep 11, 2025
  11. Kristoffer HaugsbakkSep 11, 2025
  12. 0/5 builtin/config: bug fixes for "get" subcommand with "--type=color"Patrick Steinhardt, Sep 15, 2025
  13. 1/5 t1300: write test expectations in the test's bodyPatrick Steinhardt, Sep 15, 2025
  14. 2/5 t1300: small style fixupsPatrick Steinhardt, Sep 15, 2025
  15. 3/5 builtin/config: do not die in `get_color()`Patrick Steinhardt, Sep 15, 2025
  16. 4/5 builtin/config: special-case retrieving colors without a keyPatrick Steinhardt, Sep 15, 2025
  17. Junio C HamanoSep 15, 2025
  18. 5/5 builtin/config: do not spawn pager when printing color codesPatrick Steinhardt, Sep 15, 2025
  19. Junio C HamanoSep 15, 2025
  20. Kristoffer HaugsbakkSep 16, 2025
  21. Patrick SteinhardtSep 18, 2025
  22. 0/5 builtin/config: bug fixes for "get" subcommand with "--type=color"Patrick Steinhardt, Sep 18, 2025
  23. 1/5 t1300: write test expectations in the test's bodyPatrick Steinhardt, Sep 18, 2025
  24. 2/5 t1300: small style fixupsPatrick Steinhardt, Sep 18, 2025
  25. 3/5 builtin/config: do not die in `get_color()`Patrick Steinhardt, Sep 18, 2025
  26. 4/5 builtin/config: special-case retrieving colors without a keyPatrick Steinhardt, Sep 18, 2025
  27. Junio C HamanoSep 18, 2025
  28. Patrick SteinhardtSep 22, 2025
  29. Junio C HamanoSep 22, 2025
  30. 5/5 builtin/config: do not spawn pager when printing color codesPatrick Steinhardt, Sep 18, 2025
  31. 0/5 builtin/config: bug fixes for "get" subcommand with "--type=color"Patrick Steinhardt, Sep 22, 2025
  32. 1/5 t1300: write test expectations in the test's bodyPatrick Steinhardt, Sep 22, 2025
  33. 2/5 t1300: small style fixupsPatrick Steinhardt, Sep 22, 2025
  34. 3/5 builtin/config: do not die in `get_color()`Patrick Steinhardt, Sep 22, 2025
  35. 4/5 builtin/config: special-case retrieving colors without a keyPatrick Steinhardt, Sep 22, 2025
  36. 5/5 builtin/config: do not spawn pager when printing color codesPatrick Steinhardt, Sep 22, 2025

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.