@@ -15,6 +15,7 @@ import Control.Concurrent.Extra (withNumCapabilities)
1515import Control.Concurrent.MVar (MVar , newEmptyMVar ,
1616 putMVar , tryReadMVar )
1717import Control.Concurrent.STM.Stats (dumpSTMStats )
18+ import Control.Exception.Safe as Safe
1819import Control.Monad.Extra (concatMapM , unless ,
1920 when )
2021import Control.Monad.IO.Class (liftIO )
@@ -456,16 +457,26 @@ expandFiles paths = do
456457 recurse y | " ." `isPrefixOf` takeFileName y = False -- skip .git etc
457458 recurse y = takeFileName y `notElem` [" dist" , " dist-newstyle" ] -- cabal directories
458459 in filter (\ y -> takeExtension y `elem` [" .hs" , " .lhs" ]) <$> IO. listFilesInside (return . recurse) x
459- (testGitExitCode, _, _) <- readProcessWithExitCode " git" [" status" ] " "
460+ git args = do
461+ mResult <- (Just <$> readProcessWithExitCode " git" args " " ) `Safe.catchAny` const (pure Nothing )
462+ pure $
463+ case mResult of
464+ Just (ExitSuccess , gitStdout, _) -> Just gitStout
465+ _ -> Nothing
466+ mHasGit <- git [" status" ]
460467 let findFiles =
461- case testGitExitCode of
462- ExitSuccess -> \ path -> do
463- let lookups = [path, path </> " *.hs" , path </> " *.lhs" ]
464- (trackedExitCode, trackedStdout, _) <- readProcessWithExitCode " git" (" ls-files" : lookups) " "
465- (untrackedExitCode, untrackedStdout, _) <- readProcessWithExitCode " git" (" ls-files" : " -o" : lookups) " "
466- if trackedExitCode == ExitSuccess && untrackedExitCode == ExitSuccess
467- then pure $ lines trackedStdout <> lines untrackedStdout
468- else haskellFind path
468+ case mHasGit of
469+ Just _ -> \ path -> do
470+ let lookups =
471+ if takeExtension path `elem` [" .hs" , " .lhs" ]
472+ then [path]
473+ else [path </> " *.hs" , path </> " *.lhs" ]
474+ gitLines args = fmap lines <$> git args
475+ mTracked <- gitLines (" ls-files" : lookups)
476+ mUntracked <- gitLines (" ls-files" : " -o" : lookups)
477+ case mTracked <> mUntracked of
478+ Nothing -> haskellFind path
479+ Just files -> pure files
469480 _ -> haskellFind
470481 flip concatMapM paths $ \ x -> do
471482 b <- IO. doesFileExist x
0 commit comments