From b6e7b40be4721595bafd3b1ea9c439cead07b7ff Mon Sep 17 00:00:00 2001 From: Joachim Breitner Date: Thu, 29 Dec 2011 20:50:57 +0100 Subject: [PATCH] By default, sync with all remotes having the synced/ branch --- Command/Sync.hs | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/Command/Sync.hs b/Command/Sync.hs index a9089463d4..cc88188892 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE BangPatterns #-} {- git-annex command - - Copyright 2011 Joey Hess @@ -26,10 +27,10 @@ def = [command "sync" (paramOptional (paramRepeating paramRemote)) -- syncing involves several operations, any of which can independantly fail seek :: CommandSeek seek args = do + !branch <- currentBranch remotes <- if null args - then defaultSyncRemotes + then defaultSyncRemotes branch else mapM Remote.byName args - branch <- currentBranch showStart "syncing" $ "branch " ++ Git.Ref.describe branch ++ " with remote repositories " ++ intercalate "," (map Remote.name remotes) showOutput return $ @@ -42,8 +43,16 @@ seek args = do [ pushLocal branch ] ++ [ pushRemote remote branch | remote <- remotes ] -defaultSyncRemotes :: Annex [Remote.Remote Annex] -defaultSyncRemotes = undefined +defaultSyncRemotes :: Git.Ref -> Annex [Remote.Remote Annex] +defaultSyncRemotes branch = mapM Remote.byName =<< process . L.unpack <$> inRepo showref + where + syncbranch = Git.Ref $ "refs/heads/synced/" ++ Git.Ref.describe branch + showref = Git.Command.pipeRead + [Param "show-ref", Param (Git.Ref.describe syncbranch)] + process = map getRemoteName . filter isRemote . map getBranchName . lines + isRemote r = "refs/remotes/" `isPrefixOf` r + getBranchName = snd . separate (== ' ') + getRemoteName = fst . separate (== '/') . snd . separate (== '/') . snd . separate (== '/') commit :: CommandStart commit = do