aboutsummaryrefslogtreecommitdiff
path: root/Git/Branch.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-08-05 16:35:30 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-08-05 16:35:30 -0400
commit5ae1f75a39ffd26b23c8199998f502df78b9b75a (patch)
tree5ba650b428cd90b98a0380bed37df59efd3294a9 /Git/Branch.hs
parenta3f76fe696c603078621ccca6d7b17270cc7ef11 (diff)
handle case of adding populated drive to just created repo
The just created repo has no master branch commits yet. This is now handled, merging in the master branch from the populated drive.
Diffstat (limited to 'Git/Branch.hs')
-rw-r--r--Git/Branch.hs24
1 files changed, 17 insertions, 7 deletions
diff --git a/Git/Branch.hs b/Git/Branch.hs
index 098aa1a1a..f73ae5e2a 100644
--- a/Git/Branch.hs
+++ b/Git/Branch.hs
@@ -23,13 +23,23 @@ import Git.Command
-}
current :: Repo -> IO (Maybe Git.Ref)
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
- )
+ v <- currentUnsafe r
+ case v of
+ Nothing -> return Nothing
+ Just branch ->
+ ifM (null <$> pipeRead [Param "show-ref", Param $ show branch] r)
+ ( return Nothing
+ , return v
+ )
+
+{- The current branch, which may not really exist yet. -}
+currentUnsafe :: Repo -> IO (Maybe Git.Ref)
+currentUnsafe r = parse . firstLine
+ <$> pipeRead [Param "symbolic-ref", Param "HEAD"] r
+ where
+ parse l
+ | null l = Nothing
+ | otherwise = Just $ Git.Ref l
{- Checks if the second branch has any commits not present on the first
- branch. -}