From e9b6efac5a3910c039ed19feda4e4545d9b40f2d Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Feb 2023 15:49:15 -0400 Subject: [PATCH] fix buggy sync to exporttree remote when annex-tracking-branch is not checked out sync: Fix a bug that caused files to be removed from an importtree=yes exporttree=yes special remote when the remote's annex-tracking-branch was not the currently checked out branch. Sponsored-by: Max Thoursie on Patreon --- CHANGELOG | 3 ++ Command/Sync.hs | 35 ++++++++++++------- ...hen_ran_in_other_than_tracking_branch.mdwn | 4 +++ 3 files changed, 30 insertions(+), 12 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 589fd96454..90c0a3b4d1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ git-annex (10.20230127) UNRELEASED; urgency=medium + * sync: Fix a bug that caused files to be removed from an + importtree=yes exporttree=yes special remote when the remote's + annex-tracking-branch was not the currently checked out branch. * S3: Support a region= configuration useful for some non-Amazon S3 implementations. This feature needs git-annex to be built with aws-0.24. * view: New field?=glob and ?tag syntax that includes a directory "_" diff --git a/Command/Sync.hs b/Command/Sync.hs index 054c3ebd71..d67193ddb3 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -897,9 +897,14 @@ syncFile ebloom rs af k = do ai = mkActionItem (k, af) si = SeekInput [] -{- When a remote has an annex-tracking-branch configuration, change the export - - to contain the current content of the branch. Otherwise, transfer any files - - that were part of an export but are not in the remote yet. +{- When a remote has an annex-tracking-branch configuration, and that branch + - is currently checked out, change the export to contain the current content + - of the branch. (If the branch is not currently checked out, anything + - imported from the remote will not yet have been merged into it yet and + - so exporting would delete files from the remote unexpectedly.) + - + - Otherwise, transfer any files that were part of a previous export + - but are not in the remote yet. - - Returns True if any file transfers were made. -} @@ -914,20 +919,26 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go Export.closeDb (\db -> Export.writeLockDbWhile db (go' r db)) go' r db = case remoteAnnexTrackingBranch (Remote.gitconfig r) of - Nothing -> cannotupdateexport r db Nothing + Nothing -> cannotupdateexport r db Nothing True Just b -> do mtree <- inRepo $ Git.Ref.tree b + mcurrtree <- maybe (pure Nothing) + (inRepo . Git.Ref.tree) + currbranch mtbcommitsha <- Command.Export.getExportCommit r b - case (mtree, mtbcommitsha) of - (Just tree, Just _) -> do - filteredtree <- Command.Export.filterExport r tree - Command.Export.changeExport r db filteredtree - Command.Export.fillExport r db filteredtree mtbcommitsha - _ -> cannotupdateexport r db (Just b) + case (mtree, mcurrtree, mtbcommitsha) of + (Just tree, Just currtree, Just _) + | tree == currtree -> do + filteredtree <- Command.Export.filterExport r tree + Command.Export.changeExport r db filteredtree + Command.Export.fillExport r db filteredtree mtbcommitsha + | otherwise -> cannotupdateexport r db (Just b) False + _ -> cannotupdateexport r db (Just b) True - cannotupdateexport r db mtb = do + cannotupdateexport r db mtb showwarning = do exported <- getExport (Remote.uuid r) - maybe noop (warncannotupdateexport r mtb exported) currbranch + when showwarning $ + maybe noop (warncannotupdateexport r mtb exported) currbranch fillexistingexport r db (exportedTreeishes exported) Nothing warncannotupdateexport r mtb exported currb = case mtb of diff --git a/doc/bugs/sync_with_export_remote_deletes_files_from_it_when_ran_in_other_than_tracking_branch.mdwn b/doc/bugs/sync_with_export_remote_deletes_files_from_it_when_ran_in_other_than_tracking_branch.mdwn index 27b04f707c..c5621e674b 100644 --- a/doc/bugs/sync_with_export_remote_deletes_files_from_it_when_ran_in_other_than_tracking_branch.mdwn +++ b/doc/bugs/sync_with_export_remote_deletes_files_from_it_when_ran_in_other_than_tracking_branch.mdwn @@ -12,3 +12,7 @@ remains. But bad. The problem seems to be that it assumes it's merged d/master into master, but that does not happen since master is not the current branch. And so it then updates d to look like master. --[[Joey]] + +> [[fixed|done]] by avoiding updating export remotes when +> the current branch tree is not the same as the tracking branch tree. +> --[[Joey]]