From 22bf23782f5a3599f61f3fd1366d7674611b1717 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 24 May 2024 14:29:36 -0400 Subject: [PATCH] initremote, enableremote: Added --with-url to enable using git-remote-annex Also sets remote.name.fetch to a typical value, same as git remote add does. --- CHANGELOG | 2 ++ Command/EnableRemote.hs | 49 ++++++++++++++++++++++----------- Command/InitRemote.hs | 23 ++++++++++++++-- doc/git-annex-enableremote.mdwn | 5 ++++ doc/git-annex-initremote.mdwn | 5 ++++ doc/git-remote-annex.mdwn | 5 ++-- doc/todo/git-remote-annex.mdwn | 5 ---- 7 files changed, 69 insertions(+), 25 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 075cb9a5a9..9c0a26d0ba 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -3,6 +3,8 @@ git-annex (10.20240431) UNRELEASED; urgency=medium * git-remote-annex: New program which allows pushing a git repo to a git-annex special remote, and cloning from a special remote. (Based on Michael Hanke's git-remote-datalad-annex.) + * initremote, enableremote: Added --with-url to enable using + git-remote-annex. * fsck: Fix recent reversion that made it say it was checksumming files whose content is not present. * Avoid the --fast option preventing checksumming in some cases it diff --git a/Command/EnableRemote.hs b/Command/EnableRemote.hs index 4d04610cdd..3aeae7147e 100644 --- a/Command/EnableRemote.hs +++ b/Command/EnableRemote.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2013-2023 Joey Hess + - Copyright 2013-2024 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -19,6 +19,7 @@ import qualified Annex.SpecialRemote as SpecialRemote import qualified Remote import qualified Types.Remote as Remote import qualified Remote.Git +import qualified Command.InitRemote import Logs.UUID import Annex.UUID import Config @@ -34,18 +35,32 @@ cmd = withAnnexOptions [jsonOptions] $ command "enableremote" SectionSetup "enables git-annex to use a remote" (paramPair paramName $ paramOptional $ paramRepeating paramParamValue) - (withParams seek) + (seek <$$> optParser) -seek :: CmdParams -> CommandSeek -seek = withWords (commandAction . start) +data EnableRemoteOptions = EnableRemoteOptions + { cmdparams :: CmdParams + , withUrl :: Bool + } -start :: [String] -> CommandStart -start [] = unknownNameError "Specify the remote to enable." -start (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes +optParser :: CmdParamsDesc -> Parser EnableRemoteOptions +optParser desc = EnableRemoteOptions + <$> cmdParams desc + <*> switch + ( long "with-url" + <> short 'u' + <> help "configure remote with an annex:: url" + ) + +seek :: EnableRemoteOptions -> CommandSeek +seek o = withWords (commandAction . (start o)) (cmdparams o) + +start :: EnableRemoteOptions -> [String] -> CommandStart +start _ [] = unknownNameError "Specify the remote to enable." +start o (name:rest) = go =<< filter matchingname <$> Annex.getGitRemotes where matchingname r = Git.remoteName r == Just name go [] = deadLast name $ - startSpecialRemote name (Logs.Remote.keyValToConfig Proposed rest) + startSpecialRemote o name (Logs.Remote.keyValToConfig Proposed rest) go (r:_) | not (null rest) = go [] | otherwise = do @@ -69,8 +84,8 @@ startNormalRemote name r = starting "enableremote (normal)" ai si $ do ai = ActionItemOther (Just (UnquotedString name)) si = SeekInput [name] -startSpecialRemote :: Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart -startSpecialRemote = startSpecialRemote' "enableremote" performSpecialRemote +startSpecialRemote :: EnableRemoteOptions -> Git.RemoteName -> Remote.RemoteConfig -> [(UUID, Remote.RemoteConfig, Maybe (SpecialRemote.ConfigFrom UUID))] -> CommandStart +startSpecialRemote o = startSpecialRemote' "enableremote" (performSpecialRemote o) type PerformSpecialRemote = RemoteType -> UUID -> R.RemoteConfig -> R.RemoteConfig -> RemoteGitConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandPerform @@ -97,8 +112,8 @@ startSpecialRemote' cname perform name config ((u, c, mcu):[]) = startSpecialRemote' _ _ _ _ _ = giveup "Multiple remotes have that name. Either use git-annex renameremote to rename them, or specify the uuid of the remote." -performSpecialRemote :: PerformSpecialRemote -performSpecialRemote t u oldc c gc mcu = do +performSpecialRemote :: EnableRemoteOptions -> PerformSpecialRemote +performSpecialRemote o t u oldc c gc mcu = do -- Avoid enabling a special remote if there is another remote -- with the same name. case SpecialRemote.lookupName c of @@ -110,10 +125,10 @@ performSpecialRemote t u oldc c gc mcu = do giveup $ "Not overwriting currently configured git remote named \"" ++ name ++ "\"" _ -> noop (c', u') <- R.setup t (R.Enable oldc) (Just u) Nothing c gc - next $ cleanupSpecialRemote t u' c' mcu + next $ cleanupSpecialRemote o t u' c' mcu -cleanupSpecialRemote :: RemoteType -> UUID -> R.RemoteConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandCleanup -cleanupSpecialRemote t u c mcu = do +cleanupSpecialRemote :: EnableRemoteOptions -> RemoteType -> UUID -> R.RemoteConfig -> Maybe (SpecialRemote.ConfigFrom UUID) -> CommandCleanup +cleanupSpecialRemote o t u c mcu = do case mcu of Nothing -> Logs.Remote.configSet u c Just (SpecialRemote.ConfigFrom cu) -> do @@ -124,7 +139,9 @@ cleanupSpecialRemote t u c mcu = do Just r -> do repo <- R.getRepo r setRemoteIgnore repo False - unless (Remote.gitSyncableRemoteType t) $ + when (withUrl o) $ + Command.InitRemote.setAnnexUrl c + unless (Remote.gitSyncableRemoteType t || withUrl o) $ setConfig (remoteConfig c "skipFetchAll") (boolConfig True) return True diff --git a/Command/InitRemote.hs b/Command/InitRemote.hs index 92a8804265..09dab603dd 100644 --- a/Command/InitRemote.hs +++ b/Command/InitRemote.hs @@ -1,6 +1,6 @@ {- git-annex command - - - Copyright 2011-2023 Joey Hess + - Copyright 2011-2024 Joey Hess - - Licensed under the GNU AGPL version 3 or higher. -} @@ -21,6 +21,7 @@ import Types.GitConfig import Types.ProposedAccepted import Config import Git.Config +import Git.Types import qualified Data.Map as M import qualified Data.Text as T @@ -35,6 +36,7 @@ cmd = withAnnexOptions [jsonOptions] $ data InitRemoteOptions = InitRemoteOptions { cmdparams :: CmdParams , sameas :: Maybe (DeferredParse UUID) + , withUrl :: Bool , whatElse :: Bool , privateRemote :: Bool } @@ -43,6 +45,11 @@ optParser :: CmdParamsDesc -> Parser InitRemoteOptions optParser desc = InitRemoteOptions <$> cmdParams desc <*> optional parseSameasOption + <*> switch + ( long "with-url" + <> short 'u' + <> help "configure remote with an annex:: url" + ) <*> switch ( long "whatelse" <> short 'w' @@ -125,10 +132,22 @@ cleanup t u name c o = do cu <- liftIO genUUID setConfig (remoteAnnexConfig c "config-uuid") (fromUUID cu) Logs.Remote.configSet cu c - unless (Remote.gitSyncableRemoteType t) $ + when (withUrl o) $ + setAnnexUrl c + unless (Remote.gitSyncableRemoteType t || withUrl o) $ setConfig (remoteConfig c "skipFetchAll") (boolConfig True) return True +setAnnexUrl :: R.RemoteConfig -> Annex () +setAnnexUrl c = + getConfigMaybe (remoteConfig c "url") >>= \case + Just (ConfigValue _) -> noop + _ -> do + setConfig (remoteConfig c "url") "annex::" + setConfig (remoteConfig c "fetch") $ + "+refs/heads/*:refs/remotes/" ++ + getRemoteName c ++ "/*" + describeOtherParamsFor :: RemoteConfig -> RemoteType -> CommandPerform describeOtherParamsFor c t = do cp <- R.configParser t c diff --git a/doc/git-annex-enableremote.mdwn b/doc/git-annex-enableremote.mdwn index bcc6728183..7c0a70d558 100644 --- a/doc/git-annex-enableremote.mdwn +++ b/doc/git-annex-enableremote.mdwn @@ -59,6 +59,11 @@ has found didn't work before and gave up on using, setting # OPTIONS +* `--with-url` + + This configures the remote with an "annex::" url, which allows + git to push to and pull from it, using [[git-remote-annex]]. + * `--json` Enable JSON output. This is intended to be parsed by programs that use diff --git a/doc/git-annex-initremote.mdwn b/doc/git-annex-initremote.mdwn index eb1c1294eb..0e4514e823 100644 --- a/doc/git-annex-initremote.mdwn +++ b/doc/git-annex-initremote.mdwn @@ -38,6 +38,11 @@ want to use `git annex renameremote`. # OPTIONS +* `--with-url` + + This configures the remote with an "annex::" url, which allows + git to push to and pull from it, using [[git-remote-annex]]. + * `--whatelse` / `-w` Describe additional configuration parameters that you could specify. diff --git a/doc/git-remote-annex.mdwn b/doc/git-remote-annex.mdwn index 6dbe953716..60d38f201f 100644 --- a/doc/git-remote-annex.mdwn +++ b/doc/git-remote-annex.mdwn @@ -28,8 +28,9 @@ shorter url of "annex::" is sufficient. For example: git push foo master Configuring the url like that is automatically done when cloning from a -special remote, but not by [[git-annex-initremote]](1) and -[[git-annex-enableremote]](1). +special remote. To make [[git-annex-initremote]](1) and +[[git-annex-enableremote]](1) configure the url, pass them the `--with-url` +option. When a special remote needs some additional credentials to be provided, they are not included in the URL, and need to be provided when cloning from diff --git a/doc/todo/git-remote-annex.mdwn b/doc/todo/git-remote-annex.mdwn index c54c1d00e4..96959773be 100644 --- a/doc/todo/git-remote-annex.mdwn +++ b/doc/todo/git-remote-annex.mdwn @@ -26,11 +26,6 @@ This is implememented and working. Remaining todo list for it: There are some difficulties to doing this, including that RemoteConfig can have hidden fields that should be omitted. -* initremote/enableremote could have an option that configures the url to a - special remote to a annex:: url. This would make it easier to use - git-remote-annex, since the user would not need to set up the url - themselves. (Also it would then avoid setting `skipFetchAll = true`) - * datalad-annex supports cloning from the web special remote, using an url that contains the result of pushing to eg, a directory special remote.