From 582316f66f0e664d65c78e408807c535b4ef66e2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 23 Sep 2012 12:43:14 -0400 Subject: avoid webapp crash on startup when there's no ~/.gitconfig git config --list --global exits nonzero when there's no global config --- Git/Config.hs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) (limited to 'Git') diff --git a/Git/Config.hs b/Git/Config.hs index fb0c24bab..00d1ddba2 100644 --- a/Git/Config.hs +++ b/Git/Config.hs @@ -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) -- cgit v1.2.3