From 9315d96f700109da18f953534b0b5bab8d1440dd Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Mon, 29 Dec 2014 13:41:03 -0400 Subject: sync: Now supports remote groups, the same way git remote update does. --- Remote.hs | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'Remote.hs') diff --git a/Remote.hs b/Remote.hs index 65e725338..2f0bb2111 100644 --- a/Remote.hs +++ b/Remote.hs @@ -26,6 +26,7 @@ module Remote ( uuidDescriptions, byName, byName', + byNameOrGroup, byNameOnly, byNameWithUUID, byCost, @@ -94,7 +95,11 @@ addName desc n | otherwise = desc ++ " [" ++ n ++ "]" {- When a name is specified, looks up the remote matching that name. - - (Or it can be a UUID.) -} + - (Or it can be a UUID.) + - + - Throws an error if a name is specified and no matching remote can be + - found. + -} byName :: Maybe RemoteName -> Annex (Maybe Remote) byName Nothing = return Nothing byName (Just n) = either error Just <$> byName' n @@ -121,6 +126,14 @@ byName' n = go . filter matching <$> remoteList go (match:_) = Right match matching r = n == name r || toUUID n == uuid r +{- Finds the remote or remote group matching the name. -} +byNameOrGroup :: RemoteName -> Annex [Remote] +byNameOrGroup n = go =<< getConfigMaybe (ConfigKey ("remotes." ++ n)) + where + go (Just l) = concatMap maybeToList <$> + mapM (Remote.byName . Just) (split " " l) + go Nothing = maybeToList <$> Remote.byName (Just n) + {- Only matches remote name, not UUID -} byNameOnly :: RemoteName -> Annex (Maybe Remote) byNameOnly n = headMaybe . filter matching <$> remoteList -- cgit v1.2.3