aboutsummaryrefslogtreecommitdiff
path: root/pretty.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2016-05-26 22:46:10 -0500
committerJunio C Hamano <gitster@pobox.com>2016-05-27 11:24:54 -0700
commitb15a3e005af07843116c73205742adfbab3d2e82 (patch)
treeac340c93c4cc06bf6ba73d0220f140d2f9f31240 /pretty.c
parent0f8e831356d4f1a34baf46bb1a6b2d4c89ec9cb8 (diff)
downloadgit-b15a3e005af07843116c73205742adfbab3d2e82.tar.gz
git-b15a3e005af07843116c73205742adfbab3d2e82.tar.xz
format_commit_message: honor `color=auto` for `%C(auto)`
git-log(1) documents that when specifying the `%C(auto)` format placeholder will "turn on auto coloring on the next %placeholders until the color is switched again." However, when `%C(auto)` is used, the present implementation will turn colors on unconditionally (even if the color configuration is turned off for the current context - for example, `--no-color` was specified or the color is `auto` and the output is not a tty). Update `format_commit_one` to examine the current context when a format string of `%C(auto)` is specified, which ensures that we will not unconditionally write colors. This brings that behavior in line with the behavior of `%C(auto,<colorname>)`, and allows the user the ability to specify that color should be displayed only when the output is a tty. Additionally, add a test for `%C(auto)` and update the existing tests for `%C(auto,...)` as they were misidentified as being applicable to `%C(auto)`. Tests from Jeff King. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Edward Thomson <ethomson@edwardthomson.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'pretty.c')
-rw-r--r--pretty.c2
1 files changed, 1 insertions, 1 deletions
diff --git a/pretty.c b/pretty.c
index 92b2870a7..3908e8f10 100644
--- a/pretty.c
+++ b/pretty.c
@@ -1061,7 +1061,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);