diff --git a/Command/Import.hs b/Command/Import.hs index a51c1ecb7b..91d6eca362 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -104,12 +104,12 @@ seek o@(LocalImportOptions {}) = allowConcurrentOutput $ do `withPathContents` importFiles o seek o@(RemoteImportOptions {}) = allowConcurrentOutput $ do r <- getParsed (importFromRemote o) + unlessM (Remote.isImportSupported r) $ + giveup "That remote does not support imports." subdir <- maybe (pure Nothing) (Just <$$> inRepo . toTopFilePath) (importToSubDir o) - unlessM (Remote.isImportSupported remote) $ - giveup "That remote does not support imports." seekRemote r (importToBranch o) subdir startLocal :: GetFileMatcher -> DuplicateMode -> (FilePath, FilePath) -> CommandStart diff --git a/Command/Sync.hs b/Command/Sync.hs index 9663101f39..01a4e0e86f 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -39,6 +39,7 @@ import qualified Git.Merge import qualified Git.Types as Git import qualified Git.Ref import qualified Git +import Git.FilePath import qualified Remote.Git import Config import Config.GitConfig @@ -171,6 +172,7 @@ seek o = allowConcurrentOutput $ do dataremotes <- filter (\r -> Remote.uuid r /= NoUUID) <$> filterM (not <$$> liftIO . getDynamicConfig . remoteAnnexIgnore . Remote.gitconfig) remotes let exportremotes = filter (exportTree . Remote.config) dataremotes + let importremotes = filter (importTree . Remote.config) dataremotes if cleanupOption o then do @@ -187,11 +189,13 @@ seek o = allowConcurrentOutput $ do , map (withbranch . pullRemote o mergeConfig) gitremotes , [ mergeAnnex ] ] - + whenM shouldsynccontent $ do - -- Send content to any exports first, in - -- case that lets content be dropped from - -- other repositories. + mapM_ (withbranch . importRemote o mergeConfig) importremotes + + -- Send content to any exports before other + -- repositories, in case that lets content + -- be dropped from other repositories. exportedcontent <- withbranch $ seekExportContent (Just o) exportremotes syncedcontent <- withbranch $ @@ -225,10 +229,11 @@ mergeConfig :: [Git.Merge.MergeConfig] mergeConfig = [ Git.Merge.MergeNonInteractive -- In several situations, unrelated histories should be merged - -- together. This includes pairing in the assistant, and merging - -- from a remote into a newly created direct mode repo. + -- together. This includes pairing in the assistant, merging + -- from a remote into a newly created direct mode repo, + -- and an initial merge from an import from a special remote. -- (Once direct mode is removed, this could be changed, so only - -- the assistant uses it.) + -- the assistant and import from special remotes use it.) , Git.Merge.MergeUnrelatedHistories ] @@ -404,6 +409,23 @@ pullRemote o mergeconfig remote branch = stopUnless (pure $ pullOption o && want [Param "fetch", Param $ Remote.name remote] wantpull = remoteAnnexPull (Remote.gitconfig remote) +importRemote :: SyncOptions -> [Git.Merge.MergeConfig] -> Remote -> CurrBranch -> CommandSeek +importRemote o mergeconfig remote currbranch + | not (pullOption o) || not wantpull = noop + | otherwise = case remoteAnnexTrackingBranch (Remote.gitconfig remote) of + Nothing -> noop + Just tb -> do + let (b, s) = separate (== ':') (Git.fromRef tb) + let branch = Git.Ref b + let subdir = if null s + then Nothing + else Just (asTopFilePath s) + Command.Import.seekRemote remote branch subdir + void $ mergeRemote remote currbranch mergeconfig + (resolveMergeOverride o) + where + wantpull = remoteAnnexPull (Remote.gitconfig remote) + {- The remote probably has both a master and a synced/master branch. - Which to merge from? Well, the master has whatever latest changes - were committed (or pushed changes, if this is a bare remote), diff --git a/doc/todo/import_tree.mdwn b/doc/todo/import_tree.mdwn index 7192822a5f..2fb8d083a2 100644 --- a/doc/todo/import_tree.mdwn +++ b/doc/todo/import_tree.mdwn @@ -10,6 +10,16 @@ this. ## implementation notes +* renameExport is disabled in a way that makes export tree + complain unncessarily verbosely. Perhaps change renameExport + to a Maybe so it can know when it's not available. + +* Does export of master:subdir update the remote tracking branch right? + +* Does sync --content with remote.name.annex-tracking-branch=master:subdir + export the right tree and update the remote tracking branch right? + Does it import correctly? + * Need to support annex-tracking-branch configuration, which documentation says makes git-annex sync and assistant do imports.