# git-daemon not consulting ~/.gitconfig

2 messages from 2024-12-04 to 2024-12-04. Participants: martin f krafft, Konstantin Khomoutov.
Thread: https://gitlist.dev/t/62597

## martin f krafft, 2024-12-04 10:23

Subject: git-daemon not consulting ~/.gitconfig
Message-ID: <fj5vgwmc5wtyzcxxnmcgw7whclm6qf7p5sxzh3nbao3feyutj6@daizbooxk22j>
URL: https://gitlist.dev/e/fj5vgwmc5wtyzcxxnmcgw7whclm6qf7p5sxzh3nbao3feyutj6%40daizbooxk22j

```
Hello,

I found that git-daemon stopped serving repositories managed by 
gitolite, i.e. by a different Unix user. Hence, no big surprise that 
I would get

ˋˋˋ
git-daemon[3126249]: detected dubious ownership in repository at '/srv/git/repositories/madduck/pub/etc/ssh.git'
                      To add an exception for this directory, call:
                      git config --global --add safe.directory /srv/git/repositories/madduck/pub/etc/ssh.git
ˋˋˋ

in the logs. However, adding the config to `~gitdaemon/.gitconfig` 
did not have the desired effect. Neither did adding it to 
`~root/.gitconfig` and only `/etc/gitconfig` works.

So I checked `strace` and found that when invoked by `git-daemon`, 
Git doesn't even consult `~/.gitconfig`, and I think this may be a 
bug.

Here is the relevant strace for an access to git-daemon that 
triggers the above
error:

ˋˋˋ
root@alan:~# strace -fp 3146653 -e file 2>&1 | grep config
[pid 3154713] access("/etc/gitconfig", R_OK) = 0
[pid 3154713] openat(AT_FDCWD, "/etc/gitconfig", O_RDONLY) = 3
[pid 3154713] access("/etc/gitconfig", R_OK) = 0
[pid 3154713] openat(AT_FDCWD, "/etc/gitconfig", O_RDONLY) = 4
[pid 3154713] openat(AT_FDCWD, "./config", O_RDONLY) = 4
[pid 3154713] access("/etc/gitconfig", R_OK) = 0
[pid 3154713] openat(AT_FDCWD, "/etc/gitconfig", O_RDONLY) = 4
[pid 3154713] access("config", R_OK)    = 0
[pid 3154713] openat(AT_FDCWD, "config", O_RDONLY) = 4
[pid 3154714] access("/etc/gitconfig", R_OK) = 0
[pid 3154714] openat(AT_FDCWD, "/etc/gitconfig", O_RDONLY) = 3
[pid 3154714] access("/etc/gitconfig", R_OK) = 0
[pid 3154714] openat(AT_FDCWD, "/etc/gitconfig", O_RDONLY) = 3
[pid 3154714] openat(AT_FDCWD, "./config", O_RDONLY) = 3
[pid 3154714] access("/etc/gitconfig", R_OK) = 0
[pid 3154714] openat(AT_FDCWD, "/etc/gitconfig", O_RDONLY) = 3
[pid 3154714] access("config", R_OK)    = 0
[pid 3154714] openat(AT_FDCWD, "config", O_RDONLY) = 3
ˋˋˋ

[System Info]
git version:
git version 2.39.5
cpu: x86_64
no commit associated with this build
sizeof-long: 8
sizeof-size_t: 8
shell-path: /bin/sh
uname: Linux 6.1.0-28-amd64 #1 SMP PREEMPT_DYNAMIC Debian 6.1.119-1 (2024-11-22) x86_64
compiler info: gnuc: 12.2
libc info: glibc: 2.36
$SHELL (typically, interactive shell): /bin/bash


-- 
martin krafft | https://matrix.to/#/#madduck:madduck.net
 
officer, arrest that man! he's whistling a copyrighted song.
{: .blockquote }
 
spamtraps: madduck.bogus@madduck.net
{: .hidden }


```

## Konstantin Khomoutov, 2024-12-04 15:57

Subject: Re: git-daemon not consulting ~/.gitconfig
Message-ID: <20241204155704.sxti6mn7zyr3vmyt@carbon>
URL: https://gitlist.dev/e/20241204155704.sxti6mn7zyr3vmyt%40carbon
In-Reply-To: <fj5vgwmc5wtyzcxxnmcgw7whclm6qf7p5sxzh3nbao3feyutj6@daizbooxk22j>

```
On Wed, Dec 04, 2024 at 11:23:36AM +0100, martin f krafft wrote:

[...]
> in the logs. However, adding the config to `~gitdaemon/.gitconfig` did not
> have the desired effect. Neither did adding it to `~root/.gitconfig` and
> only `/etc/gitconfig` works.
> 
> So I checked `strace` and found that when invoked by `git-daemon`, Git
> doesn't even consult `~/.gitconfig`, and I think this may be a bug.
[...]

Given the following passage from the docs, describing the "--user" option,

| Like many programs that switch user id, the daemon does not reset
| environment variables such as $HOME when it runs git programs, e.g.
| upload-pack and receive-pack. When using this option, you may also want to
| set and export HOME to point at the home directory of <user> before starting
| the daemon, and make sure any Git configuration files in that directory are
| readable by <user>.

the behavior does indeed look like a bug.


```
