summaryrefslogtreecommitdiff
path: root/Biz/Bild.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r--Biz/Bild.hs30
1 files changed, 27 insertions, 3 deletions
diff --git a/Biz/Bild.hs b/Biz/Bild.hs
index 15f2700..15d9619 100644
--- a/Biz/Bild.hs
+++ b/Biz/Bild.hs
@@ -160,7 +160,8 @@ main = Cli.Plan help move test_ pure |> Cli.main
"Biz.Bild"
[ test_bildBild,
test_bildExamples,
- test_isGitIgnored
+ test_isGitIgnored,
+ test_isGitHook
]
test_bildBild :: Test.Tree
@@ -201,6 +202,7 @@ move args =
Cli.getAllArgs args (Cli.argument "target")
|> filterM Dir.doesFileExist
+> filterM (\x -> isGitIgnored x /> don't)
+ +> filterM (\x -> isGitHook root x /> don't)
+> traverse Dir.makeAbsolute
+> traverse (namespaceFromPathOrDie root)
+> foldM analyze mempty
@@ -275,6 +277,27 @@ test_isGitIgnored =
+> (@=? [False, True])
]
+isGitHook :: FilePath -> FilePath -> IO Bool
+isGitHook root path =
+ Process.readProcess "git" ["config", "--local", "core.hooksPath"] ""
+ /> strip
+ /> stripRoot root
+ /> flip List.isInfixOf path
+
+test_isGitHook :: Test.Tree
+test_isGitHook =
+ Test.group
+ "isGitHook"
+ [ Test.unit "filters pre-commit hook" <| do
+ root <- Env.getEnv "CODEROOT"
+ res <- isGitHook root <| root <> "/Biz/Ide/hooks/pre-commit"
+ res @=? True,
+ Test.unit "doesn't filter non-hooks" <| do
+ root <- Env.getEnv "CODEROOT"
+ res <- isGitHook root <| root <> "/Biz/Bild.hs"
+ res @=? False
+ ]
+
namespaceFromPathOrDie :: FilePath -> FilePath -> IO Namespace
namespaceFromPathOrDie root path =
Namespace.fromPath root path |> \case
@@ -765,8 +788,6 @@ detectHaskellImports hmap contentLines =
(pkgs <> deps, map (stripRoot root) files |> Set.fromList)
|> pure
where
- stripRoot :: FilePath -> FilePath -> QualifiedPath
- stripRoot root f = fromMaybe f (List.stripPrefix (root <> "/") f)
filepaths :: [String] -> IO [FilePath]
filepaths imports =
imports
@@ -791,6 +812,9 @@ detectHaskellImports hmap contentLines =
onlyHaskell :: Analysis -> Analysis
onlyHaskell = Map.filterWithKey (\ns _ -> ext ns == Namespace.Hs)
+stripRoot :: FilePath -> FilePath -> FilePath
+stripRoot root f = fromMaybe f (List.stripPrefix (root <> "/") f)
+
detectLispImports :: [Text] -> IO (Set Meta.Dep)
detectLispImports contentLines =
contentLines