Merge branch 'jk/ref-filter-colors-fix'
authorJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2017 01:19:08 +0000 (10:19 +0900)
committerJunio C Hamano <gitster@pobox.com>
Wed, 18 Oct 2017 01:19:08 +0000 (10:19 +0900)
This is the "theoretically more correct" approach of simply
stepping back to the state before plumbing commands started paying
attention to "color.ui" configuration variable.

Let's run with this one.

* jk/ref-filter-colors-fix:
tag: respect color.ui config
Revert "color: check color.ui in git_default_config()"
Revert "t6006: drop "always" color config tests"
Revert "color: make "always" the same as "auto" in config"

12 files changed:
Documentation/config.txt
builtin/branch.c
builtin/clean.c
builtin/grep.c
builtin/show-branch.c
builtin/tag.c
color.c
config.c
diff.c
t/t6006-rev-list-format.sh
t/t6300-for-each-ref.sh
t/t7004-tag.sh
index b53c994d0a9f41da483aa22f66c7e308044eda1e..1ac0ae6adb0460a3460084aef2302434e24ee6de 100644 (file)
@@ -1058,10 +1058,10 @@ clean.requireForce::
 
 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).
+       linkgit:git-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).
 
 color.branch.<slot>::
        Use customized color for branch coloration. `<slot>` is one of
@@ -1072,11 +1072,12 @@ color.branch.<slot>::
 
 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],
+       If this is set to `always`, 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
-       `color.ui` is used (`auto` by default).
+       for all patches.  If it is set to `true` or `auto`, those
+       commands will only use color when output is to the terminal.
+       If unset, then the value of `color.ui` is used (`auto` by
+       default).
 +
 This does not affect linkgit:git-format-patch[1] or the
 'git-diff-{asterisk}' plumbing commands.  Can be overridden on the
@@ -1140,12 +1141,12 @@ color.grep.<slot>::
 --
 
 color.interactive::
-       When set to `true` or `auto`, use colors for interactive prompts
+       When set to `always`, always 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).
+       "git-clean --interactive"). When false (or `never`), never.
+       When set to `true` or `auto`, use colors only when the output is
+       to the terminal. If unset, then the value of `color.ui` is
+       used (`auto` by default).
 
 color.interactive.<slot>::
        Use customized color for 'git add --interactive' and 'git clean
@@ -1192,10 +1193,10 @@ color.ui::
        configuration to set a default for the `--color` option.  Set it
        to `false` or `never` if you prefer Git commands not to use
        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`.
+       or the `--color` option. Set it to `always` if you want all
+       output not intended for machine consumption to use color, to
+       `true` or `auto` (this is the default since Git 1.8.4) if you
+       want such output to use color when written to the terminal.
 
 column.ui::
        Specify whether supported commands should output in columns.
index b67593288cf54084b569763ba2ef8e3b2cf9aa97..79dc9181fd6c0008d4b8c3b841f35cc1223d6d74 100644 (file)
@@ -93,7 +93,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
                        return config_error_nonbool(var);
                return color_parse(value, branch_colors[slot]);
        }
-       return git_default_config(var, value, cb);
+       return git_color_default_config(var, value, cb);
 }
 
 static const char *branch_get_color(enum color_branch ix)
index 733b6d3745ee5780c697323372f1e78e28b8a117..189e20628c07774089c5c925380b6b69af16fc7f 100644 (file)
@@ -126,7 +126,8 @@ static int git_clean_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       return git_default_config(var, value, cb);
+       /* inspect the color.ui config variable and others */
+       return git_color_default_config(var, value, cb);
 }
 
 static const char *clean_get_color(enum color_clean ix)
index 19e23946ac4bfe53dd0f590fe26250b1f789778b..2d65f27d01f3da772f7bad21f101fdc0af0102ed 100644 (file)
@@ -275,7 +275,7 @@ static int wait_all(void)
 static int grep_cmd_config(const char *var, const char *value, void *cb)
 {
        int st = grep_config(var, value, cb);
-       if (git_default_config(var, value, cb) < 0)
+       if (git_color_default_config(var, value, cb) < 0)
                st = -1;
 
        if (!strcmp(var, "grep.threads")) {
index 84547d6fba07cb7770d94e80cda170c391d04a21..6fa1f62a88ac2704abc6f274ed7a6170bd3a2f4c 100644 (file)
@@ -554,7 +554,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
-       return git_default_config(var, value, cb);
+       return git_color_default_config(var, value, cb);
 }
 
 static int omit_in_dense(struct commit *commit, struct commit **rev, int n)
index 695cb0778e2cad52d829030b00f91a4b230224e1..b38329b593b595edad3efde82aaf1ecb90a73141 100644 (file)
@@ -158,7 +158,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
 
        if (starts_with(var, "column."))
                return git_column_config(var, value, "tag", &colopts);
-       return git_default_config(var, value, cb);
+       return git_color_default_config(var, value, cb);
 }
 
 static void write_tag_body(int fd, const struct object_id *oid)
diff --git a/color.c b/color.c
index 9c0dc823701d6aff0979659cd19ebb9c92f2eb8a..9a9261ac164f503e2a9240806f4f44bedf9b8192 100644 (file)
--- a/color.c
+++ b/color.c
@@ -308,7 +308,7 @@ int git_config_colorbool(const char *var, const char *value)
                if (!strcasecmp(value, "never"))
                        return 0;
                if (!strcasecmp(value, "always"))
-                       return var ? GIT_COLOR_AUTO : 1;
+                       return 1;
                if (!strcasecmp(value, "auto"))
                        return GIT_COLOR_AUTO;
        }
@@ -368,6 +368,14 @@ int git_color_config(const char *var, const char *value, void *cb)
        return 0;
 }
 
+int git_color_default_config(const char *var, const char *value, void *cb)
+{
+       if (git_color_config(var, value, cb) < 0)
+               return -1;
+
+       return git_default_config(var, value, cb);
+}
+
 void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
 {
        if (*color)
index 4831c1273542706437139ccc379afb38e7ca3d3b..adb7d7a3e5ee164d24f1d2420677a8ad5b61e49f 100644 (file)
--- a/config.c
+++ b/config.c
@@ -16,7 +16,6 @@
 #include "string-list.h"
 #include "utf8.h"
 #include "dir.h"
-#include "color.h"
 
 struct config_source {
        struct config_source *prev;
@@ -1351,9 +1350,6 @@ int git_default_config(const char *var, const char *value, void *dummy)
        if (starts_with(var, "advice."))
                return git_default_advice_config(var, value);
 
-       if (git_color_config(var, value, dummy) < 0)
-               return -1;
-
        if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
                pager_use_color = git_config_bool(var,value);
                return 0;
diff --git a/diff.c b/diff.c
index d76bb937c1e49bc5cd3ecaf9f498a90543def822..6fd288420bc55b5213ad6dfea4a4f411543d6dbf 100644 (file)
--- a/diff.c
+++ b/diff.c
@@ -358,6 +358,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
                return 0;
        }
 
+       if (git_color_config(var, value, cb) < 0)
+               return -1;
+
        return git_diff_basic_config(var, value, cb);
 }
 
index 25a9c65dc51926e3520c9b5f7e1fec709acede10..98be78b4a2123cad7e16911ae2eedff5695ba3d3 100755 (executable)
@@ -208,11 +208,26 @@ do
                has_no_color actual
        '
 
+       test_expect_success "$desc enables colors for color.diff" '
+               git -c color.diff=always log --format=$color -1 >actual &&
+               has_color actual
+       '
+
+       test_expect_success "$desc enables colors for color.ui" '
+               git -c color.ui=always log --format=$color -1 >actual &&
+               has_color actual
+       '
+
        test_expect_success "$desc respects --color" '
                git log --format=$color -1 --color >actual &&
                has_color actual
        '
 
+       test_expect_success "$desc respects --no-color" '
+               git -c color.ui=always log --format=$color -1 --no-color >actual &&
+               has_no_color actual
+       '
+
        test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
                test_terminal git log --format=$color -1 --color=auto >actual &&
                has_color actual
@@ -225,11 +240,6 @@ do
                        has_no_color actual
                )
        '
-
-       test_expect_success TTY "$desc respects --no-color" '
-               test_terminal git log --format=$color -1 --no-color >actual &&
-               has_no_color actual
-       '
 done
 
 test_expect_success '%C(always,...) enables color even without tty' '
index 416ff7d0b832d2898173dd2ac83201cf8e02955b..3aa534933e08f85ea1c215e5ef6cc6c7f4a7cd31 100755 (executable)
@@ -442,6 +442,11 @@ test_expect_success '--color can override tty check' '
        test_cmp expected.color actual
 '
 
+test_expect_success 'color.ui=always does not override tty check' '
+       git -c color.ui=always for-each-ref --format="$color_format" >actual &&
+       test_cmp expected.bare actual
+'
+
 cat >expected <<\EOF
 heads/master
 tags/master
index 4e62c505fc9ce84adf4b0f74110b39d18c571670..a9af2de9960b345878ac0f85c33b1efd3e038d28 100755 (executable)
@@ -1918,6 +1918,12 @@ test_expect_success '--color overrides auto-color' '
        test_cmp expect.color actual
 '
 
+test_expect_success 'color.ui=always overrides auto-color' '
+       git -c color.ui=always tag $color_args >actual.raw &&
+       test_decode_color <actual.raw >actual &&
+       test_cmp expect.color actual
+'
+
 test_expect_success 'setup --merged test tags' '
        git tag mergetest-1 HEAD~2 &&
        git tag mergetest-2 HEAD~1 &&