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

Re: [PATCH 1/2] color: downgrade "always" to "auto" only for on-disk configuration

From
Jonathan Nieder <jrnieder@gmail.com>
Date
Oct 12, 2017, 04:47 UTC
Message-ID
<20171012044724.GD155740@aiede.mtv.corp.google.com>
In-Reply-To
<20171012021007.7441-2-gitster@pobox.com>
Junio C Hamano wrote:
[...]
Show 23 quoted lines
> --- a/color.c
> +++ b/color.c
> @@ -307,8 +307,21 @@ int git_config_colorbool(const char *var, const char *value)
>  	if (value) {
>  		if (!strcasecmp(value, "never"))
>  			return 0;
> -		if (!strcasecmp(value, "always"))
> -			return var ? GIT_COLOR_AUTO : 1;
> +		if (!strcasecmp(value, "always")) {
> +			/*
> +			 * Command-line options always respect "always".
> +			 * Likewise for "-c" config on the command-line.
> +			 */
> +			if (!var ||
> +			    current_config_scope() == CONFIG_SCOPE_CMDLINE)
> +				return 1;
> +
> +			/*
> +			 * Otherwise, we're looking at on-disk config;
> +			 * downgrade to auto.
> +			 */
> +			return GIT_COLOR_AUTO;
> +		}
Yes, this looks good to me.

Should we document this special case treatment of color.* in -c somewhere? E.g.

Signed-off-by: Jonathan Nieder <jrnieder@gmail.com>
diff --git i/Documentation/config.txt w/Documentation/config.txt
index 13ce76d48b..d7bd6b169c 100644
--- i/Documentation/config.txt
+++ w/Documentation/config.txt
@@ -1067,11 +1067,15 @@ clean.requireForce::
 	-i or -n.   Defaults to true.
 
 color.branch::
-	A boolean to enable/disable color in the output of
-	linkgit:git-branch[1]. May be set to `false` (or `never`) to
-	disable color entirely, `auto` (or `true` or `always`) in which
-	case colors are used only when the output is to a terminal.  If
-	unset, then the value of `color.ui` is used (`auto` by default).
+	When to use color in the output of linkgit:git-branch[1].
+	May be set to `never` (or `false`) to disable color entirely,
+	or `auto` (or `true`) in which case colors are used only when
+	the output is to a terminal.  If unset, then the value of
+	`color.ui` is used (`auto` by default).
++
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it is a historical synonym
+for `--color=always`.
 
 color.branch.<slot>::
 	Use customized color for branch coloration. `<slot>` is one of
@@ -1084,10 +1088,13 @@ color.diff::
 	Whether to use ANSI escape sequences to add color to patches.
 	If this is set to `true` or `auto`, linkgit:git-diff[1],
 	linkgit:git-log[1], and linkgit:git-show[1] will use color
-	when output is to the terminal. The value `always` is a
-	historical synonym for `auto`.  If unset, then the value of
+	when output is to the terminal. If unset, then the value of
 	`color.ui` is used (`auto` by default).
 +
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it is a historical
+synonym for `--color=always`.
++
 This does not affect linkgit:git-format-patch[1] or the
 'git-diff-{asterisk}' plumbing commands.  Can be overridden on the
 command line with the `--color[=<when>]` option.
@@ -1118,10 +1125,14 @@ color.decorate.<slot>::
 	branches, remote-tracking branches, tags, stash and HEAD, respectively.
 
 color.grep::
-	When set to `always`, always highlight matches.  When `false` (or
+	When to highlight matches using color. When `false` (or
 	`never`), never.  When set to `true` or `auto`, use color only
 	when the output is written to the terminal.  If unset, then the
 	value of `color.ui` is used (`auto` by default).
++
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it is a historical synonym
+for `--color=always`.
 
 color.grep.<slot>::
 	Use customized color for grep colorization.  `<slot>` specifies which
@@ -1153,9 +1164,11 @@ color.interactive::
 	When set to `true` or `auto`, use colors for interactive prompts
 	and displays (such as those used by "git-add --interactive" and
 	"git-clean --interactive") when the output is to the terminal.
-	When false (or `never`), never show colors. The value `always`
-	is a historical synonym for `auto`.  If unset, then the value of
-	`color.ui` is used (`auto` by default).
+	When false (or `never`), never show colors.
++
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it means to use color
+regardless of whether output is to the terminal.
 
 color.interactive.<slot>::
 	Use customized color for 'git add --interactive' and 'git clean
@@ -1168,18 +1181,24 @@ color.pager::
 	use (default is true).
 
 color.showBranch::
-	A boolean to enable/disable color in the output of
-	linkgit:git-show-branch[1]. May be set to `always`,
-	`false` (or `never`) or `auto` (or `true`), in which case colors are used
-	only when the output is to a terminal. If unset, then the
-	value of `color.ui` is used (`auto` by default).
+	When to use color in the output of linkgit:git-show-branch[1].
+	May be set to `never` (or `false`) to disable color or `auto`
+	(or `true`) to use colors only when the output is to a terminal.
+	If unset, the value of `color.ui` is used (`auto` by default).
++
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it is a historical synonym
+for `--color=always`.
 
 color.status::
-	A boolean to enable/disable color in the output of
-	linkgit:git-status[1]. May be set to `always`,
-	`false` (or `never`) or `auto` (or `true`), in which case colors are used
-	only when the output is to a terminal. If unset, then the
-	value of `color.ui` is used (`auto` by default).
+	When to use color in the output of linkgit:git-status[1].
+	May be set to `never` (or `false`) to disable color or `auto`
+	(or `true`) to use colors only when the output is to the terminal.
+	If unset, then the value of `color.ui` is used (`auto` by default).
++
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it means to use color
+regardless of whether output is to the terminal.
 
 color.status.<slot>::
 	Use customized color for status colorization. `<slot>` is
@@ -1204,8 +1223,11 @@ color.ui::
 	color unless enabled explicitly with some other configuration
 	or the `--color` option. Set it to `true` or `auto` to enable
 	color when output is written to the terminal (this is also the
-	default since Git 1.8.4). The value `always` is a historical
-	synonym for `auto`.
+	default since Git 1.8.4).
++
+The value `always` is a historical synonym for `auto`, except when
+passed on the command line using `-c`, where it means to use color
+regardless of whether output is to the terminal.
 
 column.ui::
 	Specify whether supported commands should output in columns.
Previous: Junio C HamanoNext: Junio C Hamano
Message 18 of 42 in “What happened to "git status --color=(always|auto|never)"?”
  1. Nazri RamliyOct 9, 2017
  2. Jonathan NiederOct 10, 2017
  3. Nazri RamliyOct 10, 2017
  4. Jonathan NiederOct 10, 2017
  5. Nazri RamliyOct 10, 2017
  6. Jeff KingOct 10, 2017
  7. Junio C HamanoOct 10, 2017
  8. Jeff KingOct 10, 2017
  9. Jonathan NiederOct 10, 2017
  10. Jeff KingOct 10, 2017
  11. Junio C HamanoOct 11, 2017
  12. 0/2 Piling more kludge on top of color.uiJunio C Hamano, Oct 12, 2017
  13. 2/2 color: discourage use of ui.color=alwaysJunio C Hamano, Oct 12, 2017
  14. Jonathan NiederOct 12, 2017
  15. Jeff KingOct 12, 2017
  16. Junio C HamanoOct 13, 2017
  17. 1/2 color: downgrade "always" to "auto" only for on-disk configurationJunio C Hamano, Oct 12, 2017
  18. Jonathan NiederOct 12, 2017
  19. Junio C HamanoOct 12, 2017
  20. Jonathan NiederOct 12, 2017
  21. Junio C HamanoOct 12, 2017
  22. Junio C HamanoOct 12, 2017
  23. Jeff KingOct 12, 2017
  24. Jeff KingOct 12, 2017
  25. Jeff KingOct 12, 2017
  26. Junio C HamanoOct 13, 2017
  27. Jeff KingOct 13, 2017
  28. Junio C HamanoOct 13, 2017
  29. Jeff KingOct 13, 2017
  30. 0/4 peeling back color.ui=always hacksJeff King, Oct 13, 2017
  31. 1/4 Revert "color: make "always" the same as "auto" in config"Jeff King, Oct 13, 2017
  32. 2/4 Revert "t6006: drop "always" color config tests"Jeff King, Oct 13, 2017
  33. 3/4 Revert "color: check color.ui in git_default_config()"Jeff King, Oct 13, 2017
  34. 4/4 tag: respect color.ui configJeff King, Oct 13, 2017
  35. Junio C HamanoOct 14, 2017
  36. Jeff KingOct 16, 2017
  37. Junio C HamanoOct 17, 2017
  38. Junio C HamanoOct 17, 2017
  39. Jeff KingOct 18, 2017
  40. Junio C HamanoOct 18, 2017
  41. Jonathan NiederOct 17, 2017
  42. Jeff KingOct 18, 2017

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.