summaryrefslogtreecommitdiff
path: root/src/Repo.hs
diff options
context:
space:
mode:
Diffstat (limited to 'src/Repo.hs')
-rw-r--r--src/Repo.hs15
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