diff options
author | Joey Hess <joey@kitenet.net> | 2014-03-13 15:35:59 -0400 |
---|---|---|
committer | Joey Hess <joey@kitenet.net> | 2014-03-13 15:36:58 -0400 |
commit | a2854170f4e27d4a6b3f096625476ae5856fbe76 (patch) | |
tree | 57b103b805467de650ad78d359f36121a4f81545 /Remote.hs | |
parent | a7704b46fcfddd9722d6456987f1e1ef867cc7a0 (diff) |
Commands that allow specifying which repository to act on using the repository's description will now fail when multiple repositories match, rather than picking a repository at random.
So will --in=
Note that since limitIn is not used by preferred content expressions,
it's ok for it to throw an exception.
Diffstat (limited to 'Remote.hs')
-rw-r--r-- | Remote.hs | 34 |
1 files changed, 18 insertions, 16 deletions
@@ -37,6 +37,7 @@ module Remote ( keyPossibilities, keyPossibilitiesTrusted, nameToUUID, + nameToUUID', showTriedRemotes, showLocations, forceTrust, @@ -48,7 +49,6 @@ module Remote ( import qualified Data.Map as M import Text.JSON import Text.JSON.Generic -import Data.Tuple import Data.Ord import Common.Annex @@ -121,23 +121,25 @@ noRemoteUUIDMsg r = "cannot determine uuid for " ++ name r - and returns its UUID. Finds even repositories that are not - configured in .git/config. -} nameToUUID :: RemoteName -> Annex UUID -nameToUUID "." = getUUID -- special case for current repo -nameToUUID "here" = getUUID -nameToUUID "" = error "no remote specified" -nameToUUID n = byName' n >>= go +nameToUUID = either error return <=< nameToUUID' + +nameToUUID' :: RemoteName -> Annex (Either String UUID) +nameToUUID' "." = Right <$> getUUID -- special case for current repo +nameToUUID' "here" = Right <$> getUUID +nameToUUID' n = byName' n >>= go where - go (Right r) = case uuid r of - NoUUID -> error $ noRemoteUUIDMsg r - u -> return u - go (Left e) = fromMaybe (error e) <$> bydescription - bydescription = do + go (Right r) = return $ case uuid r of + NoUUID -> Left $ noRemoteUUIDMsg r + u -> Right u + go (Left e) = do m <- uuidMap - case M.lookup n $ transform swap m of - Just u -> return $ Just u - Nothing -> return $ byuuid m - byuuid m = M.lookup (toUUID n) $ transform double m - transform a = M.fromList . map a . M.toList - double (a, _) = (a, a) + return $ case M.keys (M.filter (== n) m) of + [u] -> Right u + [] -> let u = toUUID n + in case M.keys (M.filterWithKey (\k _ -> k == u) m) of + [] -> Left e + _ -> Right u + _us -> Left "Found multiple repositories with that description" {- Pretty-prints a list of UUIDs of remotes, for human display. - |