include subdir when checking export branch is checked out
authorJoey Hess <joeyh@joeyh.name>
Fri, 10 Mar 2023 15:41:52 +0000 (11:41 -0400)
committerJoey Hess <joeyh@joeyh.name>
Fri, 10 Mar 2023 15:41:52 +0000 (11:41 -0400)
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
Command/Sync.hs

index 2f0c8fc3cf84bc21db85c5292126f46f6621969d..b5b4903a7b89ca3956a7ed3ca547c1a7e169f719 100644 (file)
--- 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.
index 8a977cfc2c60cda65e94298549279134d768f438..595d8f12b9dd5aa6cf4b15d00b7610f45ffc3d9c 100644 (file)
@@ -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)