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.