diff options
author | Alexander Foremny <aforemny@posteo.de> | 2024-03-14 06:52:32 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2024-03-14 07:07:45 +0100 |
commit | 1821aca5ef5451d0b1943c8640c5eb1f6fa7bbee (patch) | |
tree | dc3df78464a164b3fb9674d4e03bc56d58a56df1 /app/Git.hs | |
parent | 2c107e71572888327496d327a36737c02f64d894 (diff) |
chore: resolve TODOs
Diffstat (limited to 'app/Git.hs')
-rw-r--r-- | app/Git.hs | 18 |
1 files changed, 15 insertions, 3 deletions
@@ -31,7 +31,7 @@ import Exception qualified as E import GHC.Generics (Generic) import Git.CommitHash import Patch qualified as A -import Process (proc, sh) +import Process (proc, sh, sh_) import Text.Printf (printf) getCommitHashes :: IO (NonEmpty T.Text) @@ -96,6 +96,7 @@ readTextFileOfText = readTextFileOf LT.readFile LT.decodeUtf8 readTextFileOfBS :: CommitHash -> FilePath -> IO LB.ByteString readTextFileOfBS = readTextFileOf LB.readFile id + -- REVIEW Suggestion: we could use `id` instead of `\x -> x` -- -- REVIEW OK! @@ -118,9 +119,20 @@ resolveRef = . sh . proc "git rev-parse %" --- TODO Throw if `prevHash` is not an ancestor of `hash`. +-- | `getCommitsBetween prevCommit commit` returns the commits from `prevCommit` to `commit`. The result excludes `prevCommit`, but includes `commit`. +-- +-- If `prevCommit` is not an ancestor of `commit`, this functions throws `NoAncestor commit prevCommit`. getCommitsBetween :: CommitHash -> CommitHash -> IO [CommitHash] -getCommitsBetween (Commit prevHash) (Commit hash) = do +getCommitsBetween WorkingTree commit@(Commit _) = + throwIO (E.NoAncestor WorkingTree commit) +getCommitsBetween WorkingTree WorkingTree = pure [WorkingTree] +getCommitsBetween prevCommit WorkingTree = + fmap (++ [WorkingTree]) . getCommitsBetween prevCommit + =<< resolveRef "HEAD" +getCommitsBetween prevCommit@(Commit prevHash) commit@(Commit hash) = do + catch + (sh_ (proc "git merge-base --is-ancestor % %" prevHash hash)) + (\(_ :: E.ProcessException) -> throwIO (E.NoAncestor commit prevCommit)) map (Commit . T.strip) . T.lines . T.decodeUtf8 . LB.toStrict <$> sh (proc "git log --format=%%H %..%" prevHash hash) |