From 0c88bf50502e2be7d7d8965052d77bbf08e1d519 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 3 Oct 2017 09:45:47 -0400 Subject: provide --color option for all ref-filter users When ref-filter learned about want_color() in 11b087adfd (ref-filter: consult want_color() before emitting colors, 2017-07-13), it became useful to be able to turn colors off and on for specific commands. For git-branch, you can do so with --color/--no-color. But for git-for-each-ref and git-tag, the other users of ref-filter, you have no option except to tweak the "color.ui" config setting. Let's give both of these commands the usual color command-line options. This is a bit more obvious as a method for overriding the config. And it also prepares us for the behavior of "always" changing (so that we are still left with a way of forcing color when our output goes to a non-terminal). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/git-for-each-ref.txt | 5 +++++ Documentation/git-tag.txt | 5 +++++ 2 files changed, 10 insertions(+) (limited to 'Documentation') diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt index cc42c12832..b92ebd0cd9 100644 --- a/Documentation/git-for-each-ref.txt +++ b/Documentation/git-for-each-ref.txt @@ -55,6 +55,11 @@ OPTIONS literally, in the latter case matching completely or from the beginning up to a slash. +--color[=]: + Respect any colors specified in the `--format` option. The + `` field must be one of `always`, `never`, or `auto` (if + `` is absent, behave as if `always` was given). + --shell:: --perl:: --python:: diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt index 1eb15afa1c..a1399a78a0 100644 --- a/Documentation/git-tag.txt +++ b/Documentation/git-tag.txt @@ -115,6 +115,11 @@ options for details. variable if it exists, or lexicographic order otherwise. See linkgit:git-config[1]. +--color[=]: + Respect any colors specified in the `--format` option. The + `` field must be one of `always`, `never`, or `auto` (if + `` is absent, behave as if `always` was given). + -i:: --ignore-case:: Sorting and filtering tags are case insensitive. -- cgit v1.2.3 From 6be4595edb8e5b616c6e8b9fbc78b0f831fa2a87 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 3 Oct 2017 09:46:06 -0400 Subject: color: make "always" the same as "auto" in config It can be handy to use `--color=always` (or it's synonym `--color`) on the command-line to convince a command to produce color even if it's stdout isn't going to the terminal or a pager. What's less clear is whether it makes sense to set config variables like color.ui to `always`. For a one-shot like: git -c color.ui=always ... it's potentially useful (especially if the command doesn't directly support the `--color` option). But setting `always` in your on-disk config is much muddier, as you may be surprised when piped commands generate colors (and send them to whatever is consuming the pipe downstream). Some people have done this anyway, because: 1. The documentation for color.ui makes it sound like using `always` is a good idea, when you almost certainly want `auto`. 2. Traditionally not every command (and especially not plumbing) respected color.ui in the first place. So the confusion came up less frequently than it might have. The situation changed in 136c8c8b8f (color: check color.ui in git_default_config(), 2017-07-13), which negated point (2): now scripts using only plumbing commands (like add-interactive) are broken by this setting. That commit was fixing real issues (e.g., by making `color.ui=never` work, since `auto` is the default), so we don't want to just revert it. We could turn `always` into a noop in plumbing commands, but that creates a hard-to-explain inconsistency between the plumbing and other commands. Instead, let's just turn `always` into `auto` for all config. This does break the "one-shot" config shown above, but again, we're probably better to have simple and consistent rules than to try to special-case command-line config. There is one place where `always` should retain its meaning: on the command line, `--color=always` should continue to be the same as `--color`, overriding any isatty checks. Since the command-line parser also depends on git_config_colorbool(), we can use the existence of the "var" string to deterine whether we are serving the command-line or the config. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/config.txt | 35 +++++++++++++++++------------------ 1 file changed, 17 insertions(+), 18 deletions(-) (limited to 'Documentation') diff --git a/Documentation/config.txt b/Documentation/config.txt index d5c9c4cab6..cb0f951ddc 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1052,10 +1052,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.:: Use customized color for branch coloration. `` is one of @@ -1066,12 +1066,11 @@ color.branch.:: 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 @@ -1124,12 +1123,12 @@ color.grep.:: -- 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.:: Use customized color for 'git add --interactive' and 'git clean @@ -1176,10 +1175,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. -- cgit v1.2.3 From 2c1acdf6c9f6668dc520e75709af8447587eb4d0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Fri, 13 Oct 2017 13:23:24 -0400 Subject: Revert "color: make "always" the same as "auto" in config" This reverts commit 6be4595edb8e5b616c6e8b9fbc78b0f831fa2a87. That commit weakened the "always" setting of color config so that it acted as "auto". This was meant to solve regressions in v2.14.2 in which setting "color.ui=always" in the on-disk config broke scripts like add--interactive, because the plumbing diff commands began to generate color output. This was due to 136c8c8b8f (color: check color.ui in git_default_config(), 2017-07-13), which was in turn trying to fix issues caused by 4c7f1819b3 (make color.ui default to 'auto', 2013-06-10). But in weakening "always", we created even more problems, as people expect to be able to use "git -c color.ui=always" to force color (especially because some commands don't have their own --color flag). We can fix that by special-casing the command-line "-c", but now things are getting pretty confusing. Instead of piling hacks upon hacks, let's start peeling off the hacks. The first step is dropping the weakening of "always", which this revert does. Note that we could actually revert the whole series merged in by da15b78e52642bd45fd5513ab0000fdf2e58a6f4. Most of that series consists of preparations to the tests to handle the weakening of "-c color.ui=always". But it's worth keeping for a few reasons: - there are some other preparatory cleanups, like e433749d86 (test-terminal: set TERM=vt100, 2017-10-03) - it adds "--color" options more consistently in 0c88bf5050 (provide --color option for all ref-filter users, 2017-10-03) - some of the cases dropping "-c" end up being more robust and realistic tests, as in 01c94e9001 (t7508: use test_terminal for color output, 2017-10-03) - the preferred tool for overriding config is "--color", and we should be modeling that consistently We can individually revert the few commits necessary to restore some useful tests (which will be done on top of this patch). Note that this isn't a pure revert; we'll keep the test added in t3701, but mark it as failure for now. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- Documentation/config.txt | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'Documentation') diff --git a/Documentation/config.txt b/Documentation/config.txt index 517ee48ba6..2271809d90 100644 --- a/Documentation/config.txt +++ b/Documentation/config.txt @@ -1052,10 +1052,10 @@ clean.requireForce:: color.branch:: A boolean to enable/disable color in the output of - 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). + 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). color.branch.:: Use customized color for branch coloration. `` is one of @@ -1066,11 +1066,12 @@ color.branch.:: color.diff:: Whether to use ANSI escape sequences to add color to patches. - If this is set to `true` or `auto`, linkgit:git-diff[1], + If this is set to `always`, linkgit:git-diff[1], linkgit:git-log[1], and linkgit:git-show[1] will use color - 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). + 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). + This does not affect linkgit:git-format-patch[1] or the 'git-diff-{asterisk}' plumbing commands. Can be overridden on the @@ -1123,12 +1124,12 @@ color.grep.:: -- color.interactive:: - When set to `true` or `auto`, use colors for interactive prompts + When set to `always`, always use colors for interactive prompts and displays (such as those used by "git-add --interactive" and - "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). + "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). color.interactive.:: Use customized color for 'git add --interactive' and 'git clean @@ -1175,10 +1176,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 `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`. + 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. column.ui:: Specify whether supported commands should output in columns. -- cgit v1.2.3