summaryrefslogtreecommitdiff
path: root/Remote.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2013-03-05 15:39:42 -0400
committerGravatar Joey Hess <joey@kitenet.net>2013-03-05 15:43:56 -0400
commit5c46685ab3bc1f579e55d764d5887b7f4a208d65 (patch)
tree7bb19dd15cea25d8c3617e4a3e12e92c1a28ab64 /Remote.hs
parent349da7cd84ab7b5d4b602bc3ab51e3a548a1633a (diff)
two types of byName
Clean up from 5123a1a83aa3b954fe67629508bab5ccea0e4148. In some cases, looking up a remote by name even though it has no UUID is desirable. This includes git annex sync, which can operate on remotes without an annex, and XMPP pairing, which runs addRemote (with calls byName) before the UUID of the XMPP remote has been configured in git.
Diffstat (limited to 'Remote.hs')
-rw-r--r--Remote.hs18
1 files changed, 14 insertions, 4 deletions
diff --git a/Remote.hs b/Remote.hs
index 22e304de3..4f8b7cf6a 100644
--- a/Remote.hs
+++ b/Remote.hs
@@ -24,6 +24,7 @@ module Remote (
remoteMap,
uuidDescriptions,
byName,
+ byNameWithUUID,
byCost,
prettyPrintUUIDs,
prettyListUUIDs,
@@ -72,18 +73,27 @@ addName desc n
| otherwise = n ++ " (" ++ desc ++ ")"
{- When a name is specified, looks up the remote matching that name.
- - (Or it can be a UUID.) Only finds currently configured git remotes. -}
+ - (Or it can be a UUID.) -}
byName :: Maybe String -> Annex (Maybe Remote)
byName Nothing = return Nothing
byName (Just n) = either error Just <$> byName' n
+
+{- Like byName, but the remote must have a configured UUID. -}
+byNameWithUUID :: Maybe String -> Annex (Maybe Remote)
+byNameWithUUID n = do
+ v <- byName n
+ return $ checkuuid <$> v
+ where
+ checkuuid r
+ | uuid r == NoUUID = error $ "cannot determine uuid for " ++ name r
+ | otherwise = r
+
byName' :: String -> Annex (Either String Remote)
byName' "" = return $ Left "no remote specified"
byName' n = handle . filter matching <$> remoteList
where
handle [] = Left $ "there is no available git remote named \"" ++ n ++ "\""
- handle (match:_)
- | uuid match == NoUUID = Left $ "cannot determine uuid for " ++ name match
- | otherwise = Right match
+ handle (match:_) = Right match
matching r = n == name r || toUUID n == uuid r
{- Looks up a remote by name (or by UUID, or even by description),