Skip to content

Commit 433d62f

Browse files
committed
Merge branch 'jk/ui-color-always-to-auto-maint' (early part) into jk/ref-filter-colors-fix-maint
* 'jk/ui-color-always-to-auto-maint' (early part): 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
2 parents 4010f1d + 6be4595 commit 433d62f

18 files changed

+100
-98
lines changed

Documentation/config.txt

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1052,10 +1052,10 @@ clean.requireForce::
10521052

10531053
color.branch::
10541054
A boolean to enable/disable color in the output of
1055-
linkgit:git-branch[1]. May be set to `always`,
1056-
`false` (or `never`) or `auto` (or `true`), in which case colors are used
1057-
only when the output is to a terminal. If unset, then the
1058-
value of `color.ui` is used (`auto` by default).
1055+
linkgit:git-branch[1]. May be set to `false` (or `never`) to
1056+
disable color entirely, `auto` (or `true` or `always`) in which
1057+
case colors are used only when the output is to a terminal. If
1058+
unset, then the value of `color.ui` is used (`auto` by default).
10591059

10601060
color.branch.<slot>::
10611061
Use customized color for branch coloration. `<slot>` is one of
@@ -1066,12 +1066,11 @@ color.branch.<slot>::
10661066

10671067
color.diff::
10681068
Whether to use ANSI escape sequences to add color to patches.
1069-
If this is set to `always`, linkgit:git-diff[1],
1069+
If this is set to `true` or `auto`, linkgit:git-diff[1],
10701070
linkgit:git-log[1], and linkgit:git-show[1] will use color
1071-
for all patches. If it is set to `true` or `auto`, those
1072-
commands will only use color when output is to the terminal.
1073-
If unset, then the value of `color.ui` is used (`auto` by
1074-
default).
1071+
when output is to the terminal. The value `always` is a
1072+
historical synonym for `auto`. If unset, then the value of
1073+
`color.ui` is used (`auto` by default).
10751074
+
10761075
This does not affect linkgit:git-format-patch[1] or the
10771076
'git-diff-{asterisk}' plumbing commands. Can be overridden on the
@@ -1124,12 +1123,12 @@ color.grep.<slot>::
11241123
--
11251124

11261125
color.interactive::
1127-
When set to `always`, always use colors for interactive prompts
1126+
When set to `true` or `auto`, use colors for interactive prompts
11281127
and displays (such as those used by "git-add --interactive" and
1129-
"git-clean --interactive"). When false (or `never`), never.
1130-
When set to `true` or `auto`, use colors only when the output is
1131-
to the terminal. If unset, then the value of `color.ui` is
1132-
used (`auto` by default).
1128+
"git-clean --interactive") when the output is to the terminal.
1129+
When false (or `never`), never show colors. The value `always`
1130+
is a historical synonym for `auto`. If unset, then the value of
1131+
`color.ui` is used (`auto` by default).
11331132

11341133
color.interactive.<slot>::
11351134
Use customized color for 'git add --interactive' and 'git clean
@@ -1176,10 +1175,10 @@ color.ui::
11761175
configuration to set a default for the `--color` option. Set it
11771176
to `false` or `never` if you prefer Git commands not to use
11781177
color unless enabled explicitly with some other configuration
1179-
or the `--color` option. Set it to `always` if you want all
1180-
output not intended for machine consumption to use color, to
1181-
`true` or `auto` (this is the default since Git 1.8.4) if you
1182-
want such output to use color when written to the terminal.
1178+
or the `--color` option. Set it to `true` or `auto` to enable
1179+
color when output is written to the terminal (this is also the
1180+
default since Git 1.8.4). The value `always` is a historical
1181+
synonym for `auto`.
11831182

11841183
column.ui::
11851184
Specify whether supported commands should output in columns.

Documentation/git-for-each-ref.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ OPTIONS
5656
literally, in the latter case matching completely or from the
5757
beginning up to a slash.
5858

59+
--color[=<when>]:
60+
Respect any colors specified in the `--format` option. The
61+
`<when>` field must be one of `always`, `never`, or `auto` (if
62+
`<when>` is absent, behave as if `always` was given).
63+
5964
--shell::
6065
--perl::
6166
--python::

Documentation/git-tag.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,11 @@ options for details.
115115
variable if it exists, or lexicographic order otherwise. See
116116
linkgit:git-config[1].
117117

118+
--color[=<when>]:
119+
Respect any colors specified in the `--format` option. The
120+
`<when>` field must be one of `always`, `never`, or `auto` (if
121+
`<when>` is absent, behave as if `always` was given).
122+
118123
-i::
119124
--ignore-case::
120125
Sorting and filtering tags are case insensitive.

builtin/for-each-ref.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
3636
OPT_GROUP(""),
3737
OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
3838
OPT_STRING( 0 , "format", &format.format, N_("format"), N_("format to use for the output")),
39+
OPT__COLOR(&format.use_color, N_("respect format colors")),
3940
OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
4041
N_("field name to sort on"), &parse_opt_ref_sorting),
4142
OPT_CALLBACK(0, "points-at", &filter.points_at,

builtin/tag.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
411411
},
412412
OPT_STRING( 0 , "format", &format.format, N_("format"),
413413
N_("format to use for the output")),
414+
OPT__COLOR(&format.use_color, N_("respect format colors")),
414415
OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
415416
OPT_END()
416417
};

color.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,7 @@ int git_config_colorbool(const char *var, const char *value)
308308
if (!strcasecmp(value, "never"))
309309
return 0;
310310
if (!strcasecmp(value, "always"))
311-
return 1;
311+
return var ? GIT_COLOR_AUTO : 1;
312312
if (!strcasecmp(value, "auto"))
313313
return GIT_COLOR_AUTO;
314314
}

t/t3203-branch-output.sh

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -253,13 +253,7 @@ test_expect_success '%(color) omitted without tty' '
253253
'
254254

255255
test_expect_success TTY '%(color) present with tty' '
256-
test_terminal env TERM=vt100 git branch $color_args >actual.raw &&
257-
test_decode_color <actual.raw >actual &&
258-
test_cmp expect.color actual
259-
'
260-
261-
test_expect_success 'color.branch=always overrides auto-color' '
262-
git -c color.branch=always branch $color_args >actual.raw &&
256+
test_terminal git branch $color_args >actual.raw &&
263257
test_decode_color <actual.raw >actual &&
264258
test_cmp expect.color actual
265259
'

t/t3205-branch-color.sh

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ test_expect_success 'set up some sample branches' '
1212
# choose non-default colors to make sure config
1313
# is taking effect
1414
test_expect_success 'set up some color config' '
15-
git config color.branch always &&
1615
git config color.branch.local blue &&
1716
git config color.branch.remote yellow &&
1817
git config color.branch.current cyan
@@ -24,7 +23,7 @@ test_expect_success 'regular output shows colors' '
2423
<BLUE>other<RESET>
2524
<YELLOW>remotes/origin/master<RESET>
2625
EOF
27-
git branch -a >actual.raw &&
26+
git branch --color -a >actual.raw &&
2827
test_decode_color <actual.raw >actual &&
2928
test_cmp expect actual
3029
'
@@ -36,7 +35,7 @@ test_expect_success 'verbose output shows colors' '
3635
<BLUE>other <RESET> $oid foo
3736
<YELLOW>remotes/origin/master<RESET> $oid foo
3837
EOF
39-
git branch -v -a >actual.raw &&
38+
git branch --color -v -a >actual.raw &&
4039
test_decode_color <actual.raw >actual &&
4140
test_cmp expect actual
4241
'

t/t3701-add-interactive.sh

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
test_description='add -i basic tests'
44
. ./test-lib.sh
5+
. "$TEST_DIRECTORY"/lib-terminal.sh
56

67
if ! test_have_prereq PERL
78
then
@@ -380,14 +381,11 @@ test_expect_success 'patch mode ignores unmerged entries' '
380381
test_cmp expected diff
381382
'
382383

383-
test_expect_success 'diffs can be colorized' '
384+
test_expect_success TTY 'diffs can be colorized' '
384385
git reset --hard &&
385386
386-
# force color even though the test script has no terminal
387-
test_config color.ui always &&
388-
389387
echo content >test &&
390-
printf y | git add -p >output 2>&1 &&
388+
printf y | test_terminal git add -p >output 2>&1 &&
391389
392390
# We do not want to depend on the exact coloring scheme
393391
# 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' '
485483
git diff --exit-code
486484
'
487485

486+
test_expect_success 'add -p works even with color.ui=always' '
487+
git reset --hard &&
488+
echo change >>file &&
489+
test_config color.ui always &&
490+
echo y | git add -p &&
491+
echo file >expect &&
492+
git diff --cached --name-only >actual &&
493+
test_cmp expect actual
494+
'
495+
488496
test_done

t/t4015-diff-whitespace.sh

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -821,7 +821,7 @@ test_expect_success 'diff that introduces a line with only tabs' '
821821
echo "test" >x &&
822822
git commit -m "initial" x &&
823823
echo "{NTN}" | tr "NT" "\n\t" >>x &&
824-
git -c color.diff=always diff | test_decode_color >current &&
824+
git diff --color | test_decode_color >current &&
825825
826826
cat >expected <<-\EOF &&
827827
<BOLD>diff --git a/x b/x<RESET>
@@ -851,7 +851,7 @@ test_expect_success 'diff that introduces and removes ws breakages' '
851851
echo "2. and a new line "
852852
} >x &&
853853
854-
git -c color.diff=always diff |
854+
git diff --color |
855855
test_decode_color >current &&
856856
857857
cat >expected <<-\EOF &&
@@ -923,50 +923,50 @@ test_expect_success 'ws-error-highlight test setup' '
923923

924924
test_expect_success 'test --ws-error-highlight option' '
925925
926-
git -c color.diff=always diff --ws-error-highlight=default,old |
926+
git diff --color --ws-error-highlight=default,old |
927927
test_decode_color >current &&
928928
test_cmp expect.default-old current &&
929929
930-
git -c color.diff=always diff --ws-error-highlight=all |
930+
git diff --color --ws-error-highlight=all |
931931
test_decode_color >current &&
932932
test_cmp expect.all current &&
933933
934-
git -c color.diff=always diff --ws-error-highlight=none |
934+
git diff --color --ws-error-highlight=none |
935935
test_decode_color >current &&
936936
test_cmp expect.none current
937937
938938
'
939939

940940
test_expect_success 'test diff.wsErrorHighlight config' '
941941
942-
git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
942+
git -c diff.wsErrorHighlight=default,old diff --color |
943943
test_decode_color >current &&
944944
test_cmp expect.default-old current &&
945945
946-
git -c color.diff=always -c diff.wsErrorHighlight=all diff |
946+
git -c diff.wsErrorHighlight=all diff --color |
947947
test_decode_color >current &&
948948
test_cmp expect.all current &&
949949
950-
git -c color.diff=always -c diff.wsErrorHighlight=none diff |
950+
git -c diff.wsErrorHighlight=none diff --color |
951951
test_decode_color >current &&
952952
test_cmp expect.none current
953953
954954
'
955955

956956
test_expect_success 'option overrides diff.wsErrorHighlight' '
957957
958-
git -c color.diff=always -c diff.wsErrorHighlight=none \
959-
diff --ws-error-highlight=default,old |
958+
git -c diff.wsErrorHighlight=none \
959+
diff --color --ws-error-highlight=default,old |
960960
test_decode_color >current &&
961961
test_cmp expect.default-old current &&
962962
963-
git -c color.diff=always -c diff.wsErrorHighlight=default \
964-
diff --ws-error-highlight=all |
963+
git -c diff.wsErrorHighlight=default \
964+
diff --color --ws-error-highlight=all |
965965
test_decode_color >current &&
966966
test_cmp expect.all current &&
967967
968-
git -c color.diff=always -c diff.wsErrorHighlight=all \
969-
diff --ws-error-highlight=none |
968+
git -c diff.wsErrorHighlight=all \
969+
diff --color --ws-error-highlight=none |
970970
test_decode_color >current &&
971971
test_cmp expect.none current
972972

0 commit comments

Comments
 (0)