diff options
author | Joey Hess <joey@kitenet.net> | 2012-08-05 15:45:47 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2012-08-05 15:53:47 -0400 |
commit | 34fc0d358e53e4c615b1fe6fb80374a5302ccf1c (patch) | |
tree | 4d69aacaa9cc7f36c329c992728e8dd75899fda8 /Git | |
parent | 7478872a095ef9b05ce9124f9b1f5be2773065a8 (diff) |
fix crashes when run in a git repo that has been initted but has no master branch yet
Diffstat (limited to 'Git')
-rw-r--r-- | Git/Branch.hs | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Git/Branch.hs b/Git/Branch.hs index 4d239d8fc..098aa1a1a 100644 --- a/Git/Branch.hs +++ b/Git/Branch.hs @@ -5,6 +5,8 @@ - Licensed under the GNU GPL version 3 or higher. -} +{-# LANGUAGE BangPatterns #-} + module Git.Branch where import Common @@ -12,13 +14,22 @@ import Git import Git.Sha import Git.Command -{- The currently checked out branch. -} +{- The currently checked out branch. + - + - In a just initialized git repo before the first commit, + - symbolic-ref will show the master branch, even though that + - branch is not created yet. So, this also looks at show-ref HEAD + - to double-check. + -} current :: Repo -> IO (Maybe Git.Ref) -current r = parse <$> pipeRead [Param "symbolic-ref", Param "HEAD"] r - where - parse v - | null v = Nothing - | otherwise = Just $ Git.Ref $ firstLine v +current r = do + branch <- firstLine <$> pipeRead [Param "symbolic-ref", Param "HEAD"] r + if null branch + then return Nothing + else ifM (null <$> pipeRead [Param "show-ref", Param branch] r) + ( return Nothing + , return $ Just $ Git.Ref branch + ) {- Checks if the second branch has any commits not present on the first - branch. -} |