Preserve parent environment when running hooks of the hook special remote.
This commit is contained in:
parent
b86825e42b
commit
13118136c0
2 changed files with 12 additions and 6 deletions
|
@ -10,6 +10,7 @@ module Remote.Hook (remote) where
|
||||||
import qualified Data.ByteString.Lazy.Char8 as L
|
import qualified Data.ByteString.Lazy.Char8 as L
|
||||||
import qualified Data.Map as M
|
import qualified Data.Map as M
|
||||||
import System.Exit
|
import System.Exit
|
||||||
|
import System.Environment
|
||||||
|
|
||||||
import Common.Annex
|
import Common.Annex
|
||||||
import Types.Remote
|
import Types.Remote
|
||||||
|
@ -59,9 +60,12 @@ hookSetup u c = do
|
||||||
gitConfigSpecialRemote u c' "hooktype" hooktype
|
gitConfigSpecialRemote u c' "hooktype" hooktype
|
||||||
return c'
|
return c'
|
||||||
|
|
||||||
hookEnv :: Key -> Maybe FilePath -> Maybe [(String, String)]
|
hookEnv :: Key -> Maybe FilePath -> IO (Maybe [(String, String)])
|
||||||
hookEnv k f = Just $ fileenv f ++ keyenv
|
hookEnv k f = Just <$> mergeenv (fileenv f ++ keyenv)
|
||||||
where
|
where
|
||||||
|
mergeenv l = M.toList .
|
||||||
|
M.union (M.fromList l)
|
||||||
|
<$> M.fromList <$> getEnvironment
|
||||||
env s v = ("ANNEX_" ++ s, v)
|
env s v = ("ANNEX_" ++ s, v)
|
||||||
keyenv =
|
keyenv =
|
||||||
[ env "KEY" (show k)
|
[ env "KEY" (show k)
|
||||||
|
@ -88,8 +92,9 @@ runHook hooktype hook k f a = maybe (return False) run =<< lookupHook hooktype h
|
||||||
where
|
where
|
||||||
run command = do
|
run command = do
|
||||||
showOutput -- make way for hook output
|
showOutput -- make way for hook output
|
||||||
ifM (liftIO $ boolSystemEnv
|
ifM (liftIO $
|
||||||
"sh" [Param "-c", Param command] $ hookEnv k f)
|
boolSystemEnv "sh" [Param "-c", Param command]
|
||||||
|
=<< hookEnv k f)
|
||||||
( a
|
( a
|
||||||
, do
|
, do
|
||||||
warning $ hook ++ " hook exited nonzero!"
|
warning $ hook ++ " hook exited nonzero!"
|
||||||
|
@ -129,14 +134,14 @@ checkPresent r h k = do
|
||||||
liftIO $ catchMsgIO $ check v
|
liftIO $ catchMsgIO $ check v
|
||||||
where
|
where
|
||||||
findkey s = show k `elem` lines s
|
findkey s = show k `elem` lines s
|
||||||
env = hookEnv k Nothing
|
|
||||||
check Nothing = error "checkpresent hook misconfigured"
|
check Nothing = error "checkpresent hook misconfigured"
|
||||||
check (Just hook) = do
|
check (Just hook) = do
|
||||||
(frompipe, topipe) <- createPipe
|
(frompipe, topipe) <- createPipe
|
||||||
pid <- forkProcess $ do
|
pid <- forkProcess $ do
|
||||||
_ <- dupTo topipe stdOutput
|
_ <- dupTo topipe stdOutput
|
||||||
closeFd frompipe
|
closeFd frompipe
|
||||||
executeFile "sh" True ["-c", hook] env
|
executeFile "sh" True ["-c", hook]
|
||||||
|
=<< hookEnv k Nothing
|
||||||
closeFd topipe
|
closeFd topipe
|
||||||
fromh <- fdToHandle frompipe
|
fromh <- fdToHandle frompipe
|
||||||
reply <- hGetContentsStrict fromh
|
reply <- hGetContentsStrict fromh
|
||||||
|
|
1
debian/changelog
vendored
1
debian/changelog
vendored
|
@ -8,6 +8,7 @@ git-annex (3.20120523) UNRELEASED; urgency=low
|
||||||
unsupported backend.
|
unsupported backend.
|
||||||
* Require that the SHA256 backend can be used when building, since it's the
|
* Require that the SHA256 backend can be used when building, since it's the
|
||||||
default.
|
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
|
-- Joey Hess <joeyh@debian.org> Sun, 27 May 2012 20:55:29 -0400
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue