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:
parent
3a402a907f
commit
8728695b9c
4 changed files with 35 additions and 27 deletions
|
@ -17,6 +17,9 @@ git-annex (10.20230408) UNRELEASED; urgency=medium
|
|||
* init: Avoid autoenabling special remotes that have control characters
|
||||
in their names.
|
||||
* 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
|
||||
|
||||
|
|
|
@ -50,26 +50,25 @@ start (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes
|
|||
-- other remote with the same name
|
||||
([], l) -> use l
|
||||
(l, _) -> use l
|
||||
go (r:_) = do
|
||||
go (r:_)
|
||||
| not (null rest) = go []
|
||||
| otherwise = do
|
||||
-- This could be either a normal git remote or a special
|
||||
-- remote that has an url (eg gcrypt).
|
||||
rs <- Remote.remoteList
|
||||
case filter (\rmt -> Remote.name rmt == name) rs of
|
||||
(rmt:_) | Remote.remotetype rmt == Remote.Git.remote ->
|
||||
startNormalRemote name rest r
|
||||
startNormalRemote name r
|
||||
_ -> go []
|
||||
|
||||
-- Normal git remotes are special-cased; enableremote retries probing
|
||||
-- the remote uuid.
|
||||
startNormalRemote :: Git.RemoteName -> [String] -> Git.Repo -> CommandStart
|
||||
startNormalRemote name restparams r
|
||||
| null restparams = starting "enableremote" ai si $ do
|
||||
-- enableremote of a normal git remote with no added parameters is a special case
|
||||
-- that retries probing the remote uuid.
|
||||
startNormalRemote :: Git.RemoteName -> Git.Repo -> CommandStart
|
||||
startNormalRemote name r = starting "enableremote (normal)" ai si $ do
|
||||
setRemoteIgnore r False
|
||||
r' <- Remote.Git.configRead False r
|
||||
u <- getRepoUUID r'
|
||||
next $ return $ u /= NoUUID
|
||||
| otherwise = giveup $
|
||||
"That is a normal git remote; passing these parameters does not make sense: " ++ unwords restparams
|
||||
where
|
||||
ai = ActionItemOther (Just (UnquotedString 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 t u c mcu = do
|
||||
case mcu of
|
||||
Nothing ->
|
||||
Logs.Remote.configSet u c
|
||||
Nothing -> Logs.Remote.configSet u c
|
||||
Just (SpecialRemote.ConfigFrom cu) -> do
|
||||
setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu)
|
||||
Logs.Remote.configSet cu c
|
||||
|
|
|
@ -131,13 +131,18 @@ gitSetup (AutoEnable _) mu _ c _ = enableRemote mu c
|
|||
|
||||
enableRemote :: Maybe UUID -> RemoteConfig -> Annex (RemoteConfig, UUID)
|
||||
enableRemote (Just u) c = do
|
||||
rs <- Annex.getGitRemotes
|
||||
unless (any (\r -> Git.remoteName r == Just cname) rs) $
|
||||
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)
|
||||
, 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
|
||||
|
|
|
@ -9,4 +9,6 @@ always fails with
|
|||
|
||||
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.
|
||||
|
||||
Update: Fixed that.
|
||||
"""]]
|
||||
|
|
Loading…
Reference in a new issue