further improved git cat-file error handling

This commit is contained in:
Joey Hess 2011-07-02 19:16:28 -04:00
parent bd5884d8dd
commit f626512b07

View file

@ -241,8 +241,7 @@ catFile file = do
[Param "cat-file", Param "--batch"] [Param "cat-file", Param "--batch"]
let gitcmd = join " " ("git" : toCommand cmd) let gitcmd = join " " ("git" : toCommand cmd)
(_, from, to) <- liftIO $ hPipeBoth "sh" (_, from, to) <- liftIO $ hPipeBoth "sh"
-- want stderr on stdin to see error messages ["-c", "exec " ++ gitcmd ++ " 2>/dev/null"]
["-c", "exec " ++ gitcmd ++ " 2>&1"]
setState state { catFileHandles = Just (from, to) } setState state { catFileHandles = Just (from, to) }
ask (from, to) ask (from, to)
ask (from, to) = liftIO $ do ask (from, to) = liftIO $ do
@ -255,7 +254,9 @@ catFile file = do
| length sha == Git.shaSize && | length sha == Git.shaSize &&
blob == "blob" -> handle from size blob == "blob" -> handle from size
| otherwise -> empty | otherwise -> empty
_ -> empty _
| header == want ++ " missing" -> empty
| otherwise -> error $ "unknown response from git cat-file " ++ header
handle from size = case reads size of handle from size = case reads size of
[(bytes, "")] -> readcontent from bytes [(bytes, "")] -> readcontent from bytes
_ -> empty _ -> empty