diff options
author | Joey Hess <joey@kitenet.net> | 2013-10-17 13:34:27 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2013-10-17 13:34:27 -0400 |
commit | ecf8ed364c9ac1652da3fca823a0cb823a4b8337 (patch) | |
tree | a88c9b798979887d253dce1b126f233ce817bd38 | |
parent | 8844085101f074c1ad971598121b0ecdfccd9890 (diff) |
sync: fix crash on first sync when no branch exists yet
-rw-r--r-- | Command/Sync.hs | 26 |
1 files changed, 19 insertions, 7 deletions
diff --git a/Command/Sync.hs b/Command/Sync.hs index be929ae14..d792f156f 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -33,6 +33,7 @@ import Git.FileMode import qualified Data.Set as S import Data.Hash.MD5 +import Control.Concurrent.MVar def :: [Command] def = [command "sync" (paramOptional (paramRepeating paramRemote)) @@ -42,18 +43,29 @@ def = [command "sync" (paramOptional (paramRepeating paramRemote)) seek :: CommandSeek seek rs = do prepMerge - branch <- fromMaybe nobranch <$> inRepo Git.Branch.current + + -- There may not be a branch checked out until after the commit, + -- so only look it up once needed, and only look it up once. + mvar <- liftIO newEmptyMVar + let getbranch = ifM (liftIO $ isEmptyMVar mvar) + ( do + branch <- fromMaybe (error "no branch is checked out") + <$> inRepo Git.Branch.current + liftIO $ putMVar mvar branch + return branch + , liftIO $ readMVar mvar + ) + let withbranch a = a =<< getbranch + remotes <- syncRemotes rs return $ concat [ [ commit ] - , [ mergeLocal branch ] - , [ pullRemote remote branch | remote <- remotes ] + , [ withbranch mergeLocal ] + , [ withbranch (pullRemote remote) | remote <- remotes ] , [ mergeAnnex ] - , [ pushLocal branch ] - , [ pushRemote remote branch | remote <- remotes ] + , [ withbranch pushLocal ] + , [ withbranch (pushRemote remote) | remote <- remotes ] ] - where - nobranch = error "no branch is checked out" {- Merging may delete the current directory, so go to the top - of the repo. -} |