add config-uuid to annex:: url for --sameas remotes

And use it to set annex-config-uuid in git config. This makes
using the origin special remote work after cloning.

Without the added Logs.Remote.configSet, instantiating the remote will
look at the annex-config-uuid's config in the remote log, which will be
empty, and so it will fail to find a special remote.

The added deletion of files in the alternatejournaldir is just to make
100% sure they don't get committed to the git-annex branch. Now that
they contain things that definitely should not be committed.
This commit is contained in:
Joey Hess 2024-05-29 12:07:41 -04:00
parent b0ff819850
commit e19916f54b
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
2 changed files with 33 additions and 12 deletions

View file

@ -500,12 +500,16 @@ genSpecialRemoteUrl rmt rcp
conv = escapeURIString isUnescapedInURIComponent conv = escapeURIString isUnescapedInURIComponent
. fromProposedAccepted . fromProposedAccepted
cs = M.toList $ M.filterWithKey (\k _ -> k `elem` safefields) c cs = M.toList (M.filterWithKey (\k _ -> k `elem` safefields) c)
++ case remoteAnnexConfigUUID (Remote.gitconfig rmt) of
Nothing -> []
Just cu -> [(Accepted "config-uuid", Accepted (fromUUID cu))]
c = unparsedRemoteConfig $ Remote.config rmt c = unparsedRemoteConfig $ Remote.config rmt
-- Hidden fields are used for internal stuff like ciphers -- Hidden fields are used for internal stuff like ciphers
-- that should not be included in the url. -- that should not be included in the url.
safefields = map parserForField $ safefields = map parserForField $
filter (\p -> fieldDesc p /= HiddenField) ps filter (\p -> fieldDesc p /= HiddenField) ps
knownfields = map parserForField ps knownfields = map parserForField ps
@ -544,8 +548,9 @@ withSpecialRemote cfg@(SpecialRemoteConfig {}) sab a = case specialRemoteName cf
-- Initialize a new special remote with the provided configuration -- Initialize a new special remote with the provided configuration
-- and name. -- and name.
initremote remotename = do initremote remotename = do
let c = M.insert SpecialRemote.nameField (Proposed remotename) let c = M.insert SpecialRemote.nameField (Proposed remotename) $
(specialRemoteConfig cfg) M.delete (Accepted "config-uuid") $
specialRemoteConfig cfg
t <- either giveup return (SpecialRemote.findType c) t <- either giveup return (SpecialRemote.findType c)
dummycfg <- liftIO dummyRemoteGitConfig dummycfg <- liftIO dummyRemoteGitConfig
(c', u) <- Remote.setup t Remote.Init (Just (specialRemoteUUID cfg)) (c', u) <- Remote.setup t Remote.Init (Just (specialRemoteUUID cfg))
@ -553,6 +558,17 @@ withSpecialRemote cfg@(SpecialRemoteConfig {}) sab a = case specialRemoteName cf
`onException` cleanupremote remotename `onException` cleanupremote remotename
Logs.Remote.configSet u c' Logs.Remote.configSet u c'
setConfig (remoteConfig c' "url") (specialRemoteUrl cfg) setConfig (remoteConfig c' "url") (specialRemoteUrl cfg)
case M.lookup (Accepted "config-uuid") (specialRemoteConfig cfg) of
Just cu -> do
setConfig (remoteAnnexConfig c' "config-uuid")
(fromProposedAccepted cu)
-- This is not quite the same as what is
-- usually stored to the git-annex branch
-- for the config-uuid, but it will work.
-- This change will never be committed to the
-- git-annex branch.
Logs.Remote.configSet (toUUID (fromProposedAccepted cu)) c'
Nothing -> noop
remotesChanged remotesChanged
getEnabledSpecialRemoteByName remotename >>= \case getEnabledSpecialRemoteByName remotename >>= \case
Just rmt -> return rmt Just rmt -> return rmt
@ -1070,15 +1086,17 @@ specialRemoteFromUrl sab a = withTmpDir "journal" $ \tmpdir -> do
c { annexAlwaysCommit = False } c { annexAlwaysCommit = False }
Annex.BranchState.changeState $ \st -> Annex.BranchState.changeState $ \st ->
st { alternateJournal = Just (toRawFilePath tmpdir) } st { alternateJournal = Just (toRawFilePath tmpdir) }
a `finally` cleanupInitialization sab a `finally` cleanupInitialization sab tmpdir
-- If the git-annex branch did not exist when this command started, -- If the git-annex branch did not exist when this command started,
-- it was created empty by this command, and this command has avoided -- it was created empty by this command, and this command has avoided
-- making any other commits to it. If nothing else has written to the -- making any other commits to it, writing any temporary annex branch
-- branch while this command was running, the branch will be deleted. -- changes to thre alternateJournal, which can now be discarded.
-- That allows for the git-annex branch that is fetched from the special --
-- remote to contain Differences, which would prevent it from being merged -- If nothing else has written to the branch while this command was running,
-- with the git-annex branch created by this command. -- the branch will be deleted. That allows for the git-annex branch that is
-- fetched from the special remote to contain Differences, which would prevent
-- it from being merged with the git-annex branch created by this command.
-- --
-- If there is still not a sibling git-annex branch, this deletes all annex -- If there is still not a sibling git-annex branch, this deletes all annex
-- objects for git bundles from the annex objects directory, and deletes -- objects for git bundles from the annex objects directory, and deletes
@ -1096,8 +1114,9 @@ specialRemoteFromUrl sab a = withTmpDir "journal" $ \tmpdir -> do
-- does not contain any hooks. Since initialization installs -- does not contain any hooks. Since initialization installs
-- hooks, have to work around that by not initializing, and -- hooks, have to work around that by not initializing, and
-- delete the git bundle objects. -- delete the git bundle objects.
cleanupInitialization :: StartAnnexBranch -> Annex () cleanupInitialization :: StartAnnexBranch -> FilePath -> Annex ()
cleanupInitialization sab = void $ tryNonAsync $ do cleanupInitialization sab alternatejournaldir = void $ tryNonAsync $ do
liftIO $ mapM_ removeFile =<< dirContents alternatejournaldir
case sab of case sab of
AnnexBranchExistedAlready _ -> noop AnnexBranchExistedAlready _ -> noop
AnnexBranchCreatedEmpty r -> AnnexBranchCreatedEmpty r ->

View file

@ -20,3 +20,5 @@ works, after cloning, fetching again fails:
joey@darkstar:~/tmp/newp2>git fetch origin joey@darkstar:~/tmp/newp2>git fetch origin
git-annex: no url configured for httpalso special remote git-annex: no url configured for httpalso special remote
> fixed that, [[done]] --[[Joey]]