diff options
author | Joey Hess <joey@kitenet.net> | 2011-12-31 03:38:58 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2011-12-31 03:38:58 -0400 |
commit | a2ec2d3760f5ae17836ade3b0238dde7f9de5bd2 (patch) | |
tree | d15b531723ca09eb4060dd9c6ae03e4ad39da4cb | |
parent | 8a33573caff38b557fdf60c9547a78a5cc8c4ddc (diff) |
refactor and check for a detached HEAD
-rw-r--r-- | Command/Sync.hs | 9 | ||||
-rw-r--r-- | Git/Branch.hs | 8 |
2 files changed, 11 insertions, 6 deletions
diff --git a/Command/Sync.hs b/Command/Sync.hs index 6e78543ef..9426b1c00 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -22,7 +22,6 @@ import qualified Git import qualified Types.Remote import qualified Remote.Git -import qualified Data.ByteString.Lazy.Char8 as L import qualified Data.Map as M def :: [Command] @@ -32,7 +31,7 @@ def = [command "sync" (paramOptional (paramRepeating paramRemote)) -- syncing involves several operations, any of which can independently fail seek :: CommandSeek seek rs = do - !branch <- currentBranch + !branch <- fromMaybe nobranch <$> inRepo (Git.Branch.current) remotes <- syncRemotes rs return $ concat $ [ [ commit ] @@ -42,6 +41,8 @@ seek rs = do , [ pushLocal branch ] , [ pushRemote remote branch | remote <- remotes ] ] + where + nobranch = error "no branch is checked out" syncBranch :: Git.Ref -> Git.Ref syncBranch = Git.Ref.under "refs/heads/synced/" @@ -148,10 +149,6 @@ mergeAnnex = do Annex.Branch.forceUpdate stop -currentBranch :: Annex Git.Ref -currentBranch = Git.Ref . firstLine . L.unpack <$> - inRepo (Git.Command.pipeRead [Param "symbolic-ref", Param "HEAD"]) - mergeFrom :: Git.Ref -> CommandCleanup mergeFrom branch = do showOutput diff --git a/Git/Branch.hs b/Git/Branch.hs index cce56dcfa..98811a987 100644 --- a/Git/Branch.hs +++ b/Git/Branch.hs @@ -14,6 +14,14 @@ import Git import Git.Sha import Git.Command +{- The currently checked out branch. -} +current :: Repo -> IO (Maybe Git.Ref) +current r = parse <$> pipeRead [Param "symbolic-ref", Param "HEAD"] r + where + parse v + | L.null v = Nothing + | otherwise = Just $ Git.Ref $ firstLine $ L.unpack v + {- Checks if the second branch has any commits not present on the first - branch. -} changed :: Branch -> Branch -> Repo -> IO Bool |