# [PATCH] git-diff: don't use colors when stdout is not a tty.

2 messages from 2007-07-06 to 2007-07-06. Participants: Michel Marti, Matthias Lederhofer.
Thread: https://gitlist.dev/t/8898

## Michel Marti, 2007-07-06 15:35

Subject: [PATCH] git-diff: don't use colors when stdout is not a tty.
Message-ID: <468E612E.2070903@objectxp.com>
URL: https://gitlist.dev/e/468E612E.2070903%40objectxp.com

```
Currently, with diff-coloring enabled, git-diff outputs color escape
sequences even if stdout is redirected (not a tty). This is rather annoying
when trying to further process the output. This patch teaches the diff command
to only do its coloring stuff when a pager is in use or stdout is a tty.

Signed-off-by: Michel Marti <mma@objectxp.com>
---
 diff.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/diff.c b/diff.c
index 1958970..988e741 100644
--- a/diff.c
+++ b/diff.c
@@ -451,7 +451,7 @@ static void free_diff_words_data(struct emit_callback *ecbdata)

 const char *diff_get_color(int diff_use_color, enum color_diff ix)
 {
-       if (diff_use_color)
+       if (diff_use_color && (pager_in_use || isatty(STDOUT_FILENO)))
                return diff_colors[ix];
        return "";
 }
--
1.5.2.2

```

## Matthias Lederhofer, 2007-07-06 16:37

Subject: Re: [PATCH] git-diff: don't use colors when stdout is not a tty.
Message-ID: <20070706163759.GA26670@moooo.ath.cx>
URL: https://gitlist.dev/e/20070706163759.GA26670%40moooo.ath.cx
In-Reply-To: <468E612E.2070903@objectxp.com>

```
Michel Marti <mma@objectxp.com> wrote:
> Currently, with diff-coloring enabled, git-diff outputs color escape
> sequences even if stdout is redirected (not a tty). This is rather annoying
> when trying to further process the output. This patch teaches the diff command
> to only do its coloring stuff when a pager is in use or stdout is a tty.

Set color.diff to auto instead of true.

```
