From d28b0a8bd06844b8b94e0295ad77cfc7fc003bd0 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 1 Mar 2019 14:32:45 -0400 Subject: [PATCH] use disconnected history for import tracking branch This avoids the first merge from it deleting all files in the current branch, which was very surpring and unwanted behavior. --- Command/Import.hs | 21 ++++++++++++--------- doc/git-annex-export.mdwn | 3 +++ doc/git-annex-import.mdwn | 18 ++++++++++++------ doc/todo/import_tree.mdwn | 18 ------------------ 4 files changed, 27 insertions(+), 33 deletions(-) diff --git a/Command/Import.hs b/Command/Import.hs index d0f35bc6cb..48bb0a300d 100644 --- a/Command/Import.hs +++ b/Command/Import.hs @@ -247,10 +247,15 @@ seekRemote :: Remote -> Branch -> Maybe TopFilePath -> CommandSeek seekRemote remote branch msubdir = allowConcurrentOutput $ do importtreeconfig <- case msubdir of Nothing -> return ImportTree - Just subdir -> frombranch Git.Ref.tree >>= \case - Nothing -> giveup $ "Unable to find base tree for branch " ++ fromRef branch - Just tree -> pure $ ImportSubTree subdir tree - parentcommit <- frombranch Git.Ref.sha + Just subdir -> + let mk tree = pure $ ImportSubTree subdir tree + in fromtrackingbranch Git.Ref.tree >>= \case + Just tree -> mk tree + Nothing -> inRepo (Git.Ref.tree branch) >>= \case + Just tree -> mk tree + Nothing -> giveup $ "Unable to find base tree for branch " ++ fromRef branch + + parentcommit <- fromtrackingbranch Git.Ref.sha let importcommitconfig = ImportCommitConfig parentcommit ManualCommit importmessage importable <- download importtreeconfig =<< enumerate @@ -258,12 +263,10 @@ seekRemote remote branch msubdir = allowConcurrentOutput $ do commitRemote remote branch tb parentcommit importtreeconfig importcommitconfig importable where importmessage = "import from " ++ Remote.name remote + tb = mkRemoteTrackingBranch remote branch - -- If the remote tracking branch already exists, get from it, - -- otherwise get from the branch. - frombranch a = inRepo (a (fromRemoteTrackingBranch tb)) >>= \case - Just v -> return (Just v) - Nothing -> inRepo (a branch) + + fromtrackingbranch a = inRepo $ a (fromRemoteTrackingBranch tb) enumerate = do showStart' "import" (Just (Remote.name remote)) diff --git a/doc/git-annex-export.mdwn b/doc/git-annex-export.mdwn index 1d01f2b7cd..eaaf337836 100644 --- a/doc/git-annex-export.mdwn +++ b/doc/git-annex-export.mdwn @@ -43,6 +43,9 @@ paragraph do not apply. Note that dropping content from such a remote is not supported. See individual special remotes' documentation for details of how to enable such versioning. +You can combine using `git annex export` to send changes to a special +remote with `git annex import` to fetch changes from a special remote. + The `git annex sync --content` command (and the git-annex assistant) can also be used to export a branch to a special remote, updating the special remote whenever the branch is changed. diff --git a/doc/git-annex-import.mdwn b/doc/git-annex-import.mdwn index 13dfcd9fa4..f9e1085a34 100644 --- a/doc/git-annex-import.mdwn +++ b/doc/git-annex-import.mdwn @@ -24,7 +24,11 @@ This way, something can be using the special remote for file storage, adding files, modifying files, and deleting files, and you can track those changes using git-annex. -This can only be used with special remotes that were configured with +You can combine using `git annex import` to fetch changes from a special +remote with `git annex export` to send your local changes to the special +remote. + +You can only import from special remotes that were configured with `importtree=yes` when set up with [[git-annex-initremote]](1). Only some kinds of special remotes will let you configure them this way. @@ -39,7 +43,13 @@ For example: git annex import master --from myremote git merge myremote/master -It's also posible to limit the import to a subdirectory, using the +Note that you may need to pass `--allow-unrelated-histories` the first time +you `git merge` from an import. Think of this as the remote being a +separate git repository with its own files. If you first +`git annex export` files to a remote, and then `git annex import` from it, +you won't need that option. + +You can also limit the import to a subdirectory, using the "branch:subdir" syntax. For example, if "camera" is a special remote that accesses a camera, and you want to import those into the photos directory, rather than to the root of your repository: @@ -47,10 +57,6 @@ directory, rather than to the root of your repository: git annex import master:photos --from camera git merge camera/master -You can combine using `git annex import` to fetch changes from a special -remote with `git annex export` to send your local changes to the special -remote. - The `git annex sync --content` command (and the git-annex assistant) can also be used to import from a special remote. To do this, you need to configure "remote..annex-tracking-branch" diff --git a/doc/todo/import_tree.mdwn b/doc/todo/import_tree.mdwn index a1724b8407..a199f89362 100644 --- a/doc/todo/import_tree.mdwn +++ b/doc/todo/import_tree.mdwn @@ -21,24 +21,6 @@ this. * export needs to use storeExportWithContentIdentifierM for importtree=yes remotes -* Merging the first import from a remote currently removes all local - files that are not present in the remote. But subsequent imports from the - remote do not delete newly added local files when merged. This seems - inconsistent and very surprising to the user. - - It happens because the remote tracking branch currently starts - from the local branch, and then has a commit added to it that contains - all files in the remote (and thus deletes the local files). - A subsequent import extents the tracking branch by another commit, so - merging that does not re-do the deletion. - - One fix would be to start the remote tracking branch not with the local - branch. Reflecting it being a perhaps entirely separate line of - development. Unless git-annex export were used first, and updated the - tracking branch, then the branch would start with what's exported, which - is fine. The downside of this is that git merge --allow-unrelated-histories - is needed to merge that unrelated history. - * export needs to update the tracking branch with what it exported * "git annex import master --from rmt" followed by "git annex import master:sub --from rmt"