Git development
 help / color / mirror / Atom feed
From: Jeff King <peff@peff.net>
To: Nikolaus Rath <nikolaus@quadrature.ai>
Cc: git@vger.kernel.org
Subject: Re: 'safe.directory' setting ignored for some operations?
Date: Thu, 10 Apr 2025 17:35:42 -0400	[thread overview]
Message-ID: <20250410213542.GA3168175@coredump.intra.peff.net> (raw)
In-Reply-To: <CAPzgaL1NH_GofMko6f2Auz4e1TjTJNH0w4-ph8np04QRfT_R7A@mail.gmail.com>

On Thu, Apr 10, 2025 at 02:21:01PM +0100, Nikolaus Rath wrote:

> It seems to me that the 'safe.directory = *' option is ignored for
> some operations:
> 
> ---snip--
> $ git --version
> git version 2.43.0
> 
> $ git config --get-all --show-scope safe.directory
> command *

You're getting "command" here, but I don't see any "-c". Presumably
you're setting GIT_CONFIG_* in the environment yourself?

> $ git status -v --untracked=all --ignored
> HEAD detached at e116555
> [...]
> nothing to commit, working tree clean

You don't show us the repo here, but presumably this is one you don't
own, and the config is working as expected to allow the operation to
proceed.

> $ git clone -v --no-checkout --
> /builds/coreinfra/grafana_terraform/.git
> /builds/coreinfra/grafana_terraform/tmpus18hzbs
> Cloning into '/builds/coreinfra/grafana_terraform/tmpus18hzbs'...
> fatal: detected dubious ownership in repository at
> '/builds/coreinfra/grafana_terraform/.git'
> To add an exception for this directory, call:
> 
> git config --global --add safe.directory
> /builds/coreinfra/grafana_terraform/.git
> fatal: Could not read from remote repository.
> 
> Please make sure you have the correct access rights
> and the repository exists.

Here you are running afoul of the environment-clearing that happens when
Git internally "switches" to another repo. The "clone" command is run in
your newly-made repo (which is "safe"), but it would then run
"git-upload-pack" in the remote repo to act as the server side. We clear
out many Git-related environment variables when switching between
variables, including GIT_CONFIG_*.

  Side note: clearing out the config has been a subject of debate over
  the years, but one of the main reasons we do it is to be consistent
  with non-local transports, which do not pass environment variables at
  all. Which is good for some config, but can be annoying for others, as
  seen here.

So I think things are working as intended. You can get around it with
either of these:

  - set the config in your user ~/.gitconfig, which will be read by the
    child upload-pack command

  - tell clone to pass the config to upload-pack, like:

     git clone -u 'git -c safe.directory="*" upload-pack' ...

-Peff

  reply	other threads:[~2025-04-10 21:35 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <CAPzgaL2Q4v0LMSek=osugTDCDww9D-Tg+tDsFhFvRSVXFR8g6Q@mail.gmail.com>
2025-04-10 13:21 ` 'safe.directory' setting ignored for some operations? Nikolaus Rath
2025-04-10 21:35   ` Jeff King [this message]
2025-04-10 22:13     ` brian m. carlson
2025-04-10 22:42       ` Jeff King
2025-04-11  0:47         ` brian m. carlson
2025-04-11  8:17     ` Nikolaus Rath

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250410213542.GA3168175@coredump.intra.peff.net \
    --to=peff@peff.net \
    --cc=git@vger.kernel.org \
    --cc=nikolaus@quadrature.ai \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox