From ff141c093e8e975daab8bad41a80bf244f3f0afb Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 10 Mar 2023 11:41:52 -0400 Subject: [PATCH] include subdir when checking export branch is checked out sync: Fix a reversion that prevented sending files to exporttree=yes remotes when annex-tracking-branch was configured to branch:subdir (Introduced in version 10.20230214) Sponsored-by: Kevin Mueller on Patreon --- CHANGELOG | 3 +++ Command/Sync.hs | 23 ++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 2f0c8fc3cf..b5b4903a7b 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -2,6 +2,9 @@ git-annex (10.20230228) UNRELEASED; urgency=medium * Using git-annex view in an adjusted branch, or git-annex adjust in a view branch, will enter an adjusted view branch. + * sync: Fix a reversion that prevented sending files to exporttree=yes + remotes when annex-tracking-branch was configured to branch:subdir + (Introduced in version 10.20230214) * status: This command is deprecated because it was only needed in direct mode; git status --short is very similar. * Windows: Support long filenames in more (possibly all) of the code. diff --git a/Command/Sync.hs b/Command/Sync.hs index 8a977cfc2c..595d8f12b9 100644 --- a/Command/Sync.hs +++ b/Command/Sync.hs @@ -521,12 +521,8 @@ importRemote importcontent o remote currbranch | not (pullOption o) || not wantpull = noop | otherwise = case remoteAnnexTrackingBranch (Remote.gitconfig remote) of Nothing -> noop - Just tb -> do - let (b, p) = separate' (== (fromIntegral (ord ':'))) (Git.fromRef' tb) - let branch = Git.Ref b - let subdir = if S.null p - then Nothing - else Just (asTopFilePath p) + Just b -> do + let (branch, subdir) = splitRemoteAnnexTrackingBranchSubdir b if canImportKeys remote importcontent then do Command.Import.seekRemote remote branch subdir importcontent (CheckGitIgnore True) @@ -926,8 +922,12 @@ seekExportContent o rs (currbranch, _) = or <$> forM rs go Nothing -> cannotupdateexport r db Nothing True Just b -> do mtree <- inRepo $ Git.Ref.tree b + let addsubdir = case snd (splitRemoteAnnexTrackingBranchSubdir b) of + Just subdir -> \cb -> Git.Ref $ + Git.fromRef' cb <> ":" <> getTopFilePath subdir + Nothing -> id mcurrtree <- maybe (pure Nothing) - (inRepo . Git.Ref.tree) + (inRepo . Git.Ref.tree . addsubdir) currbranch mtbcommitsha <- Command.Export.getExportCommit r b case (mtree, mcurrtree, mtbcommitsha) of @@ -1029,3 +1029,12 @@ isImport = importTree . Remote.config isThirdPartyPopulated :: Remote -> Bool isThirdPartyPopulated = Remote.thirdPartyPopulated . Remote.remotetype + +splitRemoteAnnexTrackingBranchSubdir :: Git.Ref -> (Git.Ref, Maybe TopFilePath) +splitRemoteAnnexTrackingBranchSubdir tb = (branch, subdir) + where + (b, p) = separate' (== (fromIntegral (ord ':'))) (Git.fromRef' tb) + branch = Git.Ref b + subdir = if S.null p + then Nothing + else Just (asTopFilePath p)