diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-12-08 07:34:55 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-12-08 07:35:33 +0100 |
commit | 5c9c7b360e4578f3db487e663587194746d0386b (patch) | |
tree | 625f7adf8430bf847e7ef760e9403f480619c2a2 /app/Git.hs | |
parent | 19b148277aa5a80bce1c87e33bb857e66698f4eb (diff) |
fix: fix `Git.readTextFileOf`
Diffstat (limited to 'app/Git.hs')
-rw-r--r-- | app/Git.hs | 15 |
1 files changed, 9 insertions, 6 deletions
@@ -12,7 +12,7 @@ module Git ) where -import Control.Exception (throw, throwIO) +import Control.Exception (IOException, catch, throw, throwIO) import Data.Binary (Binary, Put, get, put) import Data.ByteString.Lazy qualified as LB import Data.Fixed (Pico) @@ -30,6 +30,7 @@ import Exception qualified as E import GHC.Generics (Generic) import Git.CommitHash import Process (proc, sh) +import Text.Printf (printf) import Prelude hiding (lines) getCommitHashes :: IO (NonEmpty T.Text) @@ -105,10 +106,12 @@ getCommitOf commitHash@(Commit hash) = do } _ -> throwIO E.NoCommits --- TODO Fix `readTextFileOf` --- --- Handle file does not exist in `WorkingTree` case. readTextFileOf :: CommitHash -> FilePath -> IO LT.Text -readTextFileOf WorkingTree filePath = LT.readFile filePath +readTextFileOf WorkingTree filePath = + catch + (LT.readFile filePath) + (\(_ :: IOException) -> throwIO (E.CannotReadFile filePath)) readTextFileOf (Commit hash) filePath = - LT.decodeUtf8 <$> sh (proc "git show %:%" hash filePath) + catch + (LT.decodeUtf8 <$> sh (proc "git show %:%" hash filePath)) + (\(_ :: E.ProcessException) -> throwIO (E.CannotReadFile (printf "%s:%s" hash filePath))) |