support enableremote of git repo changing eg autoenable=

enableremote: Support enableremote of a git remote (that was previously set
up with initremote) when additional parameters such as autoenable= are
passed.

The enableremote special case for regular git repos is intended to handle
ones that don't have a UUID probed, and the user wants git-annex to
re-probe. So, that special case is still needed. But, in that special
case, the user is not passing any extra parameters. So, when there are
parameters, instead run the special remote setup code. That requires there
to be a uuid known already, and it allows changing things like autoenable=

Remote.Git.enableRemote changed to be a no-op if a git remote with the name
already exists. Which it generally will in this case.

Sponsored-by: Jack Hill on Patreon
This commit is contained in:
Joey Hess 2023-04-18 14:00:02 -04:00
parent 3a402a907f
commit 8728695b9c
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
4 changed files with 35 additions and 27 deletions

View file

@ -17,6 +17,9 @@ git-annex (10.20230408) UNRELEASED; urgency=medium
* init: Avoid autoenabling special remotes that have control characters * init: Avoid autoenabling special remotes that have control characters
in their names. in their names.
* whereused: Fix display of branch:file when run in a subdirectory. * whereused: Fix display of branch:file when run in a subdirectory.
* enableremote: Support enableremote of a git remote (that was previously
set up with initremote) when additional parameters such as autoenable=
are passed.
-- Joey Hess <id@joeyh.name> Sat, 08 Apr 2023 13:57:18 -0400 -- Joey Hess <id@joeyh.name> Sat, 08 Apr 2023 13:57:18 -0400

View file

@ -50,26 +50,25 @@ start (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes
-- other remote with the same name -- other remote with the same name
([], l) -> use l ([], l) -> use l
(l, _) -> use l (l, _) -> use l
go (r:_) = do go (r:_)
-- This could be either a normal git remote or a special | not (null rest) = go []
-- remote that has an url (eg gcrypt). | otherwise = do
rs <- Remote.remoteList -- This could be either a normal git remote or a special
case filter (\rmt -> Remote.name rmt == name) rs of -- remote that has an url (eg gcrypt).
(rmt:_) | Remote.remotetype rmt == Remote.Git.remote -> rs <- Remote.remoteList
startNormalRemote name rest r case filter (\rmt -> Remote.name rmt == name) rs of
_ -> go [] (rmt:_) | Remote.remotetype rmt == Remote.Git.remote ->
startNormalRemote name r
_ -> go []
-- Normal git remotes are special-cased; enableremote retries probing -- enableremote of a normal git remote with no added parameters is a special case
-- the remote uuid. -- that retries probing the remote uuid.
startNormalRemote :: Git.RemoteName -> [String] -> Git.Repo -> CommandStart startNormalRemote :: Git.RemoteName -> Git.Repo -> CommandStart
startNormalRemote name restparams r startNormalRemote name r = starting "enableremote (normal)" ai si $ do
| null restparams = starting "enableremote" ai si $ do setRemoteIgnore r False
setRemoteIgnore r False r' <- Remote.Git.configRead False r
r' <- Remote.Git.configRead False r u <- getRepoUUID r'
u <- getRepoUUID r' next $ return $ u /= NoUUID
next $ return $ u /= NoUUID
| otherwise = giveup $
"That is a normal git remote; passing these parameters does not make sense: " ++ unwords restparams
where where
ai = ActionItemOther (Just (UnquotedString name)) ai = ActionItemOther (Just (UnquotedString name))
si = SeekInput [name] si = SeekInput [name]
@ -105,8 +104,7 @@ performSpecialRemote t u oldc c gc mcu = do
cleanupSpecialRemote :: RemoteType -> UUID -> R.RemoteConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandCleanup cleanupSpecialRemote :: RemoteType -> UUID -> R.RemoteConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandCleanup
cleanupSpecialRemote t u c mcu = do cleanupSpecialRemote t u c mcu = do
case mcu of case mcu of
Nothing -> Nothing -> Logs.Remote.configSet u c
Logs.Remote.configSet u c
Just (SpecialRemote.ConfigFrom cu) -> do Just (SpecialRemote.ConfigFrom cu) -> do
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu) setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
Logs.Remote.configSet cu c Logs.Remote.configSet cu c

View file

@ -131,13 +131,18 @@ gitSetup (AutoEnable _) mu _ c _ = enableRemote mu c
enableRemote :: Maybe UUID -> RemoteConfig -> Annex (RemoteConfig, UUID) enableRemote :: Maybe UUID -> RemoteConfig -> Annex (RemoteConfig, UUID)
enableRemote (Just u) c = do enableRemote (Just u) c = do
inRepo $ Git.Command.run rs <- Annex.getGitRemotes
[ Param "remote" unless (any (\r -> Git.remoteName r == Just cname) rs) $
, Param "add" inRepo $ Git.Command.run
, Param $ fromMaybe (giveup "no name") (SpecialRemote.lookupName c) [ Param "remote"
, Param $ maybe (giveup "no location") fromProposedAccepted (M.lookup locationField c) , Param "add"
] , Param cname
, Param clocation
]
return (c, u) return (c, u)
where
cname = fromMaybe (giveup "no name") (SpecialRemote.lookupName c)
clocation = maybe (giveup "no location") fromProposedAccepted (M.lookup locationField c)
enableRemote Nothing _ = giveup "unable to enable git remote with no specified uuid" enableRemote Nothing _ = giveup "unable to enable git remote with no specified uuid"
{- It's assumed to be cheap to read the config of non-URL remotes, so this is {- It's assumed to be cheap to read the config of non-URL remotes, so this is

View file

@ -9,4 +9,6 @@ always fails with
That happens even when the repo is accessible. So there is no way to disable That happens even when the repo is accessible. So there is no way to disable
a normal git remote that has been initremoted with autoenable=true. a normal git remote that has been initremoted with autoenable=true.
Update: Fixed that.
"""]] """]]