3a05d53761
No behavior changes (hopefully), just adding SeekInput and plumbing it through to the JSON display code for later use. Over the course of 2 grueling days. withFilesNotInGit reimplemented in terms of seekHelper should be the only possible behavior change. It seems to test as behaving the same. Note that seekHelper dummies up the SeekInput in the case where segmentPaths' gives up on sorting the expanded paths because there are too many input paths. When SeekInput later gets exposed as a json field, that will result in it being a little bit wrong in the case where 100 or more paths are passed to a git-annex command. I think this is a subtle enough problem to not matter. If it does turn out to be a problem, fixing it would require splitting up the input parameters into groups of < 100, which would make git ls-files run perhaps more than is necessary. May want to revisit this, because that fix seems fairly low-impact.
57 lines
1.9 KiB
Haskell
57 lines
1.9 KiB
Haskell
{- git-annex command
|
|
-
|
|
- Copyright 2019 Joey Hess <id@joeyh.name>
|
|
-
|
|
- Licensed under the GNU AGPL version 3 or higher.
|
|
-}
|
|
|
|
module Command.RenameRemote where
|
|
|
|
import Command
|
|
import qualified Annex.SpecialRemote
|
|
import Annex.SpecialRemote.Config (nameField, sameasNameField)
|
|
import qualified Logs.Remote
|
|
import qualified Types.Remote as R
|
|
import qualified Remote
|
|
import Types.ProposedAccepted
|
|
|
|
import qualified Data.Map as M
|
|
|
|
cmd :: Command
|
|
cmd = command "renameremote" SectionSetup
|
|
"changes name of special remote"
|
|
(paramPair paramName paramName)
|
|
(withParams seek)
|
|
|
|
seek :: CmdParams -> CommandSeek
|
|
seek = withWords (commandAction . start)
|
|
|
|
start :: [String] -> CommandStart
|
|
start ps@(oldname:newname:[]) = Annex.SpecialRemote.findExisting oldname >>= \case
|
|
Just (u, cfg, mcu) -> Annex.SpecialRemote.findExisting newname >>= \case
|
|
Just _ -> giveup $ "The name " ++ newname ++ " is already used by a special remote."
|
|
Nothing -> go u cfg mcu
|
|
-- 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
|
|
Right u -> do
|
|
m <- Logs.Remote.readRemoteLog
|
|
case M.lookup u m of
|
|
Nothing -> giveup "That is not a special remote."
|
|
Just cfg -> go u cfg Nothing
|
|
where
|
|
ai = ActionItemOther Nothing
|
|
si = SeekInput ps
|
|
go u cfg mcu = starting "rename" ai si $ perform u cfg mcu newname
|
|
start _ = giveup "Specify an old name (or uuid or description) and a new name."
|
|
|
|
perform :: UUID -> R.RemoteConfig -> Maybe (Annex.SpecialRemote.ConfigFrom UUID) -> String -> CommandPerform
|
|
perform u cfg mcu newname = do
|
|
let (namefield, cu) = case mcu of
|
|
Nothing -> (nameField, u)
|
|
Just (Annex.SpecialRemote.ConfigFrom u') -> (sameasNameField, u')
|
|
Logs.Remote.configSet cu (M.insert namefield (Proposed newname) cfg)
|
|
|
|
next $ return True
|