Skip to content

Commit 1c0b983

Browse files
committed
Merge branch 'jk/ref-filter-colors-fix'
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"
2 parents 570676e + b521fd1 commit 1c0b983

12 files changed

+62
-32
lines changed

Documentation/config.txt

+18-17
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 `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).
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).
10651065

10661066
color.branch.<slot>::
10671067
Use customized color for branch coloration. `<slot>` is one of
@@ -1072,11 +1072,12 @@ 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 `true` or `auto`, linkgit:git-diff[1],
1075+
If this is set to `always`, linkgit:git-diff[1],
10761076
linkgit:git-log[1], and linkgit:git-show[1] will use color
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).
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).
10801081
+
10811082
This does not affect linkgit:git-format-patch[1] or the
10821083
'git-diff-{asterisk}' plumbing commands. Can be overridden on the
@@ -1140,12 +1141,12 @@ color.grep.<slot>::
11401141
--
11411142

11421143
color.interactive::
1143-
When set to `true` or `auto`, use colors for interactive prompts
1144+
When set to `always`, always use colors for interactive prompts
11441145
and displays (such as those used by "git-add --interactive" and
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).
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).
11491150

11501151
color.interactive.<slot>::
11511152
Use customized color for 'git add --interactive' and 'git clean
@@ -1192,10 +1193,10 @@ color.ui::
11921193
configuration to set a default for the `--color` option. Set it
11931194
to `false` or `never` if you prefer Git commands not to use
11941195
color unless enabled explicitly with some other configuration
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`.
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.
11991200

12001201
column.ui::
12011202
Specify whether supported commands should output in columns.

builtin/branch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ static int git_branch_config(const char *var, const char *value, void *cb)
9393
return config_error_nonbool(var);
9494
return color_parse(value, branch_colors[slot]);
9595
}
96-
return git_default_config(var, value, cb);
96+
return git_color_default_config(var, value, cb);
9797
}
9898

9999
static const char *branch_get_color(enum color_branch ix)

builtin/clean.c

+2-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,8 @@ static int git_clean_config(const char *var, const char *value, void *cb)
126126
return 0;
127127
}
128128

129-
return git_default_config(var, value, cb);
129+
/* inspect the color.ui config variable and others */
130+
return git_color_default_config(var, value, cb);
130131
}
131132

132133
static const char *clean_get_color(enum color_clean ix)

builtin/grep.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ static int wait_all(void)
275275
static int grep_cmd_config(const char *var, const char *value, void *cb)
276276
{
277277
int st = grep_config(var, value, cb);
278-
if (git_default_config(var, value, cb) < 0)
278+
if (git_color_default_config(var, value, cb) < 0)
279279
st = -1;
280280

281281
if (!strcmp(var, "grep.threads")) {

builtin/show-branch.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb)
554554
return 0;
555555
}
556556

557-
return git_default_config(var, value, cb);
557+
return git_color_default_config(var, value, cb);
558558
}
559559

560560
static int omit_in_dense(struct commit *commit, struct commit **rev, int n)

builtin/tag.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ static int git_tag_config(const char *var, const char *value, void *cb)
158158

159159
if (starts_with(var, "column."))
160160
return git_column_config(var, value, "tag", &colopts);
161-
return git_default_config(var, value, cb);
161+
return git_color_default_config(var, value, cb);
162162
}
163163

164164
static void write_tag_body(int fd, const struct object_id *oid)

color.c

+9-1
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 var ? GIT_COLOR_AUTO : 1;
311+
return 1;
312312
if (!strcasecmp(value, "auto"))
313313
return GIT_COLOR_AUTO;
314314
}
@@ -368,6 +368,14 @@ int git_color_config(const char *var, const char *value, void *cb)
368368
return 0;
369369
}
370370

371+
int git_color_default_config(const char *var, const char *value, void *cb)
372+
{
373+
if (git_color_config(var, value, cb) < 0)
374+
return -1;
375+
376+
return git_default_config(var, value, cb);
377+
}
378+
371379
void color_print_strbuf(FILE *fp, const char *color, const struct strbuf *sb)
372380
{
373381
if (*color)

config.c

-4
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
#include "string-list.h"
1717
#include "utf8.h"
1818
#include "dir.h"
19-
#include "color.h"
2019

2120
struct config_source {
2221
struct config_source *prev;
@@ -1351,9 +1350,6 @@ int git_default_config(const char *var, const char *value, void *dummy)
13511350
if (starts_with(var, "advice."))
13521351
return git_default_advice_config(var, value);
13531352

1354-
if (git_color_config(var, value, dummy) < 0)
1355-
return -1;
1356-
13571353
if (!strcmp(var, "pager.color") || !strcmp(var, "color.pager")) {
13581354
pager_use_color = git_config_bool(var,value);
13591355
return 0;

diff.c

+3
Original file line numberDiff line numberDiff line change
@@ -358,6 +358,9 @@ int git_diff_ui_config(const char *var, const char *value, void *cb)
358358
return 0;
359359
}
360360

361+
if (git_color_config(var, value, cb) < 0)
362+
return -1;
363+
361364
return git_diff_basic_config(var, value, cb);
362365
}
363366

t/t6006-rev-list-format.sh

+15-5
Original file line numberDiff line numberDiff line change
@@ -208,11 +208,26 @@ do
208208
has_no_color actual
209209
'
210210

211+
test_expect_success "$desc enables colors for color.diff" '
212+
git -c color.diff=always log --format=$color -1 >actual &&
213+
has_color actual
214+
'
215+
216+
test_expect_success "$desc enables colors for color.ui" '
217+
git -c color.ui=always log --format=$color -1 >actual &&
218+
has_color actual
219+
'
220+
211221
test_expect_success "$desc respects --color" '
212222
git log --format=$color -1 --color >actual &&
213223
has_color actual
214224
'
215225

226+
test_expect_success "$desc respects --no-color" '
227+
git -c color.ui=always log --format=$color -1 --no-color >actual &&
228+
has_no_color actual
229+
'
230+
216231
test_expect_success TTY "$desc respects --color=auto (stdout is tty)" '
217232
test_terminal git log --format=$color -1 --color=auto >actual &&
218233
has_color actual
@@ -225,11 +240,6 @@ do
225240
has_no_color actual
226241
)
227242
'
228-
229-
test_expect_success TTY "$desc respects --no-color" '
230-
test_terminal git log --format=$color -1 --no-color >actual &&
231-
has_no_color actual
232-
'
233243
done
234244

235245
test_expect_success '%C(always,...) enables color even without tty' '

t/t6300-for-each-ref.sh

+5
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,11 @@ test_expect_success '--color can override tty check' '
442442
test_cmp expected.color actual
443443
'
444444

445+
test_expect_success 'color.ui=always does not override tty check' '
446+
git -c color.ui=always for-each-ref --format="$color_format" >actual &&
447+
test_cmp expected.bare actual
448+
'
449+
445450
cat >expected <<\EOF
446451
heads/master
447452
tags/master

t/t7004-tag.sh

+6
Original file line numberDiff line numberDiff line change
@@ -1918,6 +1918,12 @@ test_expect_success '--color overrides auto-color' '
19181918
test_cmp expect.color actual
19191919
'
19201920

1921+
test_expect_success 'color.ui=always overrides auto-color' '
1922+
git -c color.ui=always tag $color_args >actual.raw &&
1923+
test_decode_color <actual.raw >actual &&
1924+
test_cmp expect.color actual
1925+
'
1926+
19211927
test_expect_success 'setup --merged test tags' '
19221928
git tag mergetest-1 HEAD~2 &&
19231929
git tag mergetest-2 HEAD~1 &&

0 commit comments

Comments
 (0)