summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2012-06-04 21:52:36 -0400
committerGravatar Joey Hess <joey@kitenet.net>2012-06-04 21:52:36 -0400
commit13118136c07a621ecd1272de3103207ed55b1da7 (patch)
tree411f8e3cd71a4fab18c07dc8043eded806f4b59d
parentb86825e42b227c3645fe93c123c38010115b2b5a (diff)
Preserve parent environment when running hooks of the hook special remote.
-rw-r--r--Remote/Hook.hs17
-rw-r--r--debian/changelog1
2 files changed, 12 insertions, 6 deletions
diff --git a/Remote/Hook.hs b/Remote/Hook.hs
index dcac9da88..1202c6087 100644
--- a/Remote/Hook.hs
+++ b/Remote/Hook.hs
@@ -10,6 +10,7 @@ module Remote.Hook (remote) where
import qualified Data.ByteString.Lazy.Char8 as L
import qualified Data.Map as M
import System.Exit
+import System.Environment
import Common.Annex
import Types.Remote
@@ -59,9 +60,12 @@ hookSetup u c = do
gitConfigSpecialRemote u c' "hooktype" hooktype
return c'
-hookEnv :: Key -> Maybe FilePath -> Maybe [(String, String)]
-hookEnv k f = Just $ fileenv f ++ keyenv
+hookEnv :: Key -> Maybe FilePath -> IO (Maybe [(String, String)])
+hookEnv k f = Just <$> mergeenv (fileenv f ++ keyenv)
where
+ mergeenv l = M.toList .
+ M.union (M.fromList l)
+ <$> M.fromList <$> getEnvironment
env s v = ("ANNEX_" ++ s, v)
keyenv =
[ env "KEY" (show k)
@@ -88,8 +92,9 @@ runHook hooktype hook k f a = maybe (return False) run =<< lookupHook hooktype h
where
run command = do
showOutput -- make way for hook output
- ifM (liftIO $ boolSystemEnv
- "sh" [Param "-c", Param command] $ hookEnv k f)
+ ifM (liftIO $
+ boolSystemEnv "sh" [Param "-c", Param command]
+ =<< hookEnv k f)
( a
, do
warning $ hook ++ " hook exited nonzero!"
@@ -129,14 +134,14 @@ checkPresent r h k = do
liftIO $ catchMsgIO $ check v
where
findkey s = show k `elem` lines s
- env = hookEnv k Nothing
check Nothing = error "checkpresent hook misconfigured"
check (Just hook) = do
(frompipe, topipe) <- createPipe
pid <- forkProcess $ do
_ <- dupTo topipe stdOutput
closeFd frompipe
- executeFile "sh" True ["-c", hook] env
+ executeFile "sh" True ["-c", hook]
+ =<< hookEnv k Nothing
closeFd topipe
fromh <- fdToHandle frompipe
reply <- hGetContentsStrict fromh
diff --git a/debian/changelog b/debian/changelog
index 52f6c3b97..fa57391a8 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -8,6 +8,7 @@ git-annex (3.20120523) UNRELEASED; urgency=low
unsupported backend.
* Require that the SHA256 backend can be used when building, since it's the
default.
+ * Preserve parent environment when running hooks of the hook special remote.
-- Joey Hess <joeyh@debian.org> Sun, 27 May 2012 20:55:29 -0400