From 8fec62d2991bc57aea161a62a2b999380afb0a3b Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Tue, 16 Oct 2012 00:02:14 -0400 Subject: [PATCH] A relative core.worktree is relative to the gitdir. Now that this is handled correctly, git-annex can be used in git submodules. Also, fixed infelicity where Git.CurrentRepo and Git.Config.updateLocation were both dealing with core.worktree. Now updateLocation handles it for Local as well as for LocalUnknown repos. --- Git/Config.hs | 29 +++++++++++++++------------- Git/CurrentRepo.hs | 2 +- debian/changelog | 2 ++ doc/bugs/submodule_path_problem.mdwn | 3 ++- 4 files changed, 21 insertions(+), 15 deletions(-) diff --git a/Git/Config.hs b/Git/Config.hs index 500c8aa0fe..cc9b27b698 100644 --- a/Git/Config.hs +++ b/Git/Config.hs @@ -93,7 +93,7 @@ hRead repo h = do store :: String -> Repo -> IO Repo store s repo = do let c = parse s - let repo' = updateLocation $ repo + repo' <- updateLocation $ repo { config = (M.map Prelude.head c) `M.union` config repo , fullconfig = M.unionWith (++) c (fullconfig repo) } @@ -106,16 +106,22 @@ store s repo = do - known. Once the config is read, this can be fixed up to a Local repo, - based on the core.bare and core.worktree settings. -} -updateLocation :: Repo -> Repo +updateLocation :: Repo -> IO Repo updateLocation r@(Repo { location = LocalUnknown d }) - | isBare r = newloc $ Local d Nothing - | otherwise = newloc $ Local (d ".git") (Just d) - where - newloc l = r { location = getworktree l } - getworktree l = case workTree r of - Nothing -> l - wt -> l { worktree = wt } -updateLocation r = r + | isBare r = updateLocation' r $ Local d Nothing + | otherwise = updateLocation' r $ Local (d ".git") (Just d) +updateLocation r@(Repo { location = l@(Local {}) }) = updateLocation' r l +updateLocation r = return r + +updateLocation' :: Repo -> RepoLocation -> IO Repo +updateLocation' r l = do + l' <- case getMaybe "core.worktree" r of + Nothing -> return l + Just d -> do + {- core.worktree is relative to the gitdir -} + top <- absPath $ gitdir l + return $ l { worktree = Just $ absPathFrom top d } + return $ r { location = l' } {- Parses git config --list or git config --null --list output into a - config map. -} @@ -142,6 +148,3 @@ isTrue s isBare :: Repo -> Bool isBare r = fromMaybe False $ isTrue =<< getMaybe "core.bare" r - -workTree :: Repo -> Maybe FilePath -workTree = getMaybe "core.worktree" diff --git a/Git/CurrentRepo.hs b/Git/CurrentRepo.hs index 861df1b64e..f82241ae28 100644 --- a/Git/CurrentRepo.hs +++ b/Git/CurrentRepo.hs @@ -31,7 +31,7 @@ get :: IO Repo get = do gd <- pathenv "GIT_DIR" r <- configure gd =<< maybe fromCwd fromPath gd - wt <- maybe (Git.Config.workTree r) Just <$> pathenv "GIT_WORK_TREE" + wt <- maybe (worktree $ location r) Just <$> pathenv "GIT_WORK_TREE" case wt of Nothing -> return r Just d -> do diff --git a/debian/changelog b/debian/changelog index 90cf813274..37ef03b356 100644 --- a/debian/changelog +++ b/debian/changelog @@ -11,6 +11,8 @@ git-annex (3.20121011) UNRELEASED; urgency=low scan is running and queueing new transfers for that remote. * The standalone binaries are now built to not use ssh connection caching, in order to work with old versions of ssh. + * A relative core.worktree is relative to the gitdir. Now that this is + handled correctly, git-annex can be used in git submodules. -- Joey Hess Fri, 12 Oct 2012 22:46:08 -0400 diff --git a/doc/bugs/submodule_path_problem.mdwn b/doc/bugs/submodule_path_problem.mdwn index 7885d02870..664e246bc6 100644 --- a/doc/bugs/submodule_path_problem.mdwn +++ b/doc/bugs/submodule_path_problem.mdwn @@ -51,5 +51,6 @@ Got: * The path in that config is relative to the config file: "worktree = ../../../../lib/submod" * Git-annex expect the path to be relative to the current directory, which is why it fails. - +> Impressive analysis, thanks. I've fixed handling of relative +> core.worktree. [[done]] --[[Joey]]