From f6f7ee71310df1dd409819bef15ce020e290f4a8 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 30 Dec 2011 18:52:24 -0400 Subject: [PATCH] automatically create the syncbranch --- Command/Sync.hs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/Command/Sync.hs b/Command/Sync.hs index 0979738485..85fffdda87 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -34,7 +34,7 @@ seek args = do remotes <- syncRemotes syncbranch args return $ concat $ [ [ commit ] - , [ mergeLocal branch ] + , [ mergeLocal branch syncbranch ] , [ pullRemote remote branch | remote <- remotes ] , [ mergeAnnex ] , [ pushLocal syncbranch ] @@ -63,28 +63,31 @@ commit = do [Param "-a", Param "-m", Param "git-annex automatic sync"] return True -mergeLocal :: Git.Ref -> CommandStart -mergeLocal branch = go =<< needmerge +mergeLocal :: Git.Ref -> Git.Ref -> CommandStart +mergeLocal branch syncbranch = go =<< needmerge where - mergebranch = Git.Ref.under "refs/heads/synced" branch needmerge = do - unlessM (inRepo $ Git.Ref.exists mergebranch) $ - error $ Git.Ref.describe mergebranch ++ " does not exist; create it to enable sync" - inRepo $ Git.Branch.changed branch mergebranch + unlessM (inRepo $ Git.Ref.exists syncbranch) $ + updateBranch syncbranch + inRepo $ Git.Branch.changed branch syncbranch go False = stop go True = do - showStart "merge" $ Git.Ref.describe mergebranch - next $ next $ mergeFromIfExists mergebranch + showStart "merge" $ Git.Ref.describe syncbranch + next $ next $ mergeFromIfExists syncbranch pushLocal :: Git.Ref -> CommandStart pushLocal syncbranch = go =<< inRepo (Git.Ref.exists syncbranch) where go False = stop go True = do - unlessM (updatebranch) $ - error $ "failed to update " ++ show syncbranch + updateBranch syncbranch stop - updatebranch = inRepo $ Git.Command.runBool "branch" + +updateBranch :: Git.Ref -> Annex () +updateBranch syncbranch = + unlessM go $ error $ "failed to update " ++ show syncbranch + where + go = inRepo $ Git.Command.runBool "branch" [ Param "-f" , Param $ show $ Git.Ref.base syncbranch ]