@@ -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,23 @@ 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
468+ case mHasGit of
469+ Just _ -> \ path -> do
463470 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
471+ gitLines args = fmap lines <$> git args
472+ mTracked <- gitlines (" ls-files" : lookups)
473+ mUntracked <- gitlines (" ls-files" : " -o" : lookups)
474+ case mTracked <> mUntracked of
475+ Nothing -> haskellFind path
476+ Just files -> pure files
469477 _ -> haskellFind
470478 flip concatMapM paths $ \ x -> do
471479 b <- IO. doesFileExist x
0 commit comments