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

Re: [PATCH v3 4/5] builtin/config: special-case retrieving colors without a key

From
Junio C Hamano <gitster@pobox.com>
Date
Sep 18, 2025, 06:49 UTC
Message-ID
<xmqqikhg9rwx.fsf@gitster.g>
In-Reply-To
<20250918-pks-config-color-v3-4-08ea618cae26@pks.im>
Patrick Steinhardt <ps@pks.im> writes:
Show 32 quoted lines
> Our documentation for git-config(1) has a section where it explains how
> to parse and use colors as Git would configure them. In order to get the
> ANSI color escape sequence to reset the colors to normal we recommend
> the following command:
>
>     $ git config get --type=color --default="reset" ""
>
> This command is not supposed to parse any configuration keys. Instead,
> it is expected to parse the "reset" default value and turn it into a
> proper ANSI color escape sequence.
>
> It was reported though [1] that this command doesn't work:
>
>     $ git config get --type=color --default="reset" ""
>     error: key does not contain a section:
>
> This error was introduced in 4e51389000 (builtin/config: introduce "get"
> subcommand, 2024-05-06), where we introduced the "get" subcommand to
> retrieve configuration values. The preimage of that commit used `git
> config --get-color "" "reset"` instead, which still works.
>
> This use case is really quite specific to parsing colors, as it wouldn't
> make sense to give git-config(1) a default value and an empty config key
> only to return that default value unmodified. But with `--type=color` we
> don't return the value directly; we instead parse the value into an ANSI
> escape sequence.
>
> As such, we can easily special-case this one use case:
>
>     - If the provided config key is empty;
>
>     - the user is asking for a color code and the user; and
"and the user;" -> ";" perhaps?
Show 5 quoted lines
>
>     - the user has provided a default value,
>
> then we call `get_color()` directly. Do so to make the documented
> command work as expected.

If we are willing to handle this as a special case anyway, I wonder if it can easily be arranged to take this as a(nother) special case.

    $ git config get --type=color --default="reset"

I.e., instead of (or in addition to) "if the config key is empty", special case "if the config key is not given", which may be slightly more intuitive.

But even without it, what is presented is a vast improvement enough ;-)

Previous: Patrick SteinhardtNext: Patrick Steinhardt
Message 27 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.