Skip Menu |

This queue is for tickets about the Git-Repository CPAN distribution.

Report information
The Basics
Id: 124711
Status: resolved
Priority: 0/
Queue: Git-Repository

People
Owner: Nobody in particular
Requestors: gustavo [...] gnustavo.com
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Why git-config --get-colorbool gives different results when invoked via Git::Repository?
Date: Wed, 7 Mar 2018 11:21:40 -0300
To: bug-Git-Repository [...] rt.cpan.org
From: Gustavo Chaves <gustavo [...] gnustavo.com>
Hi there! I'm using Git::Repository as a Git wrapper for my Git::Hooks module. Currently I'm trying to support colorized output and for that I have to invoke the command "git config --get-colorbool". But I'm getting different results between when I shell out Git directly and when I invoke it via Git::Repository. My testing environment is the following: - Ubuntu Linux 16.04.4 - Perl 5.26.0, installed with plenv. - Git 2.16.2 The following script shows the problem when I run it inside a Git repository: ========================================== $ cat colorbool.pl #!/usr/bin/env perl use 5.010; use Git::Repository; say 'CONFIG:'; say qx{git config -l | grep color}; say 'githooks.color:'; say qx{git config --get-colorbool githooks.color true}; say 'run githooks.color:'; my $git = Git::Repository->new(); say $git->run(qw/config --get-colorbool githooks.color true/); ========================================== $ ./colorbool.pl CONFIG: color.ui=auto githooks.color=true githooks.color: true run githooks.color: false ========================================== Note that the githooks.color configuration option is set to true. When I shell out Git directly it prints "true". But when I invoke the same command via Git::Repository::run it prints "false". I straced this script and noticed that the different invocations look up the configuration files differently, but this shouldn't have any effect, because the option githooks.color is set in the repository level. The shell out Git does this just before printing "true": 23264 open(".git/config", O_RDONLY) = 3 23264 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 23264 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 23264 read(3, "; -*- mode: conf -*-\n\n[githooks]"..., 4096) = 400 23264 read(3, "", 4096) = 0 23264 close(3) = 0 23264 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 23264 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 23264 write(1, "true\n", 5) = 5 And the Git invoked by Git::Repository does this: 23272 open("/home/gustavo/tmp/git/x/.git/config", O_RDONLY) = 3 23272 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 23272 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 23272 read(3, "; -*- mode: conf -*-\n\n[githooks]"..., 4096) = 400 23272 read(3, "", 4096) = 0 23272 close(3) = 0 23272 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 23272 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 23272 write(1, "false\n", 6 <unfinished ...> I'm stuck here. Can you help me? Thanks! -- Gustavo.
Subject: Re: [rt.cpan.org #124711] AutoReply: Why git-config --get-colorbool gives different results when invoked via Git::Repository?
Date: Wed, 7 Mar 2018 11:47:45 -0300
To: bug-Git-Repository [...] rt.cpan.org
From: Gustavo Chaves <gustavo [...] gnustavo.com>
Hi. It took me a few more minutes to figure it out. I'm setting githooks.color to 'true' which is the same as 'auto' for these colorbool options. In git, the "check_auto_color" function in color.c (https://github.com/git/git/blob/master/color.c) invokes the "is_terminal_dumb" function in editor.c (https://github.com/git/git/blob/master/editor.c) which returns true if the environment variable TERM is not set. The problem is that the Git::Repostory::Command::new constructor explicitly deletes the TERM environment variable like this: # turn us into a dumb terminal delete $ENV{TERM}; I suppose there's a reason for this. But if so, I don't know if I can invoke 'git config --get-colorbool' via Git::Repository and I'll have to shell out just this Git invocation. Do you see any other way around this? Thanks! 2018-03-07 11:22 GMT-03:00 Bugs in Git-Repository via RT <bug-Git-Repository@rt.cpan.org>: Show quoted text
> > Greetings, > > This message has been automatically generated in response to the > creation of a trouble ticket regarding: > "Why git-config --get-colorbool gives different results when invoked via Git::Repository?", > a summary of which appears below. > > There is no need to reply to this message right now. Your ticket has been > assigned an ID of [rt.cpan.org #124711]. Your ticket is accessible > on the web at: > > https://rt.cpan.org/Ticket/Display.html?id=124711 > > Please include the string: > > [rt.cpan.org #124711] > > in the subject line of all future correspondence about this issue. To do so, > you may reply to this message. > > Thank you, > bug-Git-Repository@rt.cpan.org > > ------------------------------------------------------------------------- > Hi there! I'm using Git::Repository as a Git wrapper for my Git::Hooks > module. Currently I'm trying to support colorized output and for that > I have to invoke the command "git config --get-colorbool". But I'm > getting different results between when I shell out Git directly and > when I invoke it via Git::Repository. > > My testing environment is the following: > - Ubuntu Linux 16.04.4 > - Perl 5.26.0, installed with plenv. > - Git 2.16.2 > > The following script shows the problem when I run it inside a Git repository: > > ========================================== > $ cat colorbool.pl > #!/usr/bin/env perl > > use 5.010; > use Git::Repository; > > say 'CONFIG:'; > say qx{git config -l | grep color}; > > say 'githooks.color:'; > say qx{git config --get-colorbool githooks.color true}; > > say 'run githooks.color:'; > my $git = Git::Repository->new(); > say $git->run(qw/config --get-colorbool githooks.color true/); > ========================================== > $ ./colorbool.pl > CONFIG: > color.ui=auto > githooks.color=true > > githooks.color: > true > > run githooks.color: > false > ========================================== > > Note that the githooks.color configuration option is set to true. > > When I shell out Git directly it prints "true". > > But when I invoke the same command via Git::Repository::run it prints "false". > > I straced this script and noticed that the different invocations look > up the configuration files differently, but this shouldn't have any > effect, because the option githooks.color is set in the repository > level. > > The shell out Git does this just before printing "true": > > 23264 open(".git/config", O_RDONLY) = 3 > 23264 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 > 23264 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 > 23264 read(3, "; -*- mode: conf -*-\n\n[githooks]"..., 4096) = 400 > 23264 read(3, "", 4096) = 0 > 23264 close(3) = 0 > 23264 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 > 23264 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 > 23264 write(1, "true\n", 5) = 5 > > And the Git invoked by Git::Repository does this: > > 23272 open("/home/gustavo/tmp/git/x/.git/config", O_RDONLY) = 3 > 23272 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 > 23272 fstat(3, {st_mode=S_IFREG|0664, st_size=400, ...}) = 0 > 23272 read(3, "; -*- mode: conf -*-\n\n[githooks]"..., 4096) = 400 > 23272 read(3, "", 4096) = 0 > 23272 close(3) = 0 > 23272 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 > 23272 fstat(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0 > 23272 write(1, "false\n", 6 <unfinished ...> > > I'm stuck here. Can you help me? > > Thanks! > > -- > Gustavo.
-- Gustavo.
On Wed Mar 07 09:48:18 2018, gustavo@gnustavo.com wrote: Show quoted text
> Hi. It took me a few more minutes to figure it out. > > I'm setting githooks.color to 'true' which is the same as 'auto' for > these colorbool options. In git, the "check_auto_color" function in > color.c (https://github.com/git/git/blob/master/color.c) invokes the > "is_terminal_dumb" function in editor.c > (https://github.com/git/git/blob/master/editor.c) which returns true > if the environment variable TERM is not set. > > The problem is that the Git::Repostory::Command::new constructor > explicitly deletes the TERM environment variable like this: > > # turn us into a dumb terminal > delete $ENV{TERM};
This was introduced a long time ago: https://github.com/book/Git-Repository/commit/4767c139a5321a88e55d06ff0219499d4e318b6b Show quoted text
> I suppose there's a reason for this. But if so, I don't know if I can > invoke 'git config --get-colorbool' via Git::Repository and I'll have > to shell out just this Git invocation.
The goal was to avoid having colors in the output as much as possible (i.e. one would need to specifically configure git for that to happen). This probably also predates the colorbool option. Show quoted text
> Do you see any other way around this?
Since Git::Repository::Command has been deleting TERM for the past 8 years, it's definitely not going to go back. :-) Git::Repository::Command is a subclass of System::Command, which supports the 'env' option, by which you can pass variables to override the environment in which the command in run. So my suggestion would be to run this command instead: say $git->run(qw/config --get-colorbool githooks.color true/, { env => { TERM => $ENV{TERM} } ); See also: https://metacpan.org/pod/distribution/Git-Repository/lib/Git/Repository/Tutorial.pod#Change-the-environment-of-a-command I should probably add some more details there about what's happening with the environment. -- BooK
Subject: Re: [rt.cpan.org #124711] Why git-config --get-colorbool gives different results when invoked via Git::Repository?
Date: Wed, 7 Mar 2018 16:27:54 -0300
To: bug-Git-Repository [...] rt.cpan.org
From: Gustavo Chaves <gustavo [...] gnustavo.com>
2018-03-07 13:20 GMT-03:00 Philippe Bruhat (BooK) via RT <bug-Git-Repository@rt.cpan.org>: Show quoted text
> Git::Repository::Command is a subclass of System::Command, which > supports the 'env' option, by which you can pass variables to override > the environment in which the command in run. > > So my suggestion would be to run this command instead: > > say $git->run(qw/config --get-colorbool githooks.color true/, { env => { TERM => $ENV{TERM} } );
Great! This solves the problem for me. Thank you very much! -- Gustavo.