pass --git-dir when reading git config when it was specified explicitly

Let GIT_DIR and --git-dir override git's protection against operating in a
repository owned by another user.

This is the same behavior other git commands have.

Sponsored-by: Jarkko Kniivilä on Patreon
This commit is contained in:
Joey Hess 2022-09-26 14:38:34 -04:00
parent 1d47a7e7e6
commit bfa451fc4e
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 19 additions and 9 deletions

View file

@ -57,12 +57,20 @@ reRead r = read' $ r
read' :: Repo -> IO Repo
read' repo = go repo
where
go Repo { location = Local { gitdir = d } } = git_config d
go Repo { location = LocalUnknown d } = git_config d
go Repo { location = Local { gitdir = d } } = git_config True d
go Repo { location = LocalUnknown d } = git_config False d
go _ = assertLocal repo $ error "internal"
git_config d = withCreateProcess p (git_config' p)
git_config isgitdir d = withCreateProcess p (git_config' p)
where
params = ["config", "--null", "--list"]
params =
-- Passing --git-dir changes git's behavior
-- when run in a repository belonging to another
-- user. When a gitdir is known, pass that in order
-- to get the local git config.
(if isgitdir && gitDirSpecifiedExplicitly repo
then ["--git-dir=."]
else [])
++ ["config", "--null", "--list"]
p = (proc "git" params)
{ cwd = Just (fromRawFilePath d)
, env = gitEnv repo