From bfa451fc4e621700883fb3b34600bdf71f515a62 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 26 Sep 2022 14:38:34 -0400 Subject: [PATCH] pass --git-dir when reading git config when it was specified explicitly MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- CHANGELOG | 2 ++ Git/Config.hs | 16 ++++++++++++---- Git/CurrentRepo.hs | 10 +++++----- 3 files changed, 19 insertions(+), 9 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 177e10e28b..0a4c8f300c 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -38,6 +38,8 @@ git-annex (10.20220823) UNRELEASED; urgency=medium * Run annex.freezecontent-command and annex.thawcontent-command when on a crippled filesystem. Thanks, Reiko Asakura + * Let GIT_DIR and --git-dir override git's protection against operating + in a repository owned by another user. -- Joey Hess Mon, 29 Aug 2022 15:03:04 -0400 diff --git a/Git/Config.hs b/Git/Config.hs index 7bf2793778..e788a2da55 100644 --- a/Git/Config.hs +++ b/Git/Config.hs @@ -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 diff --git a/Git/CurrentRepo.hs b/Git/CurrentRepo.hs index bd1ab5cd4b..3b607d7bab 100644 --- a/Git/CurrentRepo.hs +++ b/Git/CurrentRepo.hs @@ -79,11 +79,11 @@ get = do { gitdir = absd , worktree = Just curr } - r <- Git.Config.read $ newFrom loc - let r' = r { gitDirSpecifiedExplicitly = True } - return $ if Git.Config.isBare r' - then r' { location = (location r) { worktree = Nothing } } - else r' + r <- Git.Config.read $ (newFrom loc) + { gitDirSpecifiedExplicitly = True } + return $ if Git.Config.isBare r + then r { location = (location r) { worktree = Nothing } } + else r configure Nothing Nothing = giveup "Not in a git repository." addworktree w r = changelocation r $ Local