avoid webapp crash on startup when there's no ~/.gitconfig

git config --list --global exits nonzero when there's no global config
This commit is contained in:
Joey Hess 2012-09-23 12:43:14 -04:00
parent 377636850e
commit 582316f66f
2 changed files with 11 additions and 5 deletions

View file

@ -105,7 +105,7 @@ firstRun = do
putMVar v ""
takeMVar v
mainthread v _url htmlshim = do
browser <- webBrowser <$> Git.Config.global
browser <- maybe Nothing webBrowser <$> Git.Config.global
openBrowser browser htmlshim
_wait <- takeMVar v

View file

@ -58,11 +58,17 @@ read' repo = go repo
}
{- Gets the global git config, returning a dummy Repo containing it. -}
global :: IO Repo
global :: IO (Maybe Repo)
global = do
repo <- Git.Construct.fromUnknown
withHandle StdoutHandle createProcessSuccess p $
hRead repo
home <- myHomeDir
ifM (doesFileExist $ home </> ".gitconfig")
( do
repo <- Git.Construct.fromUnknown
repo' <- withHandle StdoutHandle createProcessSuccess p $
hRead repo
return $ Just repo'
, return Nothing
)
where
params = ["config", "--null", "--list", "--global"]
p = (proc "git" params)