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.
This commit is contained in:
Joey Hess 2024-05-24 14:29:36 -04:00
parent 7d61a99da3
commit 22bf23782f
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
7 changed files with 69 additions and 25 deletions

View file

@ -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

View file

@ -1,6 +1,6 @@
{- git-annex command
-
- Copyright 2013-2023 Joey Hess <id@joeyh.name>
- Copyright 2013-2024 Joey Hess <id@joeyh.name>
-
- 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

View file

@ -1,6 +1,6 @@
{- git-annex command
-
- Copyright 2011-2023 Joey Hess <id@joeyh.name>
- Copyright 2011-2024 Joey Hess <id@joeyh.name>
-
- 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

View file

@ -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

View file

@ -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.

View file

@ -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

View file

@ -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.