From 8728695b9c1141e4c176b077c1cf9388e41823b2 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 18 Apr 2023 14:00:02 -0400 Subject: [PATCH] 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 --- CHANGELOG | 3 ++ Command/EnableRemote.hs | 40 +++++++++---------- Remote/Git.hs | 17 +++++--- ..._4f3e9f15fcc96cd98c6915ec68cc471f._comment | 2 + 4 files changed, 35 insertions(+), 27 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 53e491a968..86cd04570a 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -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 Sat, 08 Apr 2023 13:57:18 -0400 diff --git a/Command/EnableRemote.hs b/Command/EnableRemote.hs index 0735db4ff0..99a713cd3b 100644 --- a/Command/EnableRemote.hs +++ b/Command/EnableRemote.hs @@ -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 - -- 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 - _ -> go [] + 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 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 - 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 +-- 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 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 diff --git a/Remote/Git.hs b/Remote/Git.hs index ef0226f6f7..14bb097c17 100644 --- a/Remote/Git.hs +++ b/Remote/Git.hs @@ -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 diff --git a/doc/bugs/Disabling_remote_auto-enabling_not_possible/comment_4_4f3e9f15fcc96cd98c6915ec68cc471f._comment b/doc/bugs/Disabling_remote_auto-enabling_not_possible/comment_4_4f3e9f15fcc96cd98c6915ec68cc471f._comment index a5b62a1760..8b148644cf 100644 --- a/doc/bugs/Disabling_remote_auto-enabling_not_possible/comment_4_4f3e9f15fcc96cd98c6915ec68cc471f._comment +++ b/doc/bugs/Disabling_remote_auto-enabling_not_possible/comment_4_4f3e9f15fcc96cd98c6915ec68cc471f._comment @@ -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. """]]