prevent renaming to name already in use
Also, look up the name in the special remote log first, only fall back to remote name/uuid/description lookup if it fails. This should avoid violating least surprise in cases where the special remote they wish t rename is not enabled, or has a git remote with a different name.
This commit is contained in:
parent
a474304f1d
commit
c57695007b
1 changed files with 18 additions and 8 deletions
|
@ -8,6 +8,7 @@
|
||||||
module Command.RenameRemote where
|
module Command.RenameRemote where
|
||||||
|
|
||||||
import Command
|
import Command
|
||||||
|
import qualified Annex.SpecialRemote
|
||||||
import qualified Logs.Remote
|
import qualified Logs.Remote
|
||||||
import qualified Types.Remote as R
|
import qualified Types.Remote as R
|
||||||
import qualified Remote
|
import qualified Remote
|
||||||
|
@ -24,15 +25,24 @@ seek :: CmdParams -> CommandSeek
|
||||||
seek = withWords (commandAction . start)
|
seek = withWords (commandAction . start)
|
||||||
|
|
||||||
start :: [String] -> CommandStart
|
start :: [String] -> CommandStart
|
||||||
start (oldname:newname:[]) = do
|
start (oldname:newname:[]) = Annex.SpecialRemote.findExisting oldname >>= \case
|
||||||
m <- Logs.Remote.readRemoteLog
|
Just (u, cfg) -> Annex.SpecialRemote.findExisting newname >>= \case
|
||||||
Remote.nameToUUID' oldname >>= \case
|
Just _ -> giveup $ "The name " ++ newname ++ " is already used by a special remote."
|
||||||
|
Nothing -> go u cfg
|
||||||
|
-- Support lookup by uuid or description as well as remote name,
|
||||||
|
-- as a fallback when there is nothing with the name in the
|
||||||
|
-- special remote log.
|
||||||
|
Nothing -> Remote.nameToUUID' oldname >>= \case
|
||||||
Left e -> giveup e
|
Left e -> giveup e
|
||||||
Right u -> case M.lookup u m of
|
Right u -> do
|
||||||
Nothing -> giveup "That is not a special remote."
|
m <- Logs.Remote.readRemoteLog
|
||||||
Just cfg -> do
|
case M.lookup u m of
|
||||||
showStart' "rename" Nothing
|
Nothing -> giveup "That is not a special remote."
|
||||||
next $ perform u cfg newname
|
Just cfg -> go u cfg
|
||||||
|
where
|
||||||
|
go u cfg = do
|
||||||
|
showStart' "rename" Nothing
|
||||||
|
next $ perform u cfg newname
|
||||||
start _ = giveup "Specify an old name (or uuid or description) and a new name."
|
start _ = giveup "Specify an old name (or uuid or description) and a new name."
|
||||||
|
|
||||||
perform :: UUID -> R.RemoteConfig -> String -> CommandPerform
|
perform :: UUID -> R.RemoteConfig -> String -> CommandPerform
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue