Skip to content

Commit f664843

Browse files
committed
--file-watch should respect VCS boring/ignore files
1 parent da38580 commit f664843

5 files changed

Lines changed: 25 additions & 6 deletions

File tree

src/Stack/FileWatch.hs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import Data.Set (Set)
1919
import qualified Data.Set as Set
2020
import Data.String (fromString)
2121
import Data.Traversable (forM)
22+
import Ignore
2223
import Path
2324
import System.FSNotify
2425
import System.IO (stderr)
@@ -32,11 +33,20 @@ printExceptionStderr e =
3233
--
3334
-- The action provided takes a callback that is used to set the files to be
3435
-- watched. When any of those files are changed, we rerun the action again.
35-
fileWatch :: ((Set (Path Abs File) -> IO ()) -> IO ())
36+
fileWatch :: IO (Path Abs Dir)
37+
-> ((Set (Path Abs File) -> IO ()) -> IO ())
3638
-> IO ()
37-
fileWatch inner = withManager $ \manager -> do
39+
fileWatch getProjectRoot inner = withManager $ \manager -> do
3840
dirtyVar <- newTVarIO True
3941
watchVar <- newTVarIO Map.empty
42+
projRoot <- getProjectRoot
43+
mChecker <- findIgnoreFiles [VCSGit, VCSMercurial, VCSDarcs] projRoot >>= buildChecker
44+
(FileIgnoredChecker isFileIgnored) <-
45+
case mChecker of
46+
Left err ->
47+
do putStrLn $ "Failed to parse VCS's ignore file: " ++ err
48+
return $ FileIgnoredChecker (const False)
49+
Right chk -> return chk
4050

4151
let onChange = atomically $ writeTVar dirtyVar True
4252

@@ -67,7 +77,7 @@ fileWatch inner = withManager $ \manager -> do
6777
return Nothing
6878
startListening = Map.mapWithKey $ \dir () -> do
6979
let dir' = fromString $ toFilePath dir
70-
listen <- watchDir manager dir' (const True) (const onChange)
80+
listen <- watchDir manager dir' (not . isFileIgnored . eventPath) (const onChange)
7181
return $ Just listen
7282

7383
let watchInput = do

src/Stack/Options.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ buildOptsParser cmd =
154154

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

159159
keepGoing = maybeBoolFlags
160160
"keep-going"

src/main/Main.hs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -666,7 +666,14 @@ cleanCmd () go = withBuildConfigAndLock go (\_ -> clean)
666666
buildCmd :: Maybe (Text, Text) -- ^ option synonym
667667
-> BuildOpts -> GlobalOpts -> IO ()
668668
buildCmd moptionSynonym opts go
669-
| boptsFileWatch opts = fileWatch inner
669+
| boptsFileWatch opts =
670+
let getProjectRoot =
671+
do (manager, lc) <- loadConfigWithOpts go
672+
bconfig <-
673+
runStackLoggingTGlobal manager go $
674+
lcLoadBuildConfig lc (globalResolver go)
675+
return (bcRoot bconfig)
676+
in fileWatch getProjectRoot inner
670677
| otherwise = inner $ const $ return ()
671678
where
672679
inner setLocalFiles = withBuildConfigAndLock go $ \lk -> do

stack.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ library
133133
, http-client-tls >= 0.2.2
134134
, http-conduit >= 2.1.7
135135
, http-types >= 0.8.6
136+
, ignore >= 0.1
136137
, lifted-base
137138
, monad-control
138139
, monad-logger >= 0.3.13.1

stack.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
resolver: lts-3.0
2-
2+
extra-deps:
3+
- ignore-0.1.0.0
34
image:
45
container:
56
base: "fpco/ubuntu-with-libgmp:14.04"

0 commit comments

Comments
 (0)