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

@ -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