From 2de35be7538023dd70e4c4b3ef984d1ae8a4c5a7 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Fri, 6 May 2016 12:26:37 -0400 Subject: Propigate GIT_DIR and GIT_WORK_TREE environment to external special remotes. Since git-annex unsets these when started, they have to be explicitly propigated. Also, this makes --git-dir and --work-tree settings be reflected in the environment. The need for this came up in https://github.com/DanielDent/git-annex-remote-rclone/issues/3 --- Git/Env.hs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) (limited to 'Git') diff --git a/Git/Env.hs b/Git/Env.hs index b0070e9a1..f41f3ad0e 100644 --- a/Git/Env.hs +++ b/Git/Env.hs @@ -9,12 +9,10 @@ module Git.Env where +import Common import Git import Git.Types import Utility.Env -#ifdef __ANDROID__ -import Common -#endif {- Adjusts the gitEnv of a Repo. Copies the system environment if the repo - does not have any gitEnv yet. -} @@ -41,6 +39,16 @@ adjustGitEnv g adj = do addGitEnv :: Repo -> String -> String -> IO Repo addGitEnv g var val = adjustGitEnv g (addEntry var val) +{- Environment variables to use when running a command. + - Includes GIT_DIR pointing at the repo, and GIT_WORK_TREE when the repo + - is not bare. Also includes anything added to the Repo's gitEnv, + - and a copy of the rest of the system environment. -} +propGitEnv :: Repo -> IO [(String, String)] +propGitEnv g = do + g' <- addGitEnv g "GIT_DIR" (localGitDir g) + g'' <- maybe (pure g') (addGitEnv g' "GIT_WORK_TREE") (repoWorkTree g) + return $ fromMaybe [] (gitEnv g'') + {- Use with any action that makes a commit to set metadata. -} commitWithMetaData :: CommitMetaData -> CommitMetaData -> (Repo -> IO a) -> Repo -> IO a commitWithMetaData authormetadata committermetadata a g = -- cgit v1.2.3