sync: fix crash on first sync when no branch exists yet
This commit is contained in:
parent
4401df1e57
commit
2ddcba7a15
1 changed files with 19 additions and 7 deletions
|
@ -33,6 +33,7 @@ import Git.FileMode
|
||||||
|
|
||||||
import qualified Data.Set as S
|
import qualified Data.Set as S
|
||||||
import Data.Hash.MD5
|
import Data.Hash.MD5
|
||||||
|
import Control.Concurrent.MVar
|
||||||
|
|
||||||
def :: [Command]
|
def :: [Command]
|
||||||
def = [command "sync" (paramOptional (paramRepeating paramRemote))
|
def = [command "sync" (paramOptional (paramRepeating paramRemote))
|
||||||
|
@ -42,18 +43,29 @@ def = [command "sync" (paramOptional (paramRepeating paramRemote))
|
||||||
seek :: CommandSeek
|
seek :: CommandSeek
|
||||||
seek rs = do
|
seek rs = do
|
||||||
prepMerge
|
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
|
remotes <- syncRemotes rs
|
||||||
return $ concat
|
return $ concat
|
||||||
[ [ commit ]
|
[ [ commit ]
|
||||||
, [ mergeLocal branch ]
|
, [ withbranch mergeLocal ]
|
||||||
, [ pullRemote remote branch | remote <- remotes ]
|
, [ withbranch (pullRemote remote) | remote <- remotes ]
|
||||||
, [ mergeAnnex ]
|
, [ mergeAnnex ]
|
||||||
, [ pushLocal branch ]
|
, [ withbranch pushLocal ]
|
||||||
, [ pushRemote remote branch | remote <- remotes ]
|
, [ withbranch (pushRemote remote) | remote <- remotes ]
|
||||||
]
|
]
|
||||||
where
|
|
||||||
nobranch = error "no branch is checked out"
|
|
||||||
|
|
||||||
{- Merging may delete the current directory, so go to the top
|
{- Merging may delete the current directory, so go to the top
|
||||||
- of the repo. -}
|
- of the repo. -}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue