summaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@gnu.kitenet.net>2012-09-23 12:43:14 -0400
committerGravatar Joey Hess <joey@gnu.kitenet.net>2012-09-23 12:43:14 -0400
commit582316f66f0e664d65c78e408807c535b4ef66e2 (patch)
treefdff2000d17c5588651174ceec682568ef658f64 /Git
parent377636850e154e74836016520c0b346251409242 (diff)
avoid webapp crash on startup when there's no ~/.gitconfig
git config --list --global exits nonzero when there's no global config
Diffstat (limited to 'Git')
-rw-r--r--Git/Config.hs14
1 files changed, 10 insertions, 4 deletions
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)