diff options
author | Alexander Foremny <aforemny@posteo.de> | 2023-10-23 10:08:49 +0200 |
---|---|---|
committer | Alexander Foremny <aforemny@posteo.de> | 2023-11-07 09:50:52 +0100 |
commit | 2e032a5210d5166a42797ee8f296ec4228d6d838 (patch) | |
tree | bb71d1b466581114ffd7613d950533ffc1298834 | |
parent | 1127c71fa5f5c5a3d6bfde818cb00eb26e9d4cb3 (diff) |
add `Git.getRootDir`
-rw-r--r-- | app/Git.hs | 4 | ||||
-rw-r--r-- | app/History/Cache.hs | 14 | ||||
-rw-r--r-- | app/Settings.hs | 5 |
3 files changed, 13 insertions, 10 deletions
@@ -1,6 +1,7 @@ module Git ( withWorkingTree, getCommitHashes, + getRootDir, ) where @@ -22,3 +23,6 @@ withWorkingTree path hash action = do getCommitHashes :: IO [T.Text] getCommitHashes = T.lines . T.decodeUtf8 . LB8.toStrict <$> sh "git log --format=%H" + +getRootDir :: IO FilePath +getRootDir = T.unpack . T.decodeUtf8 . LB8.toStrict <$> sh (proc "git rev-parse --show-toplevel") diff --git a/app/History/Cache.hs b/app/History/Cache.hs index af40a84..d0473e2 100644 --- a/app/History/Cache.hs +++ b/app/History/Cache.hs @@ -2,17 +2,15 @@ module History.Cache (cached) where import Data.Binary (Binary, decodeFileOrFail, encodeFile) import Data.Text qualified as T -import System.Directory (createDirectoryIfMissing, doesFileExist, getCurrentDirectory) +import Git qualified +import System.Directory (createDirectoryIfMissing, doesFileExist) +import System.FilePath ((</>)) cached :: Binary a => T.Text -> (T.Text -> IO a) -> IO a cached hash func = do - -- FIXME Cache inside Git root - -- - -- The cache location should not be dependant on the current directory, but - -- should be placed alongside the `.git` directory. - cwd <- getCurrentDirectory - createDirectoryIfMissing True (cwd ++ "/.anissue") - let file = (cwd ++ "/.anissue/" ++ T.unpack hash) + root <- Git.getRootDir + createDirectoryIfMissing True (root </> ".anissue") + let file = (root </> ".anissue" </> T.unpack hash) doesFileExist file >>= \case True -> decodeFileOrFail file >>= \case diff --git a/app/Settings.hs b/app/Settings.hs index 116a3d2..c439b65 100644 --- a/app/Settings.hs +++ b/app/Settings.hs @@ -7,8 +7,10 @@ where import Data.Aeson qualified as A import Data.Yaml (decodeFileThrow) import GHC.Generics (Generic) +import Git qualified import System.Directory (doesFileExist) import System.Environment.XDG.BaseDir (getSystemConfigFiles, getUserConfigFile) +import System.FilePath ((</>)) data Settings = Settings { @@ -38,6 +40,5 @@ readSettings = <$> sequence [ getSystemConfigFiles "anissue" "settings.yaml", ((: []) <$> getUserConfigFile "anissue" "settings.yaml"), - -- TODO Read settings from Git base dir - pure ["./anissue.yaml"] + ((: []) . (</> "anissue.yaml")) <$> Git.getRootDir ] |