diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-11-07 22:38:03 +0100 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-11-07 22:38:06 +0100 |
commit | 561ef3d43d94bdf098fee37295d7588905ec0c9e (patch) | |
tree | 325e692bf80fd51df35503b87eae0f0abff40269 /app/Git.hs | |
parent | c64a7e5285bb119927c8cb1136db60c6ffa77220 (diff) |
improve getCommitHashes
`getCommitHashes` now returns at least one commit, and reverses commits
by default (ie. oldest to newset).
Diffstat (limited to 'app/Git.hs')
-rw-r--r-- | app/Git.hs | 9 |
1 files changed, 6 insertions, 3 deletions
@@ -5,11 +5,14 @@ module Git ) where -import Control.Exception (finally) +import Control.Exception (finally, throw) import Data.ByteString.Lazy.Char8 qualified as LB8 +import Data.List.NonEmpty (NonEmpty) +import Data.List.NonEmpty qualified as N import Data.Maybe (fromMaybe) import Data.Text qualified as T import Data.Text.Encoding qualified as T +import Exception qualified as E import Process (proc, sh, sh_) import System.Directory (createDirectoryIfMissing) import System.FilePath (dropTrailingPathSeparator, takeDirectory) @@ -22,8 +25,8 @@ withWorkingTree path hash action = do 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" +getCommitHashes :: IO (NonEmpty T.Text) +getCommitHashes = fromMaybe (throw E.NoCommits) . N.nonEmpty . reverse . T.lines . T.decodeUtf8 . LB8.toStrict <$> sh "git log --format=%H" getRootDir :: IO FilePath getRootDir = T.unpack . stripTrailingNL . T.decodeUtf8 . LB8.toStrict <$> sh (proc "git rev-parse --show-toplevel") |