more OsPath conversion
Sponsored-by: Eve
This commit is contained in:
parent
dd01406018
commit
aa0f3f31da
23 changed files with 155 additions and 166 deletions
20
Git/Hook.hs
20
Git/Hook.hs
|
@ -21,10 +21,8 @@ import qualified Utility.RawFilePath as R
|
|||
import System.PosixCompat.Files (fileMode)
|
||||
#endif
|
||||
|
||||
import qualified System.FilePath.ByteString as P
|
||||
|
||||
data Hook = Hook
|
||||
{ hookName :: RawFilePath
|
||||
{ hookName :: OsPath
|
||||
, hookScript :: String
|
||||
, hookOldScripts :: [String]
|
||||
}
|
||||
|
@ -33,8 +31,8 @@ data Hook = Hook
|
|||
instance Eq Hook where
|
||||
a == b = hookName a == hookName b
|
||||
|
||||
hookFile :: Hook -> Repo -> RawFilePath
|
||||
hookFile h r = localGitDir r P.</> "hooks" P.</> hookName h
|
||||
hookFile :: Hook -> Repo -> OsPath
|
||||
hookFile h r = localGitDir r </> literalOsPath "hooks" </> hookName h
|
||||
|
||||
{- Writes a hook. Returns False if the hook already exists with a different
|
||||
- content. Upgrades old scripts.
|
||||
|
@ -65,8 +63,8 @@ hookWrite h r = ifM (doesFileExist f)
|
|||
-- Hook scripts on Windows could use CRLF endings, but
|
||||
-- they typically use unix newlines, which does work there
|
||||
-- and makes the repository more portable.
|
||||
viaTmp F.writeFile' (toOsPath f) (encodeBS (hookScript h))
|
||||
void $ tryIO $ modifyFileMode f (addModes executeModes)
|
||||
viaTmp F.writeFile' f (encodeBS (hookScript h))
|
||||
void $ tryIO $ modifyFileMode (fromOsPath f) (addModes executeModes)
|
||||
return True
|
||||
|
||||
{- Removes a hook. Returns False if the hook contained something else, and
|
||||
|
@ -91,7 +89,7 @@ expectedContent h r = do
|
|||
-- and so a hook file that has CRLF will be treated the same as one
|
||||
-- that has LF. That is intentional, since users may have a reason
|
||||
-- to prefer one or the other.
|
||||
content <- readFile $ fromRawFilePath $ hookFile h r
|
||||
content <- readFile $ fromOsPath $ hookFile h r
|
||||
return $ if content == hookScript h
|
||||
then ExpectedContent
|
||||
else if any (content ==) (hookOldScripts h)
|
||||
|
@ -103,13 +101,13 @@ hookExists h r = do
|
|||
let f = hookFile h r
|
||||
catchBoolIO $
|
||||
#ifndef mingw32_HOST_OS
|
||||
isExecutable . fileMode <$> R.getFileStatus f
|
||||
isExecutable . fileMode <$> R.getFileStatus (fromOsPath f)
|
||||
#else
|
||||
doesFileExist (fromRawFilePath f)
|
||||
doesFileExist f
|
||||
#endif
|
||||
|
||||
runHook :: (FilePath -> [CommandParam] -> IO a) -> Hook -> [CommandParam] -> Repo -> IO a
|
||||
runHook runner h ps r = do
|
||||
let f = fromRawFilePath $ hookFile h r
|
||||
let f = fromOsPath $ hookFile h r
|
||||
(c, cps) <- findShellCommand f
|
||||
runner c (cps ++ ps)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue