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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 3, 2017 at 09:45 UTC 0c88bf50502e2be7d7d8965052d77bbf08e1d519
6 files changed +16 -4
Documentation/git-for-each-ref.txt
+5
@@ -55,6 +55,11 @@ OPTIONS
55 literally, in the latter case matching completely or from the
56 beginning up to a slash.
57
58 +--color[=<when>]:
59 + Respect any colors specified in the `--format` option. The
60 + `<when>` field must be one of `always`, `never`, or `auto` (if
61 + `<when>` is absent, behave as if `always` was given).
62 +
63 --shell::
64 --perl::
65 --python::
Documentation/git-tag.txt
+5
@@ -115,6 +115,11 @@ options for details.
115 variable if it exists, or lexicographic order otherwise. See
116 linkgit:git-config[1].
117
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 +
123 -i::
124 --ignore-case::
125 Sorting and filtering tags are case insensitive.
builtin/for-each-ref.c
+1
@@ -36,6 +36,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
36 OPT_GROUP(""),
37 OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
38 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")),
40 OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
41 N_("field name to sort on"), &parse_opt_ref_sorting),
42 OPT_CALLBACK(0, "points-at", &filter.points_at,
builtin/tag.c
+1
@@ -411,6 +411,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
411 },
412 OPT_STRING( 0 , "format", &format.format, N_("format"),
413 N_("format to use for the output")),
414 + OPT__COLOR(&format.use_color, N_("respect format colors")),
415 OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
416 OPT_END()
417 };
t/t6300-for-each-ref.sh
+2 -2
@@ -435,8 +435,8 @@ test_expect_success '%(color) does not show color without tty' '
435 test_cmp expected.bare actual
436 '
437
438 -test_expect_success 'color.ui=always can override tty check' '
439 - git -c color.ui=always for-each-ref --format="$color_format" >actual.raw &&
438 +test_expect_success '--color can override tty check' '
439 + git for-each-ref --color --format="$color_format" >actual.raw &&
440 test_decode_color <actual.raw >actual &&
441 test_cmp expected.color actual
442 '
t/t7004-tag.sh
+2 -2
@@ -1919,8 +1919,8 @@ test_expect_success TTY '%(color) present with tty' '
1919 test_cmp expect.color actual
1920 '
1921
1922 -test_expect_success 'color.ui=always overrides auto-color' '
1923 - git -c color.ui=always tag $color_args >actual.raw &&
1922 +test_expect_success '--color overrides auto-color' '
1923 + git tag --color $color_args >actual.raw &&
1924 test_decode_color <actual.raw >actual &&
1925 test_cmp expect.color actual
1926 '