Skip to content

Commit da15b78

Browse files
committed
Merge branch 'jk/ui-color-always-to-auto'
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
2 parents 5261fef + aebd235 commit da15b78

19 files changed

+115
-113
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: 26 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,6 @@ test_expect_success 'combined diff with autocrlf conversion' '
802802
# Start testing the colored format for whitespace checks
803803

804804
test_expect_success 'setup diff colors' '
805-
git config color.diff always &&
806805
git config color.diff.plain normal &&
807806
git config color.diff.meta bold &&
808807
git config color.diff.frag cyan &&
@@ -821,7 +820,7 @@ test_expect_success 'diff that introduces a line with only tabs' '
821820
echo "test" >x &&
822821
git commit -m "initial" x &&
823822
echo "{NTN}" | tr "NT" "\n\t" >>x &&
824-
git -c color.diff=always diff | test_decode_color >current &&
823+
git diff --color | test_decode_color >current &&
825824
826825
cat >expected <<-\EOF &&
827826
<BOLD>diff --git a/x b/x<RESET>
@@ -851,7 +850,7 @@ test_expect_success 'diff that introduces and removes ws breakages' '
851850
echo "2. and a new line "
852851
} >x &&
853852
854-
git -c color.diff=always diff |
853+
git diff --color |
855854
test_decode_color >current &&
856855
857856
cat >expected <<-\EOF &&
@@ -923,50 +922,50 @@ test_expect_success 'ws-error-highlight test setup' '
923922

924923
test_expect_success 'test --ws-error-highlight option' '
925924
926-
git -c color.diff=always diff --ws-error-highlight=default,old |
925+
git diff --color --ws-error-highlight=default,old |
927926
test_decode_color >current &&
928927
test_cmp expect.default-old current &&
929928
930-
git -c color.diff=always diff --ws-error-highlight=all |
929+
git diff --color --ws-error-highlight=all |
931930
test_decode_color >current &&
932931
test_cmp expect.all current &&
933932
934-
git -c color.diff=always diff --ws-error-highlight=none |
933+
git diff --color --ws-error-highlight=none |
935934
test_decode_color >current &&
936935
test_cmp expect.none current
937936
938937
'
939938

940939
test_expect_success 'test diff.wsErrorHighlight config' '
941940
942-
git -c color.diff=always -c diff.wsErrorHighlight=default,old diff |
941+
git -c diff.wsErrorHighlight=default,old diff --color |
943942
test_decode_color >current &&
944943
test_cmp expect.default-old current &&
945944
946-
git -c color.diff=always -c diff.wsErrorHighlight=all diff |
945+
git -c diff.wsErrorHighlight=all diff --color |
947946
test_decode_color >current &&
948947
test_cmp expect.all current &&
949948
950-
git -c color.diff=always -c diff.wsErrorHighlight=none diff |
949+
git -c diff.wsErrorHighlight=none diff --color |
951950
test_decode_color >current &&
952951
test_cmp expect.none current
953952
954953
'
955954

956955
test_expect_success 'option overrides diff.wsErrorHighlight' '
957956
958-
git -c color.diff=always -c diff.wsErrorHighlight=none \
959-
diff --ws-error-highlight=default,old |
957+
git -c diff.wsErrorHighlight=none \
958+
diff --color --ws-error-highlight=default,old |
960959
test_decode_color >current &&
961960
test_cmp expect.default-old current &&
962961
963-
git -c color.diff=always -c diff.wsErrorHighlight=default \
964-
diff --ws-error-highlight=all |
962+
git -c diff.wsErrorHighlight=default \
963+
diff --color --ws-error-highlight=all |
965964
test_decode_color >current &&
966965
test_cmp expect.all current &&
967966
968-
git -c color.diff=always -c diff.wsErrorHighlight=all \
969-
diff --ws-error-highlight=none |
967+
git -c diff.wsErrorHighlight=all \
968+
diff --color --ws-error-highlight=none |
970969
test_decode_color >current &&
971970
test_cmp expect.none current
972971
@@ -986,7 +985,7 @@ test_expect_success 'detect moved code, complete file' '
986985
git mv test.c main.c &&
987986
test_config color.diff.oldMoved "normal red" &&
988987
test_config color.diff.newMoved "normal green" &&
989-
git diff HEAD --color-moved=zebra --no-renames | test_decode_color >actual &&
988+
git diff HEAD --color-moved=zebra --color --no-renames | test_decode_color >actual &&
990989
cat >expected <<-\EOF &&
991990
<BOLD>diff --git a/main.c b/main.c<RESET>
992991
<BOLD>new file mode 100644<RESET>
@@ -1087,7 +1086,7 @@ test_expect_success 'detect malicious moved code, inside file' '
10871086
bar();
10881087
}
10891088
EOF
1090-
git diff HEAD --no-renames --color-moved=zebra| test_decode_color >actual &&
1089+
git diff HEAD --no-renames --color-moved=zebra --color | test_decode_color >actual &&
10911090
cat <<-\EOF >expected &&
10921091
<BOLD>diff --git a/main.c b/main.c<RESET>
10931092
<BOLD>index 27a619c..7cf9336 100644<RESET>
@@ -1136,7 +1135,7 @@ test_expect_success 'plain moved code, inside file' '
11361135
test_config color.diff.oldMovedAlternative "blue" &&
11371136
test_config color.diff.newMovedAlternative "yellow" &&
11381137
# needs previous test as setup
1139-
git diff HEAD --no-renames --color-moved=plain| test_decode_color >actual &&
1138+
git diff HEAD --no-renames --color-moved=plain --color | test_decode_color >actual &&
11401139
cat <<-\EOF >expected &&
11411140
<BOLD>diff --git a/main.c b/main.c<RESET>
11421141
<BOLD>index 27a619c..7cf9336 100644<RESET>
@@ -1227,7 +1226,7 @@ test_expect_success 'detect permutations inside moved code -- dimmed_zebra' '
12271226
test_config color.diff.newMovedDimmed "normal cyan" &&
12281227
test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
12291228
test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
1230-
git diff HEAD --no-renames --color-moved=dimmed_zebra |
1229+
git diff HEAD --no-renames --color-moved=dimmed_zebra --color |
12311230
grep -v "index" |
12321231
test_decode_color >actual &&
12331232
cat <<-\EOF >expected &&
@@ -1271,7 +1270,7 @@ test_expect_success 'cmd option assumes configured colored-moved' '
12711270
test_config color.diff.oldMovedAlternativeDimmed "normal blue" &&
12721271
test_config color.diff.newMovedAlternativeDimmed "normal yellow" &&
12731272
test_config diff.colorMoved zebra &&
1274-
git diff HEAD --no-renames --color-moved |
1273+
git diff HEAD --no-renames --color-moved --color |
12751274
grep -v "index" |
12761275
test_decode_color >actual &&
12771276
cat <<-\EOF >expected &&
@@ -1343,7 +1342,7 @@ line 4
13431342
EOF
13441343
test_config color.diff.oldMoved "magenta" &&
13451344
test_config color.diff.newMoved "cyan" &&
1346-
git diff HEAD --no-renames --color-moved |
1345+
git diff HEAD --no-renames --color-moved --color |
13471346
grep -v "index" |
13481347
test_decode_color >actual &&
13491348
cat <<-\EOF >expected &&
@@ -1364,7 +1363,7 @@ EOF
13641363
EOF
13651364
test_cmp expected actual &&
13661365
1367-
git diff HEAD --no-renames -w --color-moved |
1366+
git diff HEAD --no-renames -w --color-moved --color |
13681367
grep -v "index" |
13691368
test_decode_color >actual &&
13701369
cat <<-\EOF >expected &&
@@ -1403,7 +1402,7 @@ test_expect_success '--color-moved block at end of diff output respects MIN_ALNU
14031402
irrelevant_line
14041403
EOF
14051404
1406-
git diff HEAD --color-moved=zebra --no-renames |
1405+
git diff HEAD --color-moved=zebra --color --no-renames |
14071406
grep -v "index" |
14081407
test_decode_color >actual &&
14091408
cat >expected <<-\EOF &&
@@ -1442,7 +1441,7 @@ test_expect_success '--color-moved respects MIN_ALNUM_COUNT' '
14421441
nineteen chars 456789
14431442
EOF
14441443
1445-
git diff HEAD --color-moved=zebra --no-renames |
1444+
git diff HEAD --color-moved=zebra --color --no-renames |
14461445
grep -v "index" |
14471446
test_decode_color >actual &&
14481447
cat >expected <<-\EOF &&
@@ -1485,7 +1484,7 @@ test_expect_success '--color-moved treats adjacent blocks as separate for MIN_AL
14851484
7charsA
14861485
EOF
14871486
1488-
git diff HEAD --color-moved=zebra --no-renames | grep -v "index" | test_decode_color >actual &&
1487+
git diff HEAD --color-moved=zebra --color --no-renames | grep -v "index" | test_decode_color >actual &&
14891488
cat >expected <<-\EOF &&
14901489
<BOLD>diff --git a/bar b/bar<RESET>
14911490
<BOLD>--- a/bar<RESET>
@@ -1519,15 +1518,15 @@ test_expect_success 'move detection with submodules' '
15191518
echo foul >bananas/recipe &&
15201519
echo ripe >fruit.t &&
15211520
1522-
git diff --submodule=diff --color-moved >actual &&
1521+
git diff --submodule=diff --color-moved --color >actual &&
15231522
15241523
# no move detection as the moved line is across repository boundaries.
15251524
test_decode_color <actual >decoded_actual &&
15261525
! grep BGREEN decoded_actual &&
15271526
! grep BRED decoded_actual &&
15281527
15291528
# nor did we mess with it another way
1530-
git diff --submodule=diff | test_decode_color >expect &&
1529+
git diff --submodule=diff --color | test_decode_color >expect &&
15311530
test_cmp expect decoded_actual
15321531
'
15331532

0 commit comments

Comments
 (0)