Avoid Git.Config.updateLocation adding "/.git" to the end of the repo
path to a bare repo when git config is not allowed to list the configs due to the CVE-2022-24765 fix. That resulted in a confusing error message, and prevented the nice message that explains how to mark the repo as safe to use. Made isBare a tristate so that the case where core.bare is not returned can be handled. The handling in updateLocation is to check if the directory contains config and objects and if so assume it's bare. Note that if that heuristic is somehow wrong, it would construct a repo that thinks it's bare but is not. That could cause follow-on problems, but since git-annex then checks checkRepoConfigInaccessible, and skips using the repo anyway, a wrong guess should not be a problem. Sponsored-by: Luke Shumaker on Patreon
This commit is contained in:
parent
12b45d3b89
commit
c1ef4a7481
7 changed files with 39 additions and 30 deletions
|
@ -133,14 +133,28 @@ store' k v repo = repo
|
|||
- based on the core.bare and core.worktree settings.
|
||||
-}
|
||||
updateLocation :: Repo -> IO Repo
|
||||
updateLocation r@(Repo { location = LocalUnknown d })
|
||||
| isBare r = ifM (doesDirectoryExist (fromRawFilePath dotgit))
|
||||
( updateLocation' r $ Local dotgit Nothing
|
||||
, updateLocation' r $ Local d Nothing
|
||||
)
|
||||
| otherwise = updateLocation' r $ Local dotgit (Just d)
|
||||
updateLocation r@(Repo { location = LocalUnknown d }) = case isBare r of
|
||||
Just True -> ifM (doesDirectoryExist (fromRawFilePath dotgit))
|
||||
( updateLocation' r $ Local dotgit Nothing
|
||||
, updateLocation' r $ Local d Nothing
|
||||
)
|
||||
Just False -> mknonbare
|
||||
{- core.bare not in config, probably because safe.directory
|
||||
- did not allow reading the config -}
|
||||
Nothing -> ifM (Git.Construct.isBareRepo (fromRawFilePath d))
|
||||
( mkbare
|
||||
, mknonbare
|
||||
)
|
||||
where
|
||||
dotgit = d P.</> ".git"
|
||||
-- git treats eg ~/foo as a bare git repository located in
|
||||
-- ~/foo/.git if ~/foo/.git/config has core.bare=true
|
||||
mkbare = ifM (doesDirectoryExist (fromRawFilePath dotgit))
|
||||
( updateLocation' r $ Local dotgit Nothing
|
||||
, updateLocation' r $ Local d Nothing
|
||||
)
|
||||
mknonbare = updateLocation' r $ Local dotgit (Just d)
|
||||
|
||||
updateLocation r@(Repo { location = l@(Local {}) }) = updateLocation' r l
|
||||
updateLocation r = return r
|
||||
|
||||
|
@ -212,8 +226,9 @@ boolConfig' :: Bool -> S.ByteString
|
|||
boolConfig' True = "true"
|
||||
boolConfig' False = "false"
|
||||
|
||||
isBare :: Repo -> Bool
|
||||
isBare r = fromMaybe False $ isTrueFalse' =<< getMaybe coreBare r
|
||||
{- Note that repoIsLocalBare is often better to use than this. -}
|
||||
isBare :: Repo -> Maybe Bool
|
||||
isBare r = isTrueFalse' =<< getMaybe coreBare r
|
||||
|
||||
coreBare :: ConfigKey
|
||||
coreBare = "core.bare"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue