diff options
author | Joey Hess <joeyh@joeyh.name> | 2016-02-25 13:46:31 -0400 |
---|---|---|
committer | Joey Hess <joeyh@joeyh.name> | 2016-02-25 13:46:31 -0400 |
commit | c5df5fd4fa172782fee20f966b04c3793df140a1 (patch) | |
tree | 8f490e8ebb8f3d1fddd4f1427b93e507103c578c /Git | |
parent | 65c51156f44a8e68eb8d3658894c2d5efa871f30 (diff) |
refactor
Diffstat (limited to 'Git')
-rw-r--r-- | Git/Env.hs | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/Git/Env.hs b/Git/Env.hs new file mode 100644 index 000000000..35a4eb04d --- /dev/null +++ b/Git/Env.hs @@ -0,0 +1,38 @@ +{- Adjusting the environment while running git commands. + - + - Copyright 2014-2016 Joey Hess <id@joeyh.name> + - + - Licensed under the GNU GPL version 3 or higher. + -} + +{-# LANGUAGE CPP #-} + +module Git.Env where + +import Git +import Utility.Env + +{- Adjusts the gitEnv of a Repo. Copies the system environment if the repo + - does not have any gitEnv yet. -} +adjustGitEnv :: Repo -> ([(String, String)] -> [(String, String)]) -> IO Repo +adjustGitEnv g adj = do + e <- maybe copyenv return (gitEnv g) + let e' = adj e + return $ g { gitEnv = Just e' } + where + copyenv = do +#ifdef __ANDROID__ + {- This should not be necessary on Android, but there is some + - weird getEnvironment breakage. See + - https://github.com/neurocyte/ghc-android/issues/7 + - Use getEnv to get some key environment variables that + - git expects to have. -} + let keyenv = words "USER PATH GIT_EXEC_PATH HOSTNAME HOME" + let getEnvPair k = maybe Nothing (\v -> Just (k, v)) <$> getEnv k + catMaybes <$> forM keyenv getEnvPair +#else + getEnvironment +#endif + +addGitEnv :: Repo -> String -> String -> IO Repo +addGitEnv g var val = adjustGitEnv g (addEntry var val) |