git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 11/12] provide --color option for all ref-filter users

From
Jeff King <peff@peff.net>
Date
Oct 3, 2017, 13:45 UTC
Message-ID
<20171003134547.c6o6kmwqhpk2eyq7@sigill.intra.peff.net>
In-Reply-To
<20171003133713.ccxv6clrmuuhhc3u@sigill.intra.peff.net>

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>
---
 Documentation/git-for-each-ref.txt | 5 +++++
 Documentation/git-tag.txt          | 5 +++++
 builtin/for-each-ref.c             | 1 +
 builtin/tag.c                      | 1 +
 t/t6300-for-each-ref.sh            | 4 ++--
 t/t7004-tag.sh                     | 4 ++--
 6 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/Documentation/git-for-each-ref.txt b/Documentation/git-for-each-ref.txt
index 66b4e0a405..cbd0a6212a 100644
--- a/Documentation/git-for-each-ref.txt
+++ b/Documentation/git-for-each-ref.txt
@@ -57,6 +57,11 @@ OPTIONS
 	`xx`; for example `%00` interpolates to `\0` (NUL),
 	`%09` to `\t` (TAB) and `%0a` to `\n` (LF).
 
+--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::
diff --git a/Documentation/git-tag.txt b/Documentation/git-tag.txt
index 95e9f391d8..956fc019f9 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[=<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.
diff --git a/builtin/for-each-ref.c b/builtin/for-each-ref.c
index 5d7c921a77..e931be9ce4 100644
--- a/builtin/for-each-ref.c
+++ b/builtin/for-each-ref.c
@@ -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,
diff --git a/builtin/tag.c b/builtin/tag.c
index c627794181..12dbbc56d9 100644
--- a/builtin/tag.c
+++ b/builtin/tag.c
@@ -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()
 	};
diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh
index d6bffe6273..6358134805 100755
--- a/t/t6300-for-each-ref.sh
+++ b/t/t6300-for-each-ref.sh
@@ -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
 '
diff --git a/t/t7004-tag.sh b/t/t7004-tag.sh
index 0a86f8ea39..4e62c505fc 100755
--- a/t/t7004-tag.sh
+++ b/t/t7004-tag.sh
@@ -1912,8 +1912,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
 '
-- 
2.14.2.1079.gce6b466188
Previous: Jeff KingNext: Jeff King
Message 34 of 42 in “Updated to v2.14.2 on macOS; git add --patch broken”
  1. Toni UebernickelSep 27, 2017
  2. Jeff KingSep 27, 2017
  3. Toni UebernickelSep 27, 2017
  4. Jeff KingSep 27, 2017
  5. Jonathan NiederSep 27, 2017
  6. Jonathan NiederSep 27, 2017
  7. Toni UebernickelSep 28, 2017
  8. Jeff KingSep 28, 2017
  9. Toni UebernickelSep 28, 2017
  10. Jonathan NiederOct 2, 2017
  11. Junio C HamanoOct 3, 2017
  12. Junio C HamanoOct 3, 2017
  13. Junio C HamanoOct 3, 2017
  14. Jeff KingOct 3, 2017
  15. Junio C HamanoOct 3, 2017
  16. Jeff KingOct 3, 2017
  17. Junio C HamanoOct 3, 2017
  18. Jeff KingOct 3, 2017
  19. Junio C HamanoOct 3, 2017
  20. Jeff KingOct 3, 2017
  21. Tsvi MostoviczOct 3, 2017
  22. Junio C HamanoOct 3, 2017
  23. Jeff KingOct 3, 2017
  24. 01/12 test-terminal: set TERM=vt100Jeff King, Oct 3, 2017
  25. 02/12 t4015: prefer --color to -c color.diff=alwaysJeff King, Oct 3, 2017
  26. 03/12 t4015: use --color with --color-movedJeff King, Oct 3, 2017
  27. 04/12 t3701: use test-terminal to collect color outputJeff King, Oct 3, 2017
  28. 05/12 t7508: use test_terminal for color outputJeff King, Oct 3, 2017
  29. 06/12 t7502: use diff.noprefix for --verbose testJeff King, Oct 3, 2017
  30. 07/12 t6006: drop "always" color config testsJeff King, Oct 3, 2017
  31. 08/12 t3203: drop "always" color testJeff King, Oct 3, 2017
  32. 09/12 t7301: use test_terminal to check colorJeff King, Oct 3, 2017
  33. 10/12 t3205: use --color instead of color.branch=alwaysJeff King, Oct 3, 2017
  34. 11/12 provide --color option for all ref-filter usersJeff King, Oct 3, 2017
  35. 12/12 color: make "always" the same as "auto" in configJeff King, Oct 3, 2017
  36. Junio C HamanoOct 4, 2017
  37. Jeff KingOct 5, 2017
  38. Jan PrachařOct 20, 2017
  39. Jeff KingOct 3, 2017
  40. 0/2 fixing "add -p" regressionJunio C Hamano, Oct 3, 2017
  41. 1/2 Revert "color: check color.ui in git_default_config()"Junio C Hamano, Oct 3, 2017
  42. 2/2 colors: git_default_config() does not read color.uiJunio C Hamano, Oct 3, 2017

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.