Skip to content

Commit 0c88bf5

Browse files
peffgitster
authored andcommitted
provide --color option for all ref-filter users
When ref-filter learned about want_color() in 11b087a (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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8126b12 commit 0c88bf5

File tree

6 files changed

+16
-4
lines changed

6 files changed

+16
-4
lines changed

Documentation/git-for-each-ref.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ OPTIONS
5555
literally, in the latter case matching completely or from the
5656
beginning up to a slash.
5757

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+
5863
--shell::
5964
--perl::
6065
--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
};

t/t6300-for-each-ref.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ test_expect_success '%(color) does not show color without tty' '
435435
test_cmp expected.bare actual
436436
'
437437

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 &&
440440
test_decode_color <actual.raw >actual &&
441441
test_cmp expected.color actual
442442
'

t/t7004-tag.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,8 +1919,8 @@ test_expect_success TTY '%(color) present with tty' '
19191919
test_cmp expect.color actual
19201920
'
19211921

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 &&
19241924
test_decode_color <actual.raw >actual &&
19251925
test_cmp expect.color actual
19261926
'

0 commit comments

Comments
 (0)