summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2017-10-10 06:25:10 -0400
committerJunio C Hamano <gitster@pobox.com>2017-10-12 21:48:46 +0900
commit20120618c1c44611d8506a552ff2327670f5183a (patch)
treec099eece3e8dbb6b96e3a05e78f79995ece6ca06
parent6be4595edb8e5b616c6e8b9fbc78b0f831fa2a87 (diff)
downloadgit-20120618c1c44611d8506a552ff2327670f5183a.tar.gz
color: downgrade "always" to "auto" only for on-disk configuration
An earlier patch downgraded "always" that comes via the ui.color configuration variable to "auto", in order to work around an unfortunate regression to "git add -i". That "fix" however regressed other third-party tools that depend on "git -c color.ui=always cmd" as the way to defeat any end-user configuration and force coloured output from git subcommand, even when the output does not go to a terminal. It is a bit ugly to treat "-c color.ui=always" from the command line differently from a definition that comes from on-disk configuration files, but it is a moral equivalent of "--color=always" option given to the subcommand from the command line, i.e. a signal that tells us that the script writer knows what s/he is doing. So let's take that route to unbreak this case while defeating a (now declared to be) misguided color.ui that is set to always in the configuration file. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
-rw-r--r--color.c17
-rwxr-xr-xt/t6006-rev-list-format.sh11
2 files changed, 26 insertions, 2 deletions
diff --git a/color.c b/color.c
index 17e2713f96..5b06c76bdc 100644
--- 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;
+ }
if (!strcasecmp(value, "auto"))
return GIT_COLOR_AUTO;
}
diff --git a/t/t6006-rev-list-format.sh b/t/t6006-rev-list-format.sh
index 25a9c65dc5..582cab5c8a 100755
--- a/t/t6006-rev-list-format.sh
+++ b/t/t6006-rev-list-format.sh
@@ -261,6 +261,17 @@ test_expect_success 'rev-list %C(auto,...) respects --color' '
test_cmp expect actual
'
+test_expect_success "color.ui=always in config file same as auto" '
+ test_config color.ui always &&
+ git log --format=$COLOR -1 >actual &&
+ has_no_color actual
+'
+
+test_expect_success "color.ui=always on command-line is always" '
+ git -c color.ui=always log --format=$COLOR -1 >actual &&
+ has_color actual
+'
+
iconv -f utf-8 -t $test_encoding > commit-msg <<EOF
Test printing of complex bodies