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
This commit is contained in:
Joey Hess 2023-02-10 15:49:15 -04:00
parent 5c6e1f5178
commit e9b6efac5a
No known key found for this signature in database
GPG key ID: DB12DB0FF05F8F38
3 changed files with 30 additions and 12 deletions

View file

@ -1,5 +1,8 @@
git-annex (10.20230127) UNRELEASED; urgency=medium 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 * S3: Support a region= configuration useful for some non-Amazon S3
implementations. This feature needs git-annex to be built with aws-0.24. implementations. This feature needs git-annex to be built with aws-0.24.
* view: New field?=glob and ?tag syntax that includes a directory "_" * view: New field?=glob and ?tag syntax that includes a directory "_"

View file

@ -897,9 +897,14 @@ syncFile ebloom rs af k = do
ai = mkActionItem (k, af) ai = mkActionItem (k, af)
si = SeekInput [] si = SeekInput []
{- When a remote has an annex-tracking-branch configuration, change the export {- When a remote has an annex-tracking-branch configuration, and that branch
- to contain the current content of the branch. Otherwise, transfer any files - is currently checked out, change the export to contain the current content
- that were part of an export but are not in the remote yet. - 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. - Returns True if any file transfers were made.
-} -}
@ -914,20 +919,26 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go
Export.closeDb Export.closeDb
(\db -> Export.writeLockDbWhile db (go' r db)) (\db -> Export.writeLockDbWhile db (go' r db))
go' r db = case remoteAnnexTrackingBranch (Remote.gitconfig r) of go' r db = case remoteAnnexTrackingBranch (Remote.gitconfig r) of
Nothing -> cannotupdateexport r db Nothing Nothing -> cannotupdateexport r db Nothing True
Just b -> do Just b -> do
mtree <- inRepo $ Git.Ref.tree b mtree <- inRepo $ Git.Ref.tree b
mcurrtree <- maybe (pure Nothing)
(inRepo . Git.Ref.tree)
currbranch
mtbcommitsha <- Command.Export.getExportCommit r b mtbcommitsha <- Command.Export.getExportCommit r b
case (mtree, mtbcommitsha) of case (mtree, mcurrtree, mtbcommitsha) of
(Just tree, Just _) -> do (Just tree, Just currtree, Just _)
filteredtree <- Command.Export.filterExport r tree | tree == currtree -> do
Command.Export.changeExport r db filteredtree filteredtree <- Command.Export.filterExport r tree
Command.Export.fillExport r db filteredtree mtbcommitsha Command.Export.changeExport r db filteredtree
_ -> cannotupdateexport r db (Just b) 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) 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 fillexistingexport r db (exportedTreeishes exported) Nothing
warncannotupdateexport r mtb exported currb = case mtb of warncannotupdateexport r mtb exported currb = case mtb of

View file

@ -12,3 +12,7 @@ remains. But bad.
The problem seems to be that it assumes it's merged d/master into master, but 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 that does not happen since master is not the current branch. And so it then
updates d to look like master. --[[Joey]] 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]]