Revert "revert recent bug fix temporarily for release"
This reverts commit 16f1e24665
.
This commit is contained in:
parent
dd1a5f4961
commit
672258c8f4
8 changed files with 47 additions and 33 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"
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{- Construction of Git Repo objects
|
||||
-
|
||||
- Copyright 2010-2021 Joey Hess <id@joeyh.name>
|
||||
- Copyright 2010-2023 Joey Hess <id@joeyh.name>
|
||||
-
|
||||
- Licensed under the GNU AGPL version 3 or higher.
|
||||
-}
|
||||
|
@ -23,6 +23,7 @@ module Git.Construct (
|
|||
checkForRepo,
|
||||
newFrom,
|
||||
adjustGitDirFile,
|
||||
isBareRepo,
|
||||
) where
|
||||
|
||||
#ifndef mingw32_HOST_OS
|
||||
|
@ -216,7 +217,7 @@ checkForRepo :: FilePath -> IO (Maybe RepoLocation)
|
|||
checkForRepo dir =
|
||||
check isRepo $
|
||||
check (checkGitDirFile (toRawFilePath dir)) $
|
||||
check isBareRepo $
|
||||
check (checkdir (isBareRepo dir)) $
|
||||
return Nothing
|
||||
where
|
||||
check test cont = maybe cont (return . Just) =<< test
|
||||
|
@ -225,16 +226,17 @@ checkForRepo dir =
|
|||
, return Nothing
|
||||
)
|
||||
isRepo = checkdir $
|
||||
gitSignature (".git" </> "config")
|
||||
doesFileExist (dir </> ".git" </> "config")
|
||||
<||>
|
||||
-- A git-worktree lacks .git/config, but has .git/gitdir.
|
||||
-- (Normally the .git is a file, not a symlink, but it can
|
||||
-- be converted to a symlink and git will still work;
|
||||
-- this handles that case.)
|
||||
gitSignature (".git" </> "gitdir")
|
||||
isBareRepo = checkdir $ gitSignature "config"
|
||||
<&&> doesDirectoryExist (dir </> "objects")
|
||||
gitSignature file = doesFileExist $ dir </> file
|
||||
doesFileExist (dir </> ".git" </> "gitdir")
|
||||
|
||||
isBareRepo :: FilePath -> IO Bool
|
||||
isBareRepo dir = doesFileExist (dir </> "config")
|
||||
<&&> doesDirectoryExist (dir </> "objects")
|
||||
|
||||
-- Check for a .git file.
|
||||
checkGitDirFile :: RawFilePath -> IO (Maybe RepoLocation)
|
||||
|
|
|
@ -81,7 +81,7 @@ get = do
|
|||
}
|
||||
r <- Git.Config.read $ (newFrom loc)
|
||||
{ gitDirSpecifiedExplicitly = True }
|
||||
return $ if Git.Config.isBare r
|
||||
return $ if fromMaybe False (Git.Config.isBare r)
|
||||
then r { location = (location r) { worktree = Nothing } }
|
||||
else r
|
||||
configure Nothing Nothing = giveup "Not in a git repository."
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue