color: special case 'always' in 'ui.color' stable
authorPierre-Yves David <pierre-yves.david@ens-lyon.org>
Tue, 02 May 2017 20:19:09 +0200
branchstable
changeset 32103 9a98023ac8db
parent 32102 9a85ea1daf49
child 32104 f06d23af6cdf
color: special case 'always' in 'ui.color' This lift the confusing case, where 'ui.color=always' would actually not always use color.
mercurial/color.py
mercurial/help/config.txt
tests/test-diff-color.t
tests/test-pager-legacy.t
tests/test-pager.t
tests/test-status-color.t
--- a/mercurial/color.py	Tue May 02 20:01:54 2017 +0200
+++ b/mercurial/color.py	Tue May 02 20:19:09 2017 +0200
@@ -195,8 +195,9 @@
     auto = (config == 'auto')
     always = False
     if not auto and util.parsebool(config):
-        # we want the config to behave like a boolean, "on" is actually auto
-        if ui.configsource('ui', 'color') == '--color':
+        # We want the config to behave like a boolean, "on" is actually auto,
+        # but "always" value is treated as a special case to reduce confusion.
+        if ui.configsource('ui', 'color') == '--color' or config == 'always':
             always = True
         else:
             auto = True
--- a/mercurial/help/config.txt	Tue May 02 20:01:54 2017 +0200
+++ b/mercurial/help/config.txt	Tue May 02 20:19:09 2017 +0200
@@ -1885,8 +1885,8 @@
 
 ``color``
     When to colorize output. Possible value are Boolean ("yes" or "no"), or
-    "debug". (default: "yes"). "yes" will use color whenever it seems possible.
-    See :hg:`help color` for details.
+    "debug", or "always". (default: "yes"). "yes" will use color whenever it
+    seems possible. See :hg:`help color` for details.
 
 ``commitsubrepos``
     Whether to commit modified subrepositories when committing the
--- a/tests/test-diff-color.t	Tue May 02 20:01:54 2017 +0200
+++ b/tests/test-diff-color.t	Tue May 02 20:19:09 2017 +0200
@@ -2,7 +2,7 @@
 
   $ cat <<EOF >> $HGRCPATH
   > [ui]
-  > color = always
+  > color = yes
   > formatted = always
   > [color]
   > mode = ansi
@@ -82,6 +82,22 @@
    a
    c
 
+(check that 'ui.color=always' force color)
+
+  $ hg diff --nodates --config ui.formatted=no --config ui.color=always
+  \x1b[0;1mdiff -r cf9f4ba66af2 a\x1b[0m (esc)
+  \x1b[0;31;1m--- a/a\x1b[0m (esc)
+  \x1b[0;32;1m+++ b/a\x1b[0m (esc)
+  \x1b[0;35m@@ -2,7 +2,7 @@\x1b[0m (esc)
+   c
+   a
+   a
+  \x1b[0;31m-b\x1b[0m (esc)
+  \x1b[0;32m+dd\x1b[0m (esc)
+   a
+   a
+   c
+
 --unified=2
 
   $ hg diff --nodates -U 2
--- a/tests/test-pager-legacy.t	Tue May 02 20:01:54 2017 +0200
+++ b/tests/test-pager-legacy.t	Tue May 02 20:19:09 2017 +0200
@@ -160,8 +160,7 @@
 even though stdout is no longer a tty.
   $ cat >> $HGRCPATH <<EOF
   > [ui]
-  > color = yes
-  > formatted = yes
+  > color = always
   > [color]
   > mode = ansi
   > EOF
--- a/tests/test-pager.t	Tue May 02 20:01:54 2017 +0200
+++ b/tests/test-pager.t	Tue May 02 20:19:09 2017 +0200
@@ -141,8 +141,7 @@
 even though stdout is no longer a tty.
   $ cat >> $HGRCPATH <<EOF
   > [ui]
-  > color = yes
-  > formatted = yes
+  > color = always
   > [color]
   > mode = ansi
   > EOF
--- a/tests/test-status-color.t	Tue May 02 20:01:54 2017 +0200
+++ b/tests/test-status-color.t	Tue May 02 20:19:09 2017 +0200
@@ -1,7 +1,6 @@
   $ cat <<EOF >> $HGRCPATH
   > [ui]
   > color = always
-  > formatted = yes
   > [color]
   > mode = ansi
   > EOF