]> git.ipfire.org Git - thirdparty/git.git/commitdiff
provide --color option for all ref-filter users
authorJeff King <peff@peff.net>
Tue, 3 Oct 2017 13:45:47 +0000 (09:45 -0400)
committerJunio C Hamano <gitster@pobox.com>
Wed, 4 Oct 2017 02:35:29 +0000 (11:35 +0900)
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>
Documentation/git-for-each-ref.txt
Documentation/git-tag.txt
builtin/for-each-ref.c
builtin/tag.c
t/t6300-for-each-ref.sh
t/t7004-tag.sh

index cc42c128323d32bd1a9bf47688722321857a5d65..b92ebd0cd9820da235967cab937a3ff31d02a187 100644 (file)
@@ -55,6 +55,11 @@ OPTIONS
        literally, in the latter case matching completely or from the
        beginning up to a slash.
 
+--color[=<when>]:
+       Respect any colors specified in the `--format` option. The
+       `<when>` field must be one of `always`, `never`, or `auto` (if
+       `<when>` is absent, behave as if `always` was given).
+
 --shell::
 --perl::
 --python::
index 1eb15afa1ce8a533d65c5f5ace0bcd694d7f6ffd..a1399a78a0694545ca1d9ce2e7f787717c2e1b09 100644 (file)
@@ -115,6 +115,11 @@ options for details.
        variable if it exists, or lexicographic order otherwise. See
        linkgit:git-config[1].
 
+--color[=<when>]:
+       Respect any colors specified in the `--format` option. The
+       `<when>` field must be one of `always`, `never`, or `auto` (if
+       `<when>` is absent, behave as if `always` was given).
+
 -i::
 --ignore-case::
        Sorting and filtering tags are case insensitive.
index 5d7c921a773718d6bee7f85b8d868fc22602377d..e931be9ce4d9f180de23d09d227e5a2f571f4f1a 100644 (file)
@@ -36,6 +36,7 @@ int cmd_for_each_ref(int argc, const char **argv, const char *prefix)
                OPT_GROUP(""),
                OPT_INTEGER( 0 , "count", &maxcount, N_("show only <n> matched refs")),
                OPT_STRING(  0 , "format", &format.format, N_("format"), N_("format to use for the output")),
+               OPT__COLOR(&format.use_color, N_("respect format colors")),
                OPT_CALLBACK(0 , "sort", sorting_tail, N_("key"),
                            N_("field name to sort on"), &parse_opt_ref_sorting),
                OPT_CALLBACK(0, "points-at", &filter.points_at,
index 66e35b823b6e0a3e732fb84e402dd0af6830a471..b9d1a13af57ad8ad84ecafb86bac8c03901463c3 100644 (file)
@@ -411,6 +411,7 @@ int cmd_tag(int argc, const char **argv, const char *prefix)
                },
                OPT_STRING(  0 , "format", &format.format, N_("format"),
                           N_("format to use for the output")),
+               OPT__COLOR(&format.use_color, N_("respect format colors")),
                OPT_BOOL('i', "ignore-case", &icase, N_("sorting and filtering are case insensitive")),
                OPT_END()
        };
index d6bffe627347e34c012b2c996b3dd7a8573b6705..6358134805302583a49f5102c225b643497637de 100755 (executable)
@@ -435,8 +435,8 @@ test_expect_success '%(color) does not show color without tty' '
        test_cmp expected.bare actual
 '
 
-test_expect_success 'color.ui=always can override tty check' '
-       git -c color.ui=always for-each-ref --format="$color_format" >actual.raw &&
+test_expect_success '--color can override tty check' '
+       git for-each-ref --color --format="$color_format" >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expected.color actual
 '
index 6dc44478f9afd30939959371d79f5aaf620c5a55..f5547371a360bf819e3a5f29973bd7a2896f62f6 100755 (executable)
@@ -1919,8 +1919,8 @@ test_expect_success TTY '%(color) present with tty' '
        test_cmp expect.color actual
 '
 
-test_expect_success 'color.ui=always overrides auto-color' '
-       git -c color.ui=always tag $color_args >actual.raw &&
+test_expect_success '--color overrides auto-color' '
+       git tag --color $color_args >actual.raw &&
        test_decode_color <actual.raw >actual &&
        test_cmp expect.color actual
 '