aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/History.hs41
1 files changed, 32 insertions, 9 deletions
diff --git a/app/History.hs b/app/History.hs
index a3cdf75..59b3961 100644
--- a/app/History.hs
+++ b/app/History.hs
@@ -64,7 +64,16 @@ merge (issue, issues) =
getIssuesWorkingTreeAll :: [FilePath] -> IO [Issue]
getIssuesWorkingTreeAll paths = do
cwd <- getCurrentDirectory
- files <- getFilesAllIn cwd paths
+ files <- gitLsFilesAllIn cwd paths
+ concat <$> catch (getIssuesPar cwd files) dieOfInvalidTreeGrepperResult
+
+-- | Gets issues in all files which have been changed in your current
+-- [working
+-- - tree](https://git-scm.com/docs/gitglossary#Documentation/gitglossary.txt-aiddefworkingtreeaworkingtree)
+getIssuesWorkingTreeChanged :: [FilePath] -> IO [Issue]
+getIssuesWorkingTreeChanged paths = do
+ cwd <- getCurrentDirectory
+ files <- gitLsFilesModifiedIn cwd paths
concat <$> catch (getIssuesPar cwd files) dieOfInvalidTreeGrepperResult
-- | Given the hash of a commit, get all issues in all files at the
@@ -77,7 +86,7 @@ getIssuesCommitAll hash = do
let cwd = tmp </> unpack hash
sh_ $ fromString $ printf "git worktree add --detach %s %s" (quote cwd) (quote $ unpack hash)
pure cwd
- files <- getFilesAll cwd
+ files <- gitLsFilesAll cwd
concat <$> catch (getIssuesPar cwd files) (dieOfInvalidTreeGrepperResult)
-- | Given the hash of a commit, get all issues in the files which have
@@ -89,16 +98,16 @@ getIssuesCommitChanged hash = do
let cwd = tmp </> unpack hash
sh_ $ fromString $ printf "git worktree add --detach %s %s" (quote cwd) (quote $ unpack hash)
pure cwd
- files <- getFilesChanged cwd
+ files <- gitShowChanged cwd
concat <$> catch (getIssuesPar cwd files) (dieOfInvalidTreeGrepperResult)
-getFilesAll :: FilePath -> IO [FilePath]
-getFilesAll cwd =
+gitLsFilesAll :: FilePath -> IO [FilePath]
+gitLsFilesAll cwd =
Prelude.lines . L8.unpack
<$> sh ("git ls-files --cached --exclude-standard --other" & setWorkingDir cwd)
-getFilesAllIn :: FilePath -> [String] -> IO [FilePath]
-getFilesAllIn cwd paths =
+gitLsFilesAllIn :: FilePath -> [String] -> IO [FilePath]
+gitLsFilesAllIn cwd paths =
Prelude.lines . L8.unpack
<$> sh
( fromString
@@ -111,11 +120,25 @@ getFilesAllIn cwd paths =
& setWorkingDir cwd
)
-getFilesChanged :: FilePath -> IO [FilePath]
-getFilesChanged cwd =
+gitShowChanged :: FilePath -> IO [FilePath]
+gitShowChanged cwd =
Prelude.lines . L8.unpack
<$> sh ("git show -p --name-only --format=''" & setWorkingDir cwd)
+gitLsFilesModifiedIn :: FilePath -> [FilePath] -> IO [FilePath]
+gitLsFilesModifiedIn cwd paths =
+ Prelude.lines . L8.unpack
+ <$> sh
+ ( fromString
+ ( (printf "git ls-files --modified%s")
+ ( case paths of
+ [] -> ""
+ _ -> " -- " ++ intercalate " " (map quote paths)
+ )
+ )
+ & setWorkingDir cwd
+ )
+
-- | Get all issues in the given directory and files. Runs
-- parallelized.
getIssuesPar :: FilePath -> [FilePath] -> IO [[Issue]]