Merge branch 'jk/ui-color-always-to-auto'
authorJunio C Hamano <gitster@pobox.com>
Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)
committerJunio C Hamano <gitster@pobox.com>
Sat, 7 Oct 2017 07:27:55 +0000 (16:27 +0900)
Fix regression of "git add -p" for users with "color.ui = always"
in their configuration, by merging the topic below and adjusting it
for the 'master' front.

* jk/ui-color-always-to-auto:
t7301: use test_terminal to check color
t4015: use --color with --color-moved
color: make "always" the same as "auto" in config
provide --color option for all ref-filter users
t3205: use --color instead of color.branch=always
t3203: drop "always" color test
t6006: drop "always" color config tests
t7502: use diff.noprefix for --verbose test
t7508: use test_terminal for color output
t3701: use test-terminal to collect color output
t4015: prefer --color to -c color.diff=always
test-terminal: set TERM=vt100

19 files changed:
Documentation/config.txt
Documentation/git-for-each-ref.txt
Documentation/git-tag.txt
builtin/for-each-ref.c
builtin/tag.c
color.c
t/t3203-branch-output.sh
t/t3205-branch-color.sh
t/t3701-add-interactive.sh
t/t4015-diff-whitespace.sh
t/t4202-log.sh
t/t6006-rev-list-format.sh
t/t6300-for-each-ref.sh
t/t7004-tag.sh
t/t7006-pager.sh
t/t7301-clean-interactive.sh
t/t7502-commit.sh
t/t7508-status.sh
t/test-terminal.perl
index 1ac0ae6adb0460a3460084aef2302434e24ee6de..b53c994d0a9f41da483aa22f66c7e308044eda1e 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 `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).
+       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).
 
 color.branch.<slot>::
        Use customized color for branch coloration. `<slot>` is one of
@@ -1072,12 +1072,11 @@ color.branch.<slot>::
 
 color.diff::
        Whether to use ANSI escape sequences to add color to patches.
-       If this is set to `always`, linkgit:git-diff[1],
+       If this is set to `true` or `auto`, linkgit:git-diff[1],
        linkgit:git-log[1], and linkgit:git-show[1] will use color
-       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).
+       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).
 +
 This does not affect linkgit:git-format-patch[1] or the
 'git-diff-{asterisk}' plumbing commands.  Can be overridden on the
@@ -1141,12 +1140,12 @@ color.grep.<slot>::
 --
 
 color.interactive::
-       When set to `always`, always use colors for interactive prompts
+       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 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).
+       "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).
 
 color.interactive.<slot>::
        Use customized color for 'git add --interactive' and 'git clean
@@ -1193,10 +1192,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 `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.
+       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`.
 
 column.ui::
        Specify whether supported commands should output in columns.
index 66b4e0a4050655e7fab27a6fe72af03d6c99f3b2..cbd0a6212a62a618252e7b56397239d4066dcbd7 100644 (file)
@@ -57,6 +57,11 @@ OPTIONS
        `xx`; for example `%00` interpolates to `\0` (NUL),
        `%09` to `\t` (TAB) and `%0a` to `\n` (LF).
 
+--color[=<when>]:
+       Respect any colors specified in the `--format` option. The
+       `<when>` field must be one of `always`, `never`, or `auto` (if
+       `<when>` is absent, behave as if `always` was given).
+
 --shell::
 --perl::
 --python::
index 95e9f391d88fc434df6bc3f0483c9b3c80983021..956fc019f984bca1754a72dc0d7308b39a28445d 100644 (file)
@@ -115,6 +115,11 @@ options for details.
        variable if it exists, or lexicographic order otherwise. See
        linkgit:git-config[1].
 
+--color[=<when>]:
+       Respect any colors specified in the `--format` option. The
+       `<when>` field must be one of `always`, `never`, or `auto` (if
+       `<when>` is absent, behave as if `always` was given).
+
 -i::
 --ignore-case::
        Sorting and filtering tags are case insensitive.
index 5d7c921a773718d6bee7f85b8d868fc22602377d..e931be9ce4d9f180de23d09d227e5a2f571f4f1a 100644 (file)
@@ -36,6 +36,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
                OPT_GROUP(""),
                OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
                OPT_STRING(  0 , "format", &format.format, N_("format"), N_("format to use for the output")),
+               OPT__COLOR(&format.use_color, N_("respect format colors")),
                OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
                            N_("field name to sort on"), &parse_opt_ref_sorting),
                OPT_CALLBACK(0, "points-at", &filter.points_at,
index 34efba5798e226f684906af74ebbc104e8401f39..695cb0778e2cad52d829030b00f91a4b230224e1 100644 (file)
@@ -411,6 +411,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                },
                OPT_STRING(  0 , "format", &format.format, N_("format"),
                           N_("format to use for the output")),
+               OPT__COLOR(&format.use_color, N_("respect format colors")),
                OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
                OPT_END()
        };
diff --git a/color.c b/color.c
index 9ccd954d6ba5cea1dd275cac23bb19966b9c6386..9c0dc823701d6aff0979659cd19ebb9c92f2eb8a 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 1;
+                       return var ? GIT_COLOR_AUTO : 1;
                if (!strcasecmp(value, "auto"))
                        return GIT_COLOR_AUTO;
        }
index d2aec0f38b7913b27687b332029dc78be59bc182..ee6787614c80edb9b5b24065277dd413350a6fc6 100755 (executable)
@@ -253,13 +253,7 @@ test_expect_success '%(color) omitted without tty' '
 '
 
 test_expect_success TTY '%(color) present with tty' '
-       test_terminal env TERM=vt100 git branch $color_args >actual.raw &&
-       test_decode_color <actual.raw >actual &&
-       test_cmp expect.color actual
-'
-
-test_expect_success 'color.branch=always overrides auto-color' '
-       git -c color.branch=always branch $color_args >actual.raw &&
+       test_terminal git branch $color_args >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expect.color actual
 '
index 9343550f50a011ff563c1455384cd1b14fd83888..4f1e16bb44e279a0c5c0fc96f95eb285e4b22c3c 100755 (executable)
@@ -12,7 +12,6 @@ test_expect_success 'set up some sample branches' '
 # choose non-default colors to make sure config
 # is taking effect
 test_expect_success 'set up some color config' '
-       git config color.branch always &&
        git config color.branch.local blue &&
        git config color.branch.remote yellow &&
        git config color.branch.current cyan
@@ -24,7 +23,7 @@ test_expect_success 'regular output shows colors' '
          <BLUE>other<RESET>
          <YELLOW>remotes/origin/master<RESET>
        EOF
-       git branch -a >actual.raw &&
+       git branch --color -a >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expect actual
 '
@@ -36,7 +35,7 @@ test_expect_success 'verbose output shows colors' '
          <BLUE>other                <RESET> $oid foo
          <YELLOW>remotes/origin/master<RESET> $oid foo
        EOF
-       git branch -v -a >actual.raw &&
+       git branch --color -v -a >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expect actual
 '
index 2f3e7cea64e897299d87196135032de22050354b..a49c12c79b28fac8545dffcbaba8e8905c8d6222 100755 (executable)
@@ -2,6 +2,7 @@
 
 test_description='add -i basic tests'
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
 
 if ! test_have_prereq PERL
 then
@@ -380,14 +381,11 @@ test_expect_success 'patch mode ignores unmerged entries' '
        test_cmp expected diff
 '
 
-test_expect_success 'diffs can be colorized' '
+test_expect_success TTY 'diffs can be colorized' '
        git reset --hard &&
 
-       # force color even though the test script has no terminal
-       test_config color.ui always &&
-
        echo content >test &&
-       printf y | git add -p >output 2>&1 &&
+       printf y | test_terminal git add -p >output 2>&1 &&
 
        # We do not want to depend on the exact coloring scheme
        # git uses for diffs, so just check that we saw some kind of color.
@@ -485,4 +483,14 @@ test_expect_success 'hunk-editing handles custom comment char' '
        git diff --exit-code
 '
 
+test_expect_success 'add -p works even with color.ui=always' '
+       git reset --hard &&
+       echo change >>file &&
+       test_config color.ui always &&
+       echo y | git add -p &&
+       echo file >expect &&
+       git diff --cached --name-only >actual &&
+       test_cmp expect actual
+'
+
 test_done
index 12d182dc1bba82401a929e6207eb2dcc7ea21672..3bca958863e68783105b542765930ebd7518b49b 100755 (executable)
@@ -802,7 +802,6 @@ test_expect_success 'combined diff with autocrlf conversion' '
 # Start testing the colored format for whitespace checks
 
 test_expect_success 'setup diff colors' '
-       git config color.diff always &&
        git config color.diff.plain normal &&
        git config color.diff.meta bold &&
        git config color.diff.frag cyan &&
@@ -821,7 +820,7 @@ test_expect_success 'diff that introduces a line with only tabs' '
        echo "test" >x &&
        git commit -m "initial" x &&
        echo "{NTN}" | tr "NT" "\n\t" >>x &&
-       git -c color.diff=always diff | test_decode_color >current &&
+       git diff --color | test_decode_color >current &&
 
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/x b/x<RESET>
@@ -851,7 +850,7 @@ test_expect_success 'diff that introduces and removes ws breakages' '
                echo "2. and a new line "
        } >x &&
 
-       git -c color.diff=always diff |
+       git diff --color |
        test_decode_color >current &&
 
        cat >expected <<-\EOF &&
@@ -923,15 +922,15 @@ test_expect_success 'ws-error-highlight test setup' '
 
 test_expect_success 'test --ws-error-highlight option' '
 
-       git -c color.diff=always diff --ws-error-highlight=default,old |
+       git diff --color --ws-error-highlight=default,old |
        test_decode_color >current &&
        test_cmp expect.default-old current &&
 
-       git -c color.diff=always diff --ws-error-highlight=all |
+       git diff --color --ws-error-highlight=all |
        test_decode_color >current &&
        test_cmp expect.all current &&
 
-       git -c color.diff=always diff --ws-error-highlight=none |
+       git diff --color --ws-error-highlight=none |
        test_decode_color >current &&
        test_cmp expect.none current
 
@@ -939,15 +938,15 @@ test_expect_success 'test --ws-error-highlight option' '
 
 test_expect_success 'test diff.wsErrorHighlight config' '
 
-       git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
+       git -c diff.wsErrorHighlight=default,old diff --color |
        test_decode_color >current &&
        test_cmp expect.default-old current &&
 
-       git -c color.diff=always -c diff.wsErrorHighlight=all diff |
+       git -c diff.wsErrorHighlight=all diff --color |
        test_decode_color >current &&
        test_cmp expect.all current &&
 
-       git -c color.diff=always -c diff.wsErrorHighlight=none diff |
+       git -c diff.wsErrorHighlight=none diff --color |
        test_decode_color >current &&
        test_cmp expect.none current
 
@@ -955,18 +954,18 @@ test_expect_success 'test diff.wsErrorHighlight config' '
 
 test_expect_success 'option overrides diff.wsErrorHighlight' '
 
-       git -c color.diff=always -c diff.wsErrorHighlight=none \
-               diff --ws-error-highlight=default,old |
+       git -c diff.wsErrorHighlight=none \
+               diff --color --ws-error-highlight=default,old |
        test_decode_color >current &&
        test_cmp expect.default-old current &&
 
-       git -c color.diff=always -c diff.wsErrorHighlight=default \
-               diff --ws-error-highlight=all |
+       git -c diff.wsErrorHighlight=default \
+               diff --color --ws-error-highlight=all |
        test_decode_color >current &&
        test_cmp expect.all current &&
 
-       git -c color.diff=always -c diff.wsErrorHighlight=all \
-               diff --ws-error-highlight=none |
+       git -c diff.wsErrorHighlight=all \
+               diff --color --ws-error-highlight=none |
        test_decode_color >current &&
        test_cmp expect.none current
 
@@ -986,7 +985,7 @@ test_expect_success 'detect moved code, complete file' '
        git mv test.c main.c &&
        test_config color.diff.oldMoved "normal red" &&
        test_config color.diff.newMoved "normal green" &&
-       git diff HEAD --color-moved=zebra --no-renames | test_decode_color >actual &&
+       git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/main.c b/main.c<RESET>
        <BOLD>new file mode 100644<RESET>
@@ -1087,7 +1086,7 @@ test_expect_success 'detect malicious moved code, inside file' '
                        bar();
                }
        EOF
-       git diff HEAD --no-renames --color-moved=zebra| test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/main.c b/main.c<RESET>
        <BOLD>index 27a619c..7cf9336 100644<RESET>
@@ -1136,7 +1135,7 @@ test_expect_success 'plain moved code, inside file' '
        test_config color.diff.oldMovedAlternative "blue" &&
        test_config color.diff.newMovedAlternative "yellow" &&
        # needs previous test as setup
-       git diff HEAD --no-renames --color-moved=plain| test_decode_color >actual &&
+       git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
        cat <<-\EOF >expected &&
        <BOLD>diff --git a/main.c b/main.c<RESET>
        <BOLD>index 27a619c..7cf9336 100644<RESET>
@@ -1227,7 +1226,7 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
        test_config color.diff.newMovedDimmed "normal cyan" &&
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
-       git diff HEAD --no-renames --color-moved=dimmed_zebra |
+       git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
                grep -v "index" |
                test_decode_color >actual &&
        cat <<-\EOF >expected &&
@@ -1271,7 +1270,7 @@ test_expect_success 'cmd option assumes configured colored-moved' '
        test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
        test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
        test_config diff.colorMoved zebra &&
-       git diff HEAD --no-renames --color-moved |
+       git diff HEAD --no-renames --color-moved --color |
                grep -v "index" |
                test_decode_color >actual &&
        cat <<-\EOF >expected &&
@@ -1343,7 +1342,7 @@ line 4
 EOF
        test_config color.diff.oldMoved "magenta" &&
        test_config color.diff.newMoved "cyan" &&
-       git diff HEAD --no-renames --color-moved |
+       git diff HEAD --no-renames --color-moved --color |
                grep -v "index" |
                test_decode_color >actual &&
        cat <<-\EOF >expected &&
@@ -1364,7 +1363,7 @@ EOF
        EOF
        test_cmp expected actual &&
 
-       git diff HEAD --no-renames -w --color-moved |
+       git diff HEAD --no-renames -w --color-moved --color |
                grep -v "index" |
                test_decode_color >actual &&
        cat <<-\EOF >expected &&
@@ -1403,7 +1402,7 @@ test_expect_success '--color-moved block at end of diff output respects MIN_ALNU
        irrelevant_line
        EOF
 
-       git diff HEAD --color-moved=zebra --no-renames |
+       git diff HEAD --color-moved=zebra --color --no-renames |
                grep -v "index" |
                test_decode_color >actual &&
        cat >expected <<-\EOF &&
@@ -1442,7 +1441,7 @@ test_expect_success '--color-moved respects MIN_ALNUM_COUNT' '
        nineteen chars 456789
        EOF
 
-       git diff HEAD --color-moved=zebra --no-renames |
+       git diff HEAD --color-moved=zebra --color --no-renames |
                grep -v "index" |
                test_decode_color >actual &&
        cat >expected <<-\EOF &&
@@ -1485,7 +1484,7 @@ test_expect_success '--color-moved treats adjacent blocks as separate for MIN_AL
        7charsA
        EOF
 
-       git diff HEAD --color-moved=zebra --no-renames | grep -v "index" | test_decode_color >actual &&
+       git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
        cat >expected <<-\EOF &&
        <BOLD>diff --git a/bar b/bar<RESET>
        <BOLD>--- a/bar<RESET>
@@ -1519,7 +1518,7 @@ test_expect_success 'move detection with submodules' '
        echo foul >bananas/recipe &&
        echo ripe >fruit.t &&
 
-       git diff --submodule=diff --color-moved >actual &&
+       git diff --submodule=diff --color-moved --color >actual &&
 
        # no move detection as the moved line is across repository boundaries.
        test_decode_color <actual >decoded_actual &&
@@ -1527,7 +1526,7 @@ test_expect_success 'move detection with submodules' '
        ! grep BRED decoded_actual &&
 
        # nor did we mess with it another way
-       git diff --submodule=diff | test_decode_color >expect &&
+       git diff --submodule=diff --color | test_decode_color >expect &&
        test_cmp expect decoded_actual
 '
 
index 36d120c969f6c116c2bed19c8bb0c027919d66a9..8f155da7a50a657db9fd092e24639f67cd03cd24 100755 (executable)
@@ -750,7 +750,7 @@ test_expect_success 'log.decorate config parsing' '
 '
 
 test_expect_success TTY 'log output on a TTY' '
-       git log --oneline --decorate >expect.short &&
+       git log --color --oneline --decorate >expect.short &&
 
        test_terminal git log --oneline >actual &&
        test_cmp expect.short actual
index b326d550f3e281e4b19ab669b95f08e8c63bf555..25a9c65dc51926e3520c9b5f7e1fec709acede10 100755 (executable)
@@ -208,29 +208,13 @@ 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 env TERM=vt100 \
-                       git log --format=$color -1 --color=auto >actual &&
+               test_terminal git log --format=$color -1 --color=auto >actual &&
                has_color actual
        '
 
@@ -241,6 +225,11 @@ 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 2274a4b73310bfbc90886e0179a1cb12d9b6f3ed..6358134805302583a49f5102c225b643497637de 100755 (executable)
@@ -425,8 +425,7 @@ test_expect_success 'set up color tests' '
 '
 
 test_expect_success TTY '%(color) shows color with a tty' '
-       test_terminal env TERM=vt100 \
-               git for-each-ref --format="$color_format" >actual.raw &&
+       test_terminal git for-each-ref --format="$color_format" >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expected.color actual
 '
@@ -436,8 +435,8 @@ test_expect_success '%(color) does not show color without tty' '
        test_cmp expected.bare actual
 '
 
-test_expect_success 'color.ui=always can override tty check' '
-       git -c color.ui=always for-each-ref --format="$color_format" >actual.raw &&
+test_expect_success '--color can override tty check' '
+       git for-each-ref --color --format="$color_format" >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expected.color actual
 '
index b545c33f83be94608f18182444ffe37eef753e88..4e62c505fc9ce84adf4b0f74110b39d18c571670 100755 (executable)
@@ -1907,13 +1907,13 @@ test_expect_success '%(color) omitted without tty' '
 '
 
 test_expect_success TTY '%(color) present with tty' '
-       test_terminal env TERM=vt100 git tag $color_args >actual.raw &&
+       test_terminal git tag $color_args >actual.raw &&
        test_decode_color <actual.raw >actual &&
        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_expect_success '--color overrides auto-color' '
+       git tag --color $color_args >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expect.color actual
 '
index 9128ec5acda3b4b2f568dee50169046a333c4527..f0f1abd1c23d4303a686310d7325cd523d6c921b 100755 (executable)
@@ -239,7 +239,7 @@ test_expect_success 'no color when stdout is a regular file' '
 test_expect_success TTY 'color when writing to a pager' '
        rm -f paginated.out &&
        test_config color.ui auto &&
-       test_terminal env TERM=vt100 git log &&
+       test_terminal git log &&
        colorful paginated.out
 '
 
@@ -247,7 +247,7 @@ test_expect_success TTY 'colors are suppressed by color.pager' '
        rm -f paginated.out &&
        test_config color.ui auto &&
        test_config color.pager false &&
-       test_terminal env TERM=vt100 git log &&
+       test_terminal git log &&
        ! colorful paginated.out
 '
 
@@ -266,7 +266,7 @@ test_expect_success 'color when writing to a file intended for a pager' '
 test_expect_success TTY 'colors are sent to pager for external commands' '
        test_config alias.externallog "!git log" &&
        test_config color.ui auto &&
-       test_terminal env TERM=vt100 git -p externallog &&
+       test_terminal git -p externallog &&
        colorful paginated.out
 '
 
index 556e1850e2b20c3f484ee43a975e5dcca8eac99e..1bf9789c8a3cfbb1cc8a6ea33e4a0b1a0da0a7cd 100755 (executable)
@@ -3,6 +3,7 @@
 test_description='git clean -i basic tests'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_expect_success 'setup' '
 
@@ -472,10 +473,10 @@ test_expect_success 'git clean -id with prefix and path (ask)' '
 
 '
 
-test_expect_success 'git clean -i paints the header in HEADER color' '
+test_expect_success TTY 'git clean -i paints the header in HEADER color' '
        >a.out &&
        echo q |
-       git -c color.ui=always clean -i |
+       test_terminal git clean -i |
        test_decode_color |
        head -n 1 >header &&
        # not i18ngrep
index 725687d5d5f26d6535b3f26d1fa221a8c567d57c..d33a3cb331b6c022343aff0bb7091cf8219b40df 100755 (executable)
@@ -171,9 +171,9 @@ test_expect_success 'verbose' '
 
 test_expect_success 'verbose respects diff config' '
 
-       test_config color.diff always &&
+       test_config diff.noprefix true &&
        git status -v >actual &&
-       grep "\[1mdiff --git" actual
+       grep "diff --git negative negative" actual
 '
 
 mesg_with_comment_and_newlines='
index 93f162a4f78cf9c54b12309a62f6a89b2ce4ddbb..50052e28727dab74037a115003b6083256d7f344 100755 (executable)
@@ -6,6 +6,7 @@
 test_description='git status'
 
 . ./test-lib.sh
+. "$TEST_DIRECTORY"/lib-terminal.sh
 
 test_expect_success 'status -h in broken repository' '
        git config --global advice.statusuoption false &&
@@ -667,7 +668,7 @@ test_expect_success 'setup unique colors' '
 
 '
 
-test_expect_success 'status with color.ui' '
+test_expect_success TTY 'status with color.ui' '
        cat >expect <<\EOF &&
 On branch <GREEN>master<RESET>
 Your branch and '\''upstream'\'' have diverged,
@@ -694,14 +695,14 @@ Untracked files:
        <BLUE>untracked<RESET>
 
 EOF
-       test_config color.ui always &&
-       git status | test_decode_color >output &&
+       test_config color.ui auto &&
+       test_terminal git status | test_decode_color >output &&
        test_i18ncmp expect output
 '
 
-test_expect_success 'status with color.status' '
-       test_config color.status always &&
-       git status | test_decode_color >output &&
+test_expect_success TTY 'status with color.status' '
+       test_config color.status auto &&
+       test_terminal git status | test_decode_color >output &&
        test_i18ncmp expect output
 '
 
@@ -714,19 +715,19 @@ cat >expect <<\EOF
 <BLUE>??<RESET> untracked
 EOF
 
-test_expect_success 'status -s with color.ui' '
+test_expect_success TTY 'status -s with color.ui' '
 
-       git config color.ui always &&
-       git status -s | test_decode_color >output &&
+       git config color.ui auto &&
+       test_terminal git status -s | test_decode_color >output &&
        test_cmp expect output
 
 '
 
-test_expect_success 'status -s with color.status' '
+test_expect_success TTY 'status -s with color.status' '
 
        git config --unset color.ui &&
-       git config color.status always &&
-       git status -s | test_decode_color >output &&
+       git config color.status auto &&
+       test_terminal git status -s | test_decode_color >output &&
        test_cmp expect output
 
 '
@@ -741,9 +742,9 @@ cat >expect <<\EOF
 <BLUE>??<RESET> untracked
 EOF
 
-test_expect_success 'status -s -b with color.status' '
+test_expect_success TTY 'status -s -b with color.status' '
 
-       git status -s -b | test_decode_color >output &&
+       test_terminal git status -s -b | test_decode_color >output &&
        test_i18ncmp expect output
 
 '
@@ -757,20 +758,20 @@ A  dir2/added
 ?? untracked
 EOF
 
-test_expect_success 'status --porcelain ignores color.ui' '
+test_expect_success TTY 'status --porcelain ignores color.ui' '
 
        git config --unset color.status &&
-       git config color.ui always &&
-       git status --porcelain | test_decode_color >output &&
+       git config color.ui auto &&
+       test_terminal git status --porcelain | test_decode_color >output &&
        test_cmp expect output
 
 '
 
-test_expect_success 'status --porcelain ignores color.status' '
+test_expect_success TTY 'status --porcelain ignores color.status' '
 
        git config --unset color.ui &&
-       git config color.status always &&
-       git status --porcelain | test_decode_color >output &&
+       git config color.status auto &&
+       test_terminal git status --porcelain | test_decode_color >output &&
        test_cmp expect output
 
 '
index 96b6a03e1c93c9ab6df356c2aad02514232f76ea..46bf6184798442560ad3ae7f68a7972680c5f8eb 100755 (executable)
@@ -80,6 +80,7 @@ sub copy_stdio {
 if ($#ARGV < 1) {
        die "usage: test-terminal program args";
 }
+$ENV{TERM} = 'vt100';
 my $master_in = new IO::Pty;
 my $master_out = new IO::Pty;
 my $master_err = new IO::Pty;