aboutsummaryrefslogtreecommitdiff
path: root/Git
diff options
context:
space:
mode:
authorGravatar Joey Hess <joeyh@joeyh.name>2016-05-06 12:26:37 -0400
committerGravatar Joey Hess <joeyh@joeyh.name>2016-05-06 12:26:44 -0400
commit2de35be7538023dd70e4c4b3ef984d1ae8a4c5a7 (patch)
treeae2da77522f5f5e6b31135bb1ddb55f12694456b /Git
parent7b33a5f2ab57f8546577bdc0532f925a3917fe78 (diff)
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
Diffstat (limited to 'Git')
-rw-r--r--Git/Env.hs14
1 files changed, 11 insertions, 3 deletions
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 =