Skip to content

Commit aebd235

Browse files
committed
Merge branch 'jk/ui-color-always-to-auto-maint' into jk/ui-color-always-to-auto
* jk/ui-color-always-to-auto-maint: 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 3c788e7 + 6be4595 commit aebd235

19 files changed

+101
-99
lines changed

Documentation/config.txt

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

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

10661066
color.branch.<slot>::
10671067
Use customized color for branch coloration. `<slot>` is one of
@@ -1072,12 +1072,11 @@ color.branch.<slot>::
10721072

10731073
color.diff::
10741074
Whether to use ANSI escape sequences to add color to patches.
1075-
If this is set to `always`, linkgit:git-diff[1],
1075+
If this is set to `true` or `auto`, linkgit:git-diff[1],
10761076
linkgit:git-log[1], and linkgit:git-show[1] will use color
1077-
for all patches. If it is set to `true` or `auto`, those
1078-
commands will only use color when output is to the terminal.
1079-
If unset, then the value of `color.ui` is used (`auto` by
1080-
default).
1077+
when output is to the terminal. The value `always` is a
1078+
historical synonym for `auto`. If unset, then the value of
1079+
`color.ui` is used (`auto` by default).
10811080
+
10821081
This does not affect linkgit:git-format-patch[1] or the
10831082
'git-diff-{asterisk}' plumbing commands. Can be overridden on the
@@ -1141,12 +1140,12 @@ color.grep.<slot>::
11411140
--
11421141

11431142
color.interactive::
1144-
When set to `always`, always use colors for interactive prompts
1143+
When set to `true` or `auto`, use colors for interactive prompts
11451144
and displays (such as those used by "git-add --interactive" and
1146-
"git-clean --interactive"). When false (or `never`), never.
1147-
When set to `true` or `auto`, use colors only when the output is
1148-
to the terminal. If unset, then the value of `color.ui` is
1149-
used (`auto` by default).
1145+
"git-clean --interactive") when the output is to the terminal.
1146+
When false (or `never`), never show colors. The value `always`
1147+
is a historical synonym for `auto`. If unset, then the value of
1148+
`color.ui` is used (`auto` by default).
11501149

11511150
color.interactive.<slot>::
11521151
Use customized color for 'git add --interactive' and 'git clean
@@ -1193,10 +1192,10 @@ color.ui::
11931192
configuration to set a default for the `--color` option. Set it
11941193
to `false` or `never` if you prefer Git commands not to use
11951194
color unless enabled explicitly with some other configuration
1196-
or the `--color` option. Set it to `always` if you want all
1197-
output not intended for machine consumption to use color, to
1198-
`true` or `auto` (this is the default since Git 1.8.4) if you
1199-
want such output to use color when written to the terminal.
1195+
or the `--color` option. Set it to `true` or `auto` to enable
1196+
color when output is written to the terminal (this is also the
1197+
default since Git 1.8.4). The value `always` is a historical
1198+
synonym for `auto`.
12001199

12011200
column.ui::
12021201
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
@@ -57,6 +57,11 @@ OPTIONS
5757
`xx`; for example `%00` interpolates to `\0` (NUL),
5858
`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
5959

60+
--color[=<when>]:
61+
Respect any colors specified in the `--format` option. The
62+
`<when>` field must be one of `always`, `never`, or `auto` (if
63+
`<when>` is absent, behave as if `always` was given).
64+
6065
--shell::
6166
--perl::
6267
--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
@@ -820,7 +820,7 @@ test_expect_success 'diff that introduces a line with only tabs' '
820820
echo "test" >x &&
821821
git commit -m "initial" x &&
822822
echo "{NTN}" | tr "NT" "\n\t" >>x &&
823-
git -c color.diff=always diff | test_decode_color >current &&
823+
git diff --color | test_decode_color >current &&
824824
825825
cat >expected <<-\EOF &&
826826
<BOLD>diff --git a/x b/x<RESET>
@@ -850,7 +850,7 @@ test_expect_success 'diff that introduces and removes ws breakages' '
850850
echo "2. and a new line "
851851
} >x &&
852852
853-
git -c color.diff=always diff |
853+
git diff --color |
854854
test_decode_color >current &&
855855
856856
cat >expected <<-\EOF &&
@@ -922,50 +922,50 @@ test_expect_success 'ws-error-highlight test setup' '
922922

923923
test_expect_success 'test --ws-error-highlight option' '
924924
925-
git -c color.diff=always diff --ws-error-highlight=default,old |
925+
git diff --color --ws-error-highlight=default,old |
926926
test_decode_color >current &&
927927
test_cmp expect.default-old current &&
928928
929-
git -c color.diff=always diff --ws-error-highlight=all |
929+
git diff --color --ws-error-highlight=all |
930930
test_decode_color >current &&
931931
test_cmp expect.all current &&
932932
933-
git -c color.diff=always diff --ws-error-highlight=none |
933+
git diff --color --ws-error-highlight=none |
934934
test_decode_color >current &&
935935
test_cmp expect.none current
936936
937937
'
938938

939939
test_expect_success 'test diff.wsErrorHighlight config' '
940940
941-
git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
941+
git -c diff.wsErrorHighlight=default,old diff --color |
942942
test_decode_color >current &&
943943
test_cmp expect.default-old current &&
944944
945-
git -c color.diff=always -c diff.wsErrorHighlight=all diff |
945+
git -c diff.wsErrorHighlight=all diff --color |
946946
test_decode_color >current &&
947947
test_cmp expect.all current &&
948948
949-
git -c color.diff=always -c diff.wsErrorHighlight=none diff |
949+
git -c diff.wsErrorHighlight=none diff --color |
950950
test_decode_color >current &&
951951
test_cmp expect.none current
952952
953953
'
954954

955955
test_expect_success 'option overrides diff.wsErrorHighlight' '
956956
957-
git -c color.diff=always -c diff.wsErrorHighlight=none \
958-
diff --ws-error-highlight=default,old |
957+
git -c diff.wsErrorHighlight=none \
958+
diff --color --ws-error-highlight=default,old |
959959
test_decode_color >current &&
960960
test_cmp expect.default-old current &&
961961
962-
git -c color.diff=always -c diff.wsErrorHighlight=default \
963-
diff --ws-error-highlight=all |
962+
git -c diff.wsErrorHighlight=default \
963+
diff --color --ws-error-highlight=all |
964964
test_decode_color >current &&
965965
test_cmp expect.all current &&
966966
967-
git -c color.diff=always -c diff.wsErrorHighlight=all \
968-
diff --ws-error-highlight=none |
967+
git -c diff.wsErrorHighlight=all \
968+
diff --color --ws-error-highlight=none |
969969
test_decode_color >current &&
970970
test_cmp expect.none current
971971

0 commit comments

Comments
 (0)