diff options
author | Ben Sima <ben@bsima.me> | 2024-04-01 16:35:15 -0400 |
---|---|---|
committer | Ben Sima <ben@bsima.me> | 2024-04-01 16:35:15 -0400 |
commit | 99e114f5c598ce6321c81bbe41e212877a3c375c (patch) | |
tree | 07b2ac7c96c0970291bce7691aa58054bd1f965a /Biz/Bild.hs | |
parent | 4c7327d144a1e1fd2bd2cfa6a9c49b838674bdd8 (diff) |
Make bild exception for git hooks
Apparently git hooks don't get called if they have a file extention, so these
weren't getting called at all since commit
904de577261e7024373e7a42fd763184764238f9. So this renames them back to the
extension-less versions, and adds an exception in bild for files in the
core.hooksPath directory.
Unfortunately this means Lint.hs will silently ignore these files, but I guess
that's okay for now.
Diffstat (limited to 'Biz/Bild.hs')
-rw-r--r-- | Biz/Bild.hs | 30 |
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 |