aboutsummaryrefslogtreecommitdiffstats
path: root/app/Git.hs
diff options
context:
space:
mode:
authorLibravatar Alexander Foremny <aforemny@posteo.de>2023-10-17 14:14:48 +0200
committerLibravatar Alexander Foremny <aforemny@posteo.de>2023-11-07 09:50:51 +0100
commitea1236f2cf6d3ef4b739b2ca28f47a3bbed42295 (patch)
tree3b1801ad9654e657ed0c0b202e316dc42244c56d /app/Git.hs
parent4521eb7a4b0d4a4ff8cf9153484d0596c5143170 (diff)
refactor history
Diffstat (limited to 'app/Git.hs')
-rw-r--r--app/Git.hs17
1 files changed, 13 insertions, 4 deletions
diff --git a/app/Git.hs b/app/Git.hs
index 57fffdc..7891288 100644
--- a/app/Git.hs
+++ b/app/Git.hs
@@ -1,15 +1,24 @@
-module Git (withWorkingTree) where
+module Git
+ ( withWorkingTree,
+ getCommitHashes,
+ )
+where
import Control.Exception (finally)
-import Data.Text (Text)
-import Process (proc, sh_)
+import Data.ByteString.Lazy.Char8 qualified as LB8
+import Data.Text qualified as T
+import Data.Text.Encoding qualified as T
+import Process (proc, sh, sh_)
import System.Directory (createDirectoryIfMissing)
import System.FilePath (dropTrailingPathSeparator, takeDirectory)
-- | Runs an IO-action within a working tree.
-withWorkingTree :: FilePath -> Text -> IO a -> IO a
+withWorkingTree :: FilePath -> T.Text -> IO a -> IO a
withWorkingTree path hash action = do
createDirectoryIfMissing True (takeDirectory (dropTrailingPathSeparator path))
sh_ $ proc "git worktree add --quiet --detach % %" path hash
action `finally` do
sh_ $ proc "git worktree remove --force %" path
+
+getCommitHashes :: IO [T.Text]
+getCommitHashes = T.lines . T.decodeUtf8 . LB8.toStrict <$> sh "git log --format=%H"