more OsPath conversion

Git.Types now uses it, as does TopFilePath, making for plenty of new
compile errors needing fixing.

Sponsored-by: Brock Spratlen
This commit is contained in:
Joey Hess 2025-01-23 16:15:00 -04:00
parent 12660314f1
commit ea775baccd
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
22 changed files with 159 additions and 163 deletions

View file

@ -176,43 +176,43 @@ fromRemoteLocation s knownurl repo = gen $ parseRemoteLocation s knownurl repo
fromRemotePath :: FilePath -> Repo -> IO Repo
fromRemotePath dir repo = do
dir' <- expandTilde dir
fromPath $ repoPath repo P.</> toRawFilePath dir'
fromPath $ repoPath repo P.</> dir'
{- Git remotes can have a directory that is specified relative
- to the user's home directory, or that contains tilde expansions.
- This converts such a directory to an absolute path.
- Note that it has to run on the system where the remote is.
-}
repoAbsPath :: RawFilePath -> IO RawFilePath
repoAbsPath :: OsPath -> IO OsPath
repoAbsPath d = do
d' <- expandTilde (fromRawFilePath d)
d' <- expandTilde (fromOsPath d)
h <- myHomeDir
return $ toRawFilePath $ h </> d'
return $ toOsPath h </> d'
expandTilde :: FilePath -> IO FilePath
expandTilde :: FilePath -> IO OsPath
#ifdef mingw32_HOST_OS
expandTilde = return
expandTilde = return . toOsPath
#else
expandTilde p = expandt True p
-- If unable to expand a tilde, eg due to a user not existing,
-- use the path as given.
`catchNonAsync` (const (return p))
`catchNonAsync` (const (return (toOsPath p)))
where
expandt _ [] = return ""
expandt _ [] = return $ literalOsPath ""
expandt _ ('/':cs) = do
v <- expandt True cs
return ('/':v)
return $ literalOsPath "/" <> v
expandt True ('~':'/':cs) = do
h <- myHomeDir
return $ h </> cs
expandt True "~" = myHomeDir
return $ toOsPath h </> toOsPath cs
expandt True "~" = toOsPath <$> myHomeDir
expandt True ('~':cs) = do
let (name, rest) = findname "" cs
u <- getUserEntryForName name
return $ homeDirectory u </> rest
return $ toOsPath (homeDirectory u) </> toOsPath rest
expandt _ (c:cs) = do
v <- expandt False cs
return (c:v)
return $ toOsPath [c] <> v
findname n [] = (n, "")
findname n (c:cs)
| c == '/' = (n, cs)
@ -221,11 +221,11 @@ expandTilde p = expandt True p
{- Checks if a git repository exists in a directory. Does not find
- git repositories in parent directories. -}
checkForRepo :: RawFilePath -> IO (Maybe RepoLocation)
checkForRepo :: OsPath -> IO (Maybe RepoLocation)
checkForRepo dir =
check isRepo $
check (checkGitDirFile dir) $
check (checkdir (isBareRepo dir')) $
check (checkdir (isBareRepo dir)) $
return Nothing
where
check test cont = maybe cont (return . Just) =<< test
@ -234,23 +234,22 @@ checkForRepo dir =
, return Nothing
)
isRepo = checkdir $
doesFileExist (dir' </> ".git" </> "config")
doesFileExist (dir </> literalOsPath ".git" </> literalOsPath "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.)
doesFileExist (dir' </> ".git" </> "gitdir")
dir' = fromRawFilePath dir
doesFileExist (dir </> literalOsPath ".git" </> literalOsPath "gitdir")
isBareRepo :: FilePath -> IO Bool
isBareRepo dir = doesFileExist (dir </> "config")
<&&> doesDirectoryExist (dir </> "objects")
isBareRepo :: OsPath -> IO Bool
isBareRepo dir = doesFileExist (dir </> literalOsPath "config")
<&&> doesDirectoryExist (dir </> literalOsPath "objects")
-- Check for a .git file.
checkGitDirFile :: RawFilePath -> IO (Maybe RepoLocation)
checkGitDirFile :: OsPath -> IO (Maybe RepoLocation)
checkGitDirFile dir = adjustGitDirFile' $ Local
{ gitdir = dir P.</> ".git"
{ gitdir = dir </> literalOsPath ".git"
, worktree = Just dir
}