在我的下面的代码中,我使用callProcess来运行外部git pull
。我想要的是,如果git pull
在一个目录中失败,程序将跳过它并尝试下一个目录。但是使用我的代码,程序会停止并显示来自git的错误消息:
错误讯息:
我们在:/ home / nut / dev / haskell / haskellnews您目前不在 科。请指定要合并的分支。看到 git-pull(1)了解详情。
git pull <remote> <branch>
scripts-exe:callProcess:git&#34; pull&#34; (退出1):失败
我的代码:
src = sourceDirectory "/home/haskell" `catchC` (\(e :: MyException)-> liftIO $ throwIO $ MyException (show e))
.| C.mapM_ (\f ->
do
b <- liftIO . doesDirectoryExist $ f
case b of
True -> do liftIO . setCurrentDirectory $ f
bb <- liftIO . doesDirectoryExist $ ".git"
case bb of
True -> liftIO $ do
res <- try (callProcess "git" ["pull"]) :: IO (Either MyException ())
case res of
Right a -> putStrLn "we are good"
Left e -> putStrLn "bad git"
False -> liftIO . putStrLn $ "Not a git directory"
False -> do liftIO . putStrLn $ "Not a directory"
)
main :: IO ()
main = runConduitRes $ src