Subject: Re: [PATCH 6/7] Git.pm: introduce environment variable GIT_TEST_PRETEND_TTY

From: Slavica Djukic <[email-masked]>
Date: Tue, 15 Jan 2019 13:45:50 +0100

Hi Phillip,

First of all, thank you for taking your time to review this patch series.

On 14-Jan-19 12:13 PM, Phillip Wood wrote:
> Hi Salvica/Johannes
>
> On 20/12/2018 12:09, Slavica Djukic via GitGitGadget wrote:
>> From: Slavica Djukic <[email-masked]>
>>
>> To enable testing the colored output on Windows, enable TTY
>> by using environment variable GIT_TEST_PRETEND_TTY.
>>
>> This is the original idea by Johannes Schindelin.
> I normally use GIT_PAGER_IN_USE=1 to force colored output, is there some
> reason that does not work here?

I tried that approach, and it turns out GIT_PAGER_IN_USE=1 does force 
colored output.

As for the changes suggested in the other two e-mails -- I will apply 
them as well and send re-roll.

Thank you,

Slavica

>
> Best Wishes
>
> Phillip
>
>> Signed-off-by: Slavica Djukic <[email-masked]>
>> ---
>>   color.c     | 4 ++++
>>   perl/Git.pm | 2 +-
>>   2 files changed, 5 insertions(+), 1 deletion(-)
>>
>> diff --git a/color.c b/color.c
>> index ebb222ec33..4aa6cc3442 100644
>> --- a/color.c
>> +++ b/color.c
>> @@ -323,6 +323,10 @@ static int check_auto_color(int fd)
>>   {
>>   	static int color_stderr_is_tty = -1;
>>   	int *is_tty_p = fd == 1 ? &color_stdout_is_tty : &color_stderr_is_tty;
>> +	
>> +	if (git_env_bool("GIT_TEST_PRETEND_TTY", 0))
>> +		return 1;
>> +
>>   	if (*is_tty_p < 0)
>>   		*is_tty_p = isatty(fd);
>>   	if (*is_tty_p || (fd == 1 && pager_in_use() && pager_use_color)) {
>> diff --git a/perl/Git.pm b/perl/Git.pm
>> index d856930b2e..51a1ce0617 100644
>> --- a/perl/Git.pm
>> +++ b/perl/Git.pm
>> @@ -757,7 +757,7 @@ and returns boolean (true for "use color", false for "do not use color").
>>   
>>   sub get_colorbool {
>>   	my ($self, $var) = @_;
>> -	my $stdout_to_tty = (-t STDOUT) ? "true" : "false";
>> +	my $stdout_to_tty = $ENV{GIT_TEST_PRETEND_TTY} || (-t STDOUT) ? "true" : "false";
>>   	my $use_color = $self->command_oneline('config', '--get-colorbool',
>>   					       $var, $stdout_to_tty);
>>   	return ($use_color eq 'true');
>>