better handling of multiple repositories with the same name

Used to fail with a bad error message, indicating there was no
repository with the specified name, or something like that. Now, suggest
they use the uuid to disambiguate.

* info, enableremotemote, renameremote: Avoid a confusing message when more
  than one repository matches the user provided name.
* info: Exit nonzero when the input is not supported.

Sponsored-by: Kevin Mueller on Patreon
This commit is contained in:
Joey Hess 2023-02-13 14:30:54 -04:00
parent 826b225ca8
commit 452b080dba
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
6 changed files with 41 additions and 33 deletions

View file

@ -173,26 +173,33 @@ noRemoteUUIDMsg r = "cannot determine uuid for " ++ name r ++ " (perhaps you nee
- and returns its UUID. Finds even repositories that are not
- configured in .git/config. -}
nameToUUID :: RemoteName -> Annex UUID
nameToUUID = either giveup return <=< nameToUUID'
nameToUUID n = nameToUUID' n >>= \case
([u], _) -> return u
(_, msg) -> giveup msg
nameToUUID' :: RemoteName -> Annex (Either String UUID)
nameToUUID' "." = Right <$> getUUID -- special case for current repo
nameToUUID' "here" = Right <$> getUUID
nameToUUID' n = byName' n >>= go
nameToUUID' :: RemoteName -> Annex ([UUID], String)
nameToUUID' n
| n == "." = currentrepo
| n == "here" = currentrepo
| otherwise = byName' n >>= go
where
currentrepo = mkone <$> getUUID
go (Right r) = return $ case uuid r of
NoUUID -> Left $ noRemoteUUIDMsg r
u -> Right u
NoUUID -> ([], noRemoteUUIDMsg r)
u -> mkone u
go (Left e) = do
m <- uuidDescMap
let descn = UUIDDesc (encodeBS n)
return $ case M.keys (M.filter (== descn) m) of
[u] -> Right u
[] -> let u = toUUID n
[] ->
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"
[] -> ([], e)
_ -> ([u], e)
us -> (us, "found multiple repositories with that description (use the uuid instead to disambiguate)")
mkone u = ([u], "found a remote")
{- Pretty-prints a list of UUIDs of remotes, with their descriptions,
- for human display.