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

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