initremote type=git probe uuid
rather than matching path of an existing remote to find the uuid. The main benefit of this is that locations not using ssh:// will work now, including both paths and host:/path The other benefit is that it's a simpler interface, no need to have an existing remote with the same url and some other name. Although that will still work of course. This does rely on tryGitConfigRead working when given a Git.Repo that is not a remote. Luckily, it works fine that way. Also, tryGitConfigRead will auto-init a local repo that has a git-annex branch. I did not enable auto-init of ssh repos though. The uuid discovery actually happens twice; initremote discovers it, and uses it to store the special remote config, but does not set it in the git remote it creates. So the next run of git-annex does uuid discovery again, and caches it that time. This could be improved for a tiny speedup, but I didn't want to complicate things for that in this commit. Sponsored-by: Dartmouth College's DANDI project
This commit is contained in:
parent
2f509e529e
commit
14584e7a38
5 changed files with 33 additions and 35 deletions
|
@ -2,6 +2,10 @@ git-annex (10.20220526) UNRELEASED; urgency=medium
|
||||||
|
|
||||||
* init: Added --no-autoenable option.
|
* init: Added --no-autoenable option.
|
||||||
* info: Added --autoenable option.
|
* info: Added --autoenable option.
|
||||||
|
* initremote: Improve handling of type=git special remotes.
|
||||||
|
The location value no longer needs to match the url of an existing
|
||||||
|
git remote, and locations not using ssh:// will work now, including
|
||||||
|
both paths and host:/path
|
||||||
|
|
||||||
-- Joey Hess <id@joeyh.name> Wed, 01 Jun 2022 13:23:05 -0400
|
-- Joey Hess <id@joeyh.name> Wed, 01 Jun 2022 13:23:05 -0400
|
||||||
|
|
||||||
|
|
|
@ -107,11 +107,11 @@ list autoinit = do
|
||||||
Git.Construct.remoteNamed n $
|
Git.Construct.remoteNamed n $
|
||||||
Git.Construct.fromRemoteLocation (Git.fromConfigValue url) g
|
Git.Construct.fromRemoteLocation (Git.fromConfigValue url) g
|
||||||
|
|
||||||
{- Git remotes are normally set up using standard git command, not
|
{- Git remotes are normally set up using standard git commands, not
|
||||||
- git-annex initremote and enableremote.
|
- git-annex initremote and enableremote.
|
||||||
-
|
-
|
||||||
- For initremote, the git remote must already be set up, and have a uuid.
|
- For initremote, probe the location to find the uuid.
|
||||||
- Initremote simply remembers its location.
|
- and set up a git remote.
|
||||||
-
|
-
|
||||||
- enableremote simply sets up a git remote using the stored location.
|
- enableremote simply sets up a git remote using the stored location.
|
||||||
- No attempt is made to make the remote be accessible via ssh key setup,
|
- No attempt is made to make the remote be accessible via ssh key setup,
|
||||||
|
@ -119,17 +119,16 @@ list autoinit = do
|
||||||
-}
|
-}
|
||||||
gitSetup :: SetupStage -> Maybe UUID -> Maybe CredPair -> RemoteConfig -> RemoteGitConfig -> Annex (RemoteConfig, UUID)
|
gitSetup :: SetupStage -> Maybe UUID -> Maybe CredPair -> RemoteConfig -> RemoteGitConfig -> Annex (RemoteConfig, UUID)
|
||||||
gitSetup Init mu _ c _ = do
|
gitSetup Init mu _ c _ = do
|
||||||
let location = fromMaybe (giveup "Specify location=url") $
|
let location = maybe (giveup "Specify location=url") fromProposedAccepted $
|
||||||
Url.parseURIRelaxed . fromProposedAccepted
|
M.lookup locationField c
|
||||||
=<< M.lookup locationField c
|
r <- inRepo $ Git.Construct.fromRemoteLocation location
|
||||||
rs <- Annex.getGitRemotes
|
r' <- tryGitConfigRead False r False
|
||||||
u <- case filter (\r -> Git.location r == Git.Url location) rs of
|
let u = getUncachedUUID r'
|
||||||
[r] -> getRepoUUID r
|
if u == NoUUID
|
||||||
[] -> giveup "could not find existing git remote with specified location"
|
then gitveup "git repository does not have an annex uuid"
|
||||||
_ -> giveup "found multiple git remotes with specified location"
|
else if isNothing mu || mu == Just u
|
||||||
if isNothing mu || mu == Just u
|
then enableRemote (Just u) c
|
||||||
then return (c, u)
|
else giveup "git repository does not have specified uuid"
|
||||||
else error "git remote did not have specified uuid"
|
|
||||||
gitSetup (Enable _) mu _ c _ = enableRemote mu c
|
gitSetup (Enable _) mu _ c _ = enableRemote mu c
|
||||||
gitSetup (AutoEnable _) mu _ c _ = enableRemote mu c
|
gitSetup (AutoEnable _) mu _ c _ = enableRemote mu c
|
||||||
|
|
||||||
|
@ -142,7 +141,7 @@ enableRemote (Just u) c = do
|
||||||
, Param $ maybe (giveup "no location") fromProposedAccepted (M.lookup locationField c)
|
, Param $ maybe (giveup "no location") fromProposedAccepted (M.lookup locationField c)
|
||||||
]
|
]
|
||||||
return (c, u)
|
return (c, u)
|
||||||
enableRemote Nothing _ = error "unable to enable git remote with no specified uuid"
|
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
|
{- It's assumed to be cheap to read the config of non-URL remotes, so this is
|
||||||
- done each time git-annex is run in a way that uses remotes, unless
|
- done each time git-annex is run in a way that uses remotes, unless
|
||||||
|
|
|
@ -66,3 +66,5 @@ above
|
||||||
|
|
||||||
[[!meta author=yoh]]
|
[[!meta author=yoh]]
|
||||||
[[!tag projects/dandi]]
|
[[!tag projects/dandi]]
|
||||||
|
|
||||||
|
> [[fixed|done]] --[[Joey]]
|
||||||
|
|
|
@ -0,0 +1,10 @@
|
||||||
|
[[!comment format=mdwn
|
||||||
|
username="joey"
|
||||||
|
subject="""comment 2"""
|
||||||
|
date="2022-06-09T17:04:23Z"
|
||||||
|
content="""
|
||||||
|
Implemented probing of the uuid of the repo location. Which may change
|
||||||
|
how you use this feature. Although the old roundabout method of having an
|
||||||
|
existing git remote and running initremote with the same location will
|
||||||
|
work too, it's not neccessary to do that anymore.
|
||||||
|
"""]]
|
|
@ -7,29 +7,12 @@ git-annex and git will use the remote the same as any normal git remote,
|
||||||
but its url will be recorded in the repository. One benefit of doing this
|
but its url will be recorded in the repository. One benefit of doing this
|
||||||
is it allows [[git-annex init|git-annex-init]] to autoenable the remote.
|
is it allows [[git-annex init|git-annex-init]] to autoenable the remote.
|
||||||
|
|
||||||
First you need a regular git remote with the url that you want to use for
|
To set up such a special remote:
|
||||||
the special remote.
|
|
||||||
|
|
||||||
git remote add tmpremote ssh://...
|
|
||||||
|
|
||||||
Then, to set up the special remote:
|
|
||||||
|
|
||||||
git annex initremote myremote type=git location=ssh://... autoenable=true
|
git annex initremote myremote type=git location=ssh://... autoenable=true
|
||||||
|
|
||||||
The location must be the same url as the existing git remote.
|
|
||||||
|
|
||||||
Now `git annex init` in each clone of the repository will autoenable myremote.
|
Now `git annex init` in each clone of the repository will autoenable myremote.
|
||||||
|
|
||||||
Note that the name of the git remote (`tmpremote` above) has to be
|
|
||||||
different than the name you later use for the special remote,
|
|
||||||
since [[git-annex initremote|git-annex-initremote]] will refuse to use the name of an existing
|
|
||||||
remote. To work around that, you could finish by removing `tmpremote` and
|
|
||||||
enable the special remote:
|
|
||||||
|
|
||||||
git remote remove tmpremote
|
|
||||||
git annex enableremote myremote
|
|
||||||
|
|
||||||
This only works for git repositories that have a git-annex uuid set,
|
This only works for git repositories that have a git-annex uuid set,
|
||||||
because git-annex thinks about special remotes in terms of their uuid. So
|
because special remotes have to have a uuid. So it cannot be used
|
||||||
it cannot be used with a git remote hosted somewhere that does not have
|
with git repositories that are not git-annex repositories.
|
||||||
git-annex installed.
|
|
||||||
|
|
Loading…
Reference in a new issue