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:
parent
826b225ca8
commit
452b080dba
6 changed files with 41 additions and 33 deletions
|
@ -21,6 +21,9 @@ git-annex (10.20230127) UNRELEASED; urgency=medium
|
||||||
* sync: Warn when the adjusted basis ref cannot be found, as happens eg when
|
* sync: Warn when the adjusted basis ref cannot be found, as happens eg when
|
||||||
the user has renamed branches.
|
the user has renamed branches.
|
||||||
* Sped up view branch construction by 50%.
|
* Sped up view branch construction by 50%.
|
||||||
|
* 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.
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Mon, 06 Feb 2023 13:39:18 -0400
|
-- Joey Hess <id@joeyh.name> Mon, 06 Feb 2023 13:39:18 -0400
|
||||||
|
|
||||||
|
|
|
@ -79,10 +79,10 @@ startSpecialRemote name config [] = do
|
||||||
m <- SpecialRemote.specialRemoteMap
|
m <- SpecialRemote.specialRemoteMap
|
||||||
confm <- Logs.Remote.remoteConfigMap
|
confm <- Logs.Remote.remoteConfigMap
|
||||||
Remote.nameToUUID' name >>= \case
|
Remote.nameToUUID' name >>= \case
|
||||||
Right u | u `M.member` m ->
|
([u], _) | u `M.member` m ->
|
||||||
startSpecialRemote name config $
|
startSpecialRemote name config $
|
||||||
[(u, fromMaybe M.empty (M.lookup u confm), Nothing)]
|
[(u, fromMaybe M.empty (M.lookup u confm), Nothing)]
|
||||||
_ -> unknownNameError "Unknown remote name."
|
(_, msg) -> unknownNameError msg
|
||||||
startSpecialRemote name config ((u, c, mcu):[]) =
|
startSpecialRemote name config ((u, c, mcu):[]) =
|
||||||
starting "enableremote" ai si $ do
|
starting "enableremote" ai si $ do
|
||||||
let fullconfig = config `M.union` c
|
let fullconfig = config `M.union` c
|
||||||
|
|
|
@ -165,28 +165,24 @@ autoenableInfo = showCustom "info" (SeekInput []) $ do
|
||||||
itemInfo :: InfoOptions -> (SeekInput, String) -> Annex ()
|
itemInfo :: InfoOptions -> (SeekInput, String) -> Annex ()
|
||||||
itemInfo o (si, p) = ifM (isdir p)
|
itemInfo o (si, p) = ifM (isdir p)
|
||||||
( dirInfo o p si
|
( dirInfo o p si
|
||||||
, do
|
, Remote.byName' p >>= \case
|
||||||
v <- Remote.byName' p
|
|
||||||
case v of
|
|
||||||
Right r -> remoteInfo o r si
|
Right r -> remoteInfo o r si
|
||||||
Left _ -> do
|
Left _ -> Remote.nameToUUID' p >>= \case
|
||||||
v' <- Remote.nameToUUID' p
|
([], _) -> do
|
||||||
case v' of
|
|
||||||
Right u -> uuidInfo o u si
|
|
||||||
Left _ -> do
|
|
||||||
relp <- liftIO $ relPathCwdToFile (toRawFilePath p)
|
relp <- liftIO $ relPathCwdToFile (toRawFilePath p)
|
||||||
lookupKey relp >>= \case
|
lookupKey relp >>= \case
|
||||||
Just k -> fileInfo o (fromRawFilePath relp) si k
|
Just k -> fileInfo o (fromRawFilePath relp) si k
|
||||||
Nothing -> treeishInfo o p si
|
Nothing -> treeishInfo o p si
|
||||||
|
([u], _) -> uuidInfo o u si
|
||||||
|
(_us, msg) -> noInfo p si msg
|
||||||
)
|
)
|
||||||
where
|
where
|
||||||
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
isdir = liftIO . catchBoolIO . (isDirectory <$$> getFileStatus)
|
||||||
|
|
||||||
noInfo :: String -> SeekInput -> Annex ()
|
noInfo :: String -> SeekInput -> String -> Annex ()
|
||||||
noInfo s si = do
|
noInfo s si msg = do
|
||||||
showStart "info" (encodeBS s) si
|
showStart "info" (encodeBS s) si
|
||||||
showNote $ "not a directory or an annexed file or a treeish or a remote or a uuid"
|
giveup msg
|
||||||
showEndFail
|
|
||||||
|
|
||||||
dirInfo :: InfoOptions -> FilePath -> SeekInput -> Annex ()
|
dirInfo :: InfoOptions -> FilePath -> SeekInput -> Annex ()
|
||||||
dirInfo o dir si = showCustom (unwords ["info", dir]) si $ do
|
dirInfo o dir si = showCustom (unwords ["info", dir]) si $ do
|
||||||
|
@ -203,6 +199,7 @@ treeishInfo o t si = do
|
||||||
mi <- getTreeStatInfo o (Git.Ref (encodeBS t))
|
mi <- getTreeStatInfo o (Git.Ref (encodeBS t))
|
||||||
case mi of
|
case mi of
|
||||||
Nothing -> noInfo t si
|
Nothing -> noInfo t si
|
||||||
|
"not a directory or an annexed file or a treeish or a remote or a uuid"
|
||||||
Just i -> showCustom (unwords ["info", t]) si $ do
|
Just i -> showCustom (unwords ["info", t]) si $ do
|
||||||
stats <- selStats
|
stats <- selStats
|
||||||
(tostats (tree_name:tree_fast_stats False))
|
(tostats (tree_name:tree_fast_stats False))
|
||||||
|
|
|
@ -35,12 +35,12 @@ start ps@(oldname:newname:[]) = Annex.SpecialRemote.findExisting oldname >>= \ca
|
||||||
-- as a fallback when there is nothing with the name in the
|
-- as a fallback when there is nothing with the name in the
|
||||||
-- special remote log.
|
-- special remote log.
|
||||||
[] -> Remote.nameToUUID' oldname >>= \case
|
[] -> Remote.nameToUUID' oldname >>= \case
|
||||||
Left e -> giveup e
|
([u], _) -> do
|
||||||
Right u -> do
|
|
||||||
m <- Logs.Remote.remoteConfigMap
|
m <- Logs.Remote.remoteConfigMap
|
||||||
case M.lookup u m of
|
case M.lookup u m of
|
||||||
Nothing -> giveup "That is not a special remote."
|
Nothing -> giveup "That is not a special remote."
|
||||||
Just cfg -> go u cfg Nothing
|
Just cfg -> go u cfg Nothing
|
||||||
|
(_, msg) -> giveup msg
|
||||||
_ -> giveup $ "There are multiple special remotes named " ++ oldname ++ ". Provide instead the uuid or description of the remote to rename."
|
_ -> giveup $ "There are multiple special remotes named " ++ oldname ++ ". Provide instead the uuid or description of the remote to rename."
|
||||||
where
|
where
|
||||||
ai = ActionItemOther Nothing
|
ai = ActionItemOther Nothing
|
||||||
|
|
31
Remote.hs
31
Remote.hs
|
@ -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
|
- and returns its UUID. Finds even repositories that are not
|
||||||
- configured in .git/config. -}
|
- configured in .git/config. -}
|
||||||
nameToUUID :: RemoteName -> Annex UUID
|
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' :: RemoteName -> Annex ([UUID], String)
|
||||||
nameToUUID' "." = Right <$> getUUID -- special case for current repo
|
nameToUUID' n
|
||||||
nameToUUID' "here" = Right <$> getUUID
|
| n == "." = currentrepo
|
||||||
nameToUUID' n = byName' n >>= go
|
| n == "here" = currentrepo
|
||||||
|
| otherwise = byName' n >>= go
|
||||||
where
|
where
|
||||||
|
currentrepo = mkone <$> getUUID
|
||||||
|
|
||||||
go (Right r) = return $ case uuid r of
|
go (Right r) = return $ case uuid r of
|
||||||
NoUUID -> Left $ noRemoteUUIDMsg r
|
NoUUID -> ([], noRemoteUUIDMsg r)
|
||||||
u -> Right u
|
u -> mkone u
|
||||||
go (Left e) = do
|
go (Left e) = do
|
||||||
m <- uuidDescMap
|
m <- uuidDescMap
|
||||||
let descn = UUIDDesc (encodeBS n)
|
let descn = UUIDDesc (encodeBS n)
|
||||||
return $ case M.keys (M.filter (== descn) m) of
|
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
|
in case M.keys (M.filterWithKey (\k _ -> k == u) m) of
|
||||||
[] -> Left e
|
[] -> ([], e)
|
||||||
_ -> Right u
|
_ -> ([u], e)
|
||||||
_us -> Left "Found multiple repositories with that description"
|
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,
|
{- Pretty-prints a list of UUIDs of remotes, with their descriptions,
|
||||||
- for human display.
|
- for human display.
|
||||||
|
|
|
@ -43,3 +43,4 @@ local repository version: 10
|
||||||
### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
|
### Have you had any luck using git-annex before? (Sometimes we get tired of reading bug reports all day and a lil' positive end note does wonders)
|
||||||
|
|
||||||
|
|
||||||
|
> [[fixed|done]] --[[Joey]]
|
||||||
|
|
Loading…
Reference in a new issue