aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
Diffstat (limited to 'app')
-rw-r--r--app/Git.hs4
-rw-r--r--app/History/Cache.hs14
-rw-r--r--app/Settings.hs5
3 files changed, 13 insertions, 10 deletions
diff --git a/app/Git.hs b/app/Git.hs
index 7891288..c72edea 100644
--- a/app/Git.hs
+++ b/app/Git.hs
@@ -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
]