Re: Git --file doesn't override $HOME in version 1.8.1.2

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

Re: Git --file doesn't override $HOME in version 1.8.1.2

From: Thomas Rast <hidden>
Date: 2016-06-15 22:58:03

Sarajärvi Tony [off-list ref] writes:
Using Ubuntu 13.04 with Git 1.8.1.2 I stumbled upon a problem using Puppet.

In Puppet we launch Git with the command: '/usr/bin/git config --file
/home/qt/.gitconfig --get "user.name" "Qt Continuous Integration
System"'
However, puppet logs: "fatal: unable to access '/root/.config/git/config': Permission denied".

Puppet is run as root, so HOME points to /root, but still -file should override the environment variable.

If the same command is run directly from terminal as root, it works as well.
To elaborate (I briefly talked to Sarajärvi on IRC): this isn't about
the fatal error; we downgraded this to a nonfatal error in 4698c8f
(config: allow inaccessible configuration under $HOME, 2013-04-12).

Rather, it's very strange that 'git config --file foo' tries to look at
any config file other than 'foo'.  In a git repo:

  $ strace git config --file fooconfig test.var 2>&1 | grep 'open.*config'
  open("/home/thomas/.gitconfig", O_RDONLY) = 3
  open(".git/config", O_RDONLY)           = 3
  open("/home/thomas/.gitconfig", O_RDONLY) = 3
  open(".git/config", O_RDONLY)           = 3
  open("fooconfig", O_RDONLY)             = 3

I haven't looked into the code yet.  Probably it's simply following the
usual code paths to discover a repo and read its config.  However, with
the --file option, it shouldn't.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

Re: Git --file doesn't override $HOME in version 1.8.1.2

From: Jeff King <hidden>
Date: 2016-06-15 22:58:03

On Tue, Jul 09, 2013 at 01:49:21PM +0200, Thomas Rast wrote:
Rather, it's very strange that 'git config --file foo' tries to look at
any config file other than 'foo'.  In a git repo:

  $ strace git config --file fooconfig test.var 2>&1 | grep 'open.*config'
  open("/home/thomas/.gitconfig", O_RDONLY) = 3
  open(".git/config", O_RDONLY)           = 3
  open("/home/thomas/.gitconfig", O_RDONLY) = 3
  open(".git/config", O_RDONLY)           = 3
  open("fooconfig", O_RDONLY)             = 3

I haven't looked into the code yet.  Probably it's simply following the
usual code paths to discover a repo and read its config.  However, with
the --file option, it shouldn't.
I'm not so sure. It is (in theory) OK to read the usual config files to
find out _how_ git-config should behave, but then return results from a
specific file. The former should read the "normal" files, and the latter
should read whatever is specified by the options ("--file", a specific
level like "--global", or the usual set of files).

There are probably not many config options that can affect git-config's
behavior. The few I can think of are:

  1. core.editor should affect "git config --edit"

  2. pager.config would auto-start a pager. I am not sure if that is a
     sane thing to do or not.

  3. In theory you could have advice.* affect git-config, but I do not
     think any currently do.

  4. Currently git-config does not read objects, but there are patches
     proposed to do so. In that case, things like core.packedGitWindowSize
     might be important.

So I think you could probably drop the config parsing, special-case (1),
and ignore (2) as silly. But I think (3) and (4) show that it isn't the
right thing to do; you will never know which config options affect
git-config's behavior in the future.

The real issue here is not the "extra" normal config parsing; it is that
the normal parsing does not work in some cases. And that has already
been fixed by Jonathan's 4698c8f (config: allow inaccessible
configuration under $HOME, 2013-04-12).

-Peff
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help