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 "" putMVar v ""
takeMVar v takeMVar v
mainthread v _url htmlshim = do mainthread v _url htmlshim = do
browser <- webBrowser <$> Git.Config.global browser <- maybe Nothing webBrowser <$> Git.Config.global
openBrowser browser htmlshim openBrowser browser htmlshim
_wait <- takeMVar v _wait <- takeMVar v

View file

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