diff options
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))) |