enableremote: Avoid overwriting existing git remote when passed the uuid of a specialremote that was earlier initialized with the same name

This commit is contained in:
Joey Hess 2023-09-22 13:29:48 -04:00
parent 80ee107880
commit 41f4d0bda9
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 32 additions and 0 deletions

View file

@ -99,6 +99,16 @@ startSpecialRemote' _ _ _ _ _ =
performSpecialRemote :: PerformSpecialRemote
performSpecialRemote t u oldc c gc mcu = do
-- Avoid enabling a special remote if there is another remote
-- with the same name.
case SpecialRemote.lookupName c of
Nothing -> noop
Just name -> do
rs <- Remote.remoteList
case filter (\rmt -> Remote.name rmt == name) rs of
(rmt:_) | Remote.uuid rmt /= u ->
giveup $ "Not overwriting currently configured git remote named \"" ++ name ++ "\""
_ -> noop
(c', u') <- R.setup t (R.Enable oldc) (Just u) Nothing c gc
next $ cleanupSpecialRemote t u' c' mcu