Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

--file-watch should respect VCS boring/ignore files #831

Merged
merged 1 commit into from
Aug 23, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions src/Stack/FileWatch.hs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import Data.Set (Set)
import qualified Data.Set as Set
import Data.String (fromString)
import Data.Traversable (forM)
import Ignore
import Path
import System.FSNotify
import System.IO (stderr)
Expand All @@ -32,11 +33,20 @@ printExceptionStderr e =
--
-- The action provided takes a callback that is used to set the files to be
-- watched. When any of those files are changed, we rerun the action again.
fileWatch :: ((Set (Path Abs File) -> IO ()) -> IO ())
fileWatch :: IO (Path Abs Dir)
-> ((Set (Path Abs File) -> IO ()) -> IO ())
-> IO ()
fileWatch inner = withManager $ \manager -> do
fileWatch getProjectRoot inner = withManager $ \manager -> do
dirtyVar <- newTVarIO True
watchVar <- newTVarIO Map.empty
projRoot <- getProjectRoot
mChecker <- findIgnoreFiles [VCSGit, VCSMercurial, VCSDarcs] projRoot >>= buildChecker
(FileIgnoredChecker isFileIgnored) <-
case mChecker of
Left err ->
do putStrLn $ "Failed to parse VCS's ignore file: " ++ err
return $ FileIgnoredChecker (const False)
Right chk -> return chk

let onChange = atomically $ writeTVar dirtyVar True

Expand Down Expand Up @@ -67,7 +77,7 @@ fileWatch inner = withManager $ \manager -> do
return Nothing
startListening = Map.mapWithKey $ \dir () -> do
let dir' = fromString $ toFilePath dir
listen <- watchDir manager dir' (const True) (const onChange)
listen <- watchDir manager dir' (not . isFileIgnored . eventPath) (const onChange)
return $ Just listen

let watchInput = do
Expand Down
2 changes: 1 addition & 1 deletion src/Stack/Options.hs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ buildOptsParser cmd =

fileWatch' = flag False True
(long "file-watch" <>
help "Watch for changes in local files and automatically rebuild")
help "Watch for changes in local files and automatically rebuild. Ignores files in VCS boring/ignore file")

keepGoing = maybeBoolFlags
"keep-going"
Expand Down
9 changes: 8 additions & 1 deletion src/main/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -666,7 +666,14 @@ cleanCmd () go = withBuildConfigAndLock go (\_ -> clean)
buildCmd :: Maybe (Text, Text) -- ^ option synonym
-> BuildOpts -> GlobalOpts -> IO ()
buildCmd moptionSynonym opts go
| boptsFileWatch opts = fileWatch inner
| boptsFileWatch opts =
let getProjectRoot =
do (manager, lc) <- loadConfigWithOpts go
bconfig <-
runStackLoggingTGlobal manager go $
lcLoadBuildConfig lc (globalResolver go)
return (bcRoot bconfig)
in fileWatch getProjectRoot inner
| otherwise = inner $ const $ return ()
where
inner setLocalFiles = withBuildConfigAndLock go $ \lk -> do
Expand Down
1 change: 1 addition & 0 deletions stack.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,7 @@ library
, http-client-tls >= 0.2.2
, http-conduit >= 2.1.7
, http-types >= 0.8.6
, ignore >= 0.1
, lifted-base
, monad-control
, monad-logger >= 0.3.13.1
Expand Down
3 changes: 2 additions & 1 deletion stack.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
resolver: lts-3.0

extra-deps:
- ignore-0.1.0.0
image:
container:
base: "fpco/ubuntu-with-libgmp:14.04"
Expand Down