# [PATCH] format_commit_message: honor `color=auto` for `%C(auto)`

3 messages from 2016-05-24 to 2016-05-25. Participants: Edward Thomson, Junio C Hamano.
Thread: https://gitlist.dev/t/42442

## Edward Thomson, 2016-05-24 19:48

Subject: [PATCH] format_commit_message: honor `color=auto` for `%C(auto)`
Message-ID: <20160524194814.GA12479@zoidberg>
URL: https://gitlist.dev/e/20160524194814.GA12479%40zoidberg

```
Check that we are configured to display colors in the given context when
the user specifies a format string of `%C(auto)`, instead of always
displaying the default color for the given context.  This makes
`%C(auto)` obey the `color=auto` setting and brings its behavior in line
with the behavior of `%C(auto,<colorname>)`.

This allows the user the ability to specify that color should be
displayed for a string only when the output is a tty, and to use the
default color for the given context without having to hardcode a
color value.
---
 pretty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/pretty.c b/pretty.c
index 87c4497..c3ec430 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1063,7 +1063,7 @@ static size_t format_commit_one(struct strbuf *sb, /* in UTF-8 */
 	switch (placeholder[0]) {
 	case 'C':
 		if (starts_with(placeholder + 1, "(auto)")) {
-			c->auto_color = 1;
+			c->auto_color = want_color(c->pretty_ctx->color);
 			return 7; /* consumed 7 bytes, "C(auto)" */
 		} else {
 			int ret = parse_color(sb, placeholder, c);
-- 
2.6.4 (Apple Git-63)

```

## Junio C Hamano, 2016-05-25 00:55

Subject: Re: [PATCH] format_commit_message: honor `color=auto` for `%C(auto)`
Message-ID: <CAPc5daV4Z0gvaOL1H-v-G7RepGyiuir_AnzNx32aM3j2pm0RGw@mail.gmail.com>
URL: https://gitlist.dev/e/CAPc5daV4Z0gvaOL1H-v-G7RepGyiuir_AnzNx32aM3j2pm0RGw%40mail.gmail.com
In-Reply-To: <20160524194814.GA12479@zoidberg>

```
On Tue, May 24, 2016 at 12:48 PM, Edward Thomson
<ethomson@edwardthomson.com> wrote:
> Check that we are configured to display colors in the given context when
> the user specifies a format string of `%C(auto)`, instead of always
> displaying the default color for the given context.  This makes
> `%C(auto)` obey the `color=auto` setting and brings its behavior in line
> with the behavior of `%C(auto,<colorname>)`.
>
> This allows the user the ability to specify that color should be
> displayed for a string only when the output is a tty, and to use the
> default color for the given context without having to hardcode a
> color value.
> ---
>  pretty.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)

Looks obviously the right thing to do from a cursory read.
Missing sign-off?

Thanks.

```

## Edward Thomson, 2016-05-25 01:26

Subject: Re: [PATCH] format_commit_message: honor `color=auto` for `%C(auto)`
Message-ID: <20160525012652.GA13168@zoidberg>
URL: https://gitlist.dev/e/20160525012652.GA13168%40zoidberg
In-Reply-To: <CAPc5daV4Z0gvaOL1H-v-G7RepGyiuir_AnzNx32aM3j2pm0RGw@mail.gmail.com>

```
On Tue, May 24, 2016 at 05:55:02PM -0700, Junio C Hamano wrote:
> Looks obviously the right thing to do from a cursory read.
> Missing sign-off?

Yes, apologies for the oversight; will re-send.

Thanks-
-ed

```
