summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Annex.hs12
-rw-r--r--Command/Sync.hs3
2 files changed, 14 insertions, 1 deletions
diff --git a/Annex.hs b/Annex.hs
index 202c25e4f..e4c05c627 100644
--- a/Annex.hs
+++ b/Annex.hs
@@ -31,6 +31,7 @@ module Annex (
changeGitRepo,
getRemoteGitConfig,
withCurrentState,
+ changeDirectory,
) where
import Common
@@ -300,3 +301,14 @@ withCurrentState :: Annex a -> Annex (IO a)
withCurrentState a = do
s <- getState id
return $ eval s a
+
+{- It's not safe to use setCurrentDirectory in the Annex monad,
+ - because the git repo paths are stored relative.
+ - Instead, use this.
+ -}
+changeDirectory :: FilePath -> Annex ()
+changeDirectory d = do
+ r <- liftIO . Git.adjustPath absPath =<< gitRepo
+ liftIO $ setCurrentDirectory d
+ r' <- liftIO $ Git.relPath r
+ changeState $ \s -> s { repo = r' }
diff --git a/Command/Sync.hs b/Command/Sync.hs
index 2299306ed..0433153b1 100644
--- a/Command/Sync.hs
+++ b/Command/Sync.hs
@@ -29,6 +29,7 @@ import Annex.Hook
import qualified Git.Command
import qualified Git.LsFiles as LsFiles
import qualified Git.Branch
+import qualified Git.Types as Git
import qualified Git.Ref
import qualified Git
import qualified Remote.Git
@@ -107,7 +108,7 @@ seek rs = do
- of the repo. This also means that sync always acts on all files in the
- repository, not just on a subdirectory. -}
prepMerge :: Annex ()
-prepMerge = liftIO . setCurrentDirectory =<< fromRepo Git.repoPath
+prepMerge = Annex.changeDirectory =<< fromRepo Git.repoPath
syncBranch :: Git.Ref -> Git.Ref
syncBranch = Git.Ref.under "refs/heads/synced" . fromDirectBranch