support enableremote of git repo changing eg autoenable=
authorJoey Hess <joeyh@joeyh.name>
Tue, 18 Apr 2023 18:00:02 +0000 (14:00 -0400)
committerJoey Hess <joeyh@joeyh.name>
Tue, 18 Apr 2023 18:00:24 +0000 (14:00 -0400)
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
Command/EnableRemote.hs
Remote/Git.hs
doc/bugs/Disabling_remote_auto-enabling_not_possible/comment_4_4f3e9f15fcc96cd98c6915ec68cc471f._comment

index 53e491a968bc170793bba75e3917dee3434d35d3..86cd04570a3cbbd34379f15b3249f54b470da55a 100644 (file)
--- 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 <id@joeyh.name>  Sat, 08 Apr 2023 13:57:18 -0400
 
index 0735db4ff0c8ffb46524774afe4656931b66f31f..99a713cd3bb43fb6919825c8cab6c16ba12e8cec 100644 (file)
@@ -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
index ef0226f6f7e84a3c1bf6bbffeeec8e04970334d2..14bb097c17185f583edce8a30dd7f7d1da88de98 100644 (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
index a5b62a1760d12651ee3b4e2e09b20b6f28e5fbc5..8b148644cfcd701d203857674f5b11ca629b40fa 100644 (file)
@@ -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.
 """]]