diff options
| -rw-r--r-- | Main.hs | 23 | ||||
| -rw-r--r-- | git-auto-acp.cabal | 1 |
2 files changed, 12 insertions, 12 deletions
@@ -18,7 +18,6 @@ import System.Clock import System.Environment import System.Exit import System.FSNotify -import System.FilePath.Glob import System.IO import System.Process @@ -78,24 +77,26 @@ opts = do <> showDefault pure Opts {..} -data Event - = AddBounce - | PushBounce - | Change Watch - | Finished - deriving (Show, Eq, Ord) - delaySec :: Float -> IO () delaySec = threadDelay . round . (1000000 *) +intervalPassed :: (Ord a, Num a) => a -> TimeSpec -> TimeSpec -> Bool intervalPassed i a b = 1000000000 * i <= fromIntegral (toNanoSecs $ diffTimeSpec a b) +runCmd :: String -> [String] -> IO () runCmd prog args = do st <- rawSystem prog args unless (st == ExitSuccess) . hPutStrLn stderr $ prog ++ " failed with args " ++ show args +data Event + = AddBounce + | PushBounce + | Change Watch + | Finished + deriving (Show, Eq, Ord) + main :: IO () main = do o <- @@ -109,7 +110,7 @@ main = do git <- fromMaybe "git" <$> lookupEnv "AUTO_ACP_GIT" withManager $ \fsmgr -> do chan <- newChan - done <- newEmptyMVar + done <- newEmptyMVar -- TODO catch sigterm -- start some watchers for_ (optWatches o) $ \w@(Watch path _) -> watchTree fsmgr path (const True) . const $ writeChan chan (Change w) @@ -139,8 +140,8 @@ main = do | not (S.null ws) , addsPending == 1 || intervalPassed (optAddCommitDelay o) now lastAdd -> do - for_ ws $ \(Watch p all) -> do - if all + for_ ws $ \(Watch p addAll) -> do + if addAll then runCmd git ["add", p] else runCmd git ["add", "--all", p] runCmd git ["commit", "--message", optMsg o] diff --git a/git-auto-acp.cabal b/git-auto-acp.cabal index 47aafe8..88aeced 100644 --- a/git-auto-acp.cabal +++ b/git-auto-acp.cabal @@ -31,7 +31,6 @@ executable git-auto-acp , containers , filepath , fsnotify - , Glob , optparse-applicative , process |
