diff options
author | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-07 22:00:57 +0100 |
---|---|---|
committer | Roman Smrž <roman.smrz@seznam.cz> | 2025-03-07 22:00:57 +0100 |
commit | b2295603ac1a8e333079fe1a87c04b27bd4ce157 (patch) | |
tree | cdc68ec6d734b100453c22ab68ae09459fec9205 /src/Repo.hs | |
parent | 53ed8a2eb2c0f8eab4c346114c0b777cdf7c9f55 (diff) |
Subtree checkout option
Diffstat (limited to 'src/Repo.hs')
-rw-r--r-- | src/Repo.hs | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/src/Repo.hs b/src/Repo.hs index 0720179..ef95b36 100644 --- a/src/Repo.hs +++ b/src/Repo.hs @@ -19,6 +19,8 @@ module Repo ( getCommitTitle, getCommitMessage, + getSubtree, + checkoutAt, readCommittedFile, @@ -245,6 +247,19 @@ getCommitMessage :: (MonadIO m, MonadFail m) => Commit -> m Text getCommitMessage = fmap commitMessage . getCommitDetails +getSubtree :: MonadIO m => FilePath -> Tree -> m (Maybe Tree) +getSubtree path tree = liftIO $ do + let GitRepo {..} = treeRepo tree + readProcessWithExitCode "git" [ "--git-dir=" <> gitDir, "rev-parse", "--verify", "--quiet", showTreeId (treeId tree) <> ":" <> path ] "" >>= \case + ( ExitSuccess, out, _ ) | tid : _ <- lines out -> do + return $ Just Tree + { treeRepo = treeRepo tree + , treeId = TreeId (BC.pack tid) + } + _ -> do + return Nothing + + checkoutAt :: (MonadIO m, MonadFail m) => Tree -> FilePath -> m () checkoutAt Tree {..} dest = do let GitRepo {..} = treeRepo |