From 4d63a9f0ad327cba305e239e51d02e5e33213eda Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sun, 1 Nov 2015 13:37:49 -0400 Subject: run editor processes in foreground --- src/Propellor/Gpg.hs | 21 +++++++++++++-------- src/Propellor/PrivData.hs | 5 ++++- src/Propellor/Spin.hs | 8 +++++--- 3 files changed, 22 insertions(+), 12 deletions(-) diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs index 60b0d52d..9c58a5d1 100644 --- a/src/Propellor/Gpg.hs +++ b/src/Propellor/Gpg.hs @@ -16,6 +16,7 @@ import Utility.Monad import Utility.Misc import Utility.Tmp import Utility.FileSystemEncoding +import Utility.ConcurrentOutput type KeyId = String @@ -111,10 +112,7 @@ gitCommitKeyRing action = do -- Commit explicitly the keyring and privdata files, as other -- changes may be staged by the user and shouldn't be committed. tocommit <- filterM doesFileExist [ privDataFile, keyring] - gitCommit $ (map File tocommit) ++ - [ Param "-m" - , Param ("propellor " ++ action) - ] + gitCommit (Just ("propellor " ++ action)) (map File tocommit) -- Adds --gpg-sign if there's a keyring. gpgSignParams :: [CommandParam] -> IO [CommandParam] @@ -124,10 +122,17 @@ gpgSignParams ps = ifM (doesFileExist keyring) ) -- Automatically sign the commit if there'a a keyring. -gitCommit :: [CommandParam] -> IO Bool -gitCommit ps = do - ps' <- gpgSignParams ps - boolSystem "git" (Param "commit" : ps') +gitCommit :: Maybe String -> [CommandParam] -> IO Bool +gitCommit msg ps = do + let ps' = Param "commit" : ps ++ + maybe [] (\m -> [Param "-m", Param m]) msg + ps'' <- gpgSignParams ps' + if isNothing msg + then do + (_, _, _, p) <- createProcessForeground $ + proc "git" (toCommand ps'') + checkSuccessProcess p + else boolSystem "git" ps'' gpgDecrypt :: FilePath -> IO String gpgDecrypt f = ifM (doesFileExist f) diff --git a/src/Propellor/PrivData.hs b/src/Propellor/PrivData.hs index e59f42c3..6b77f782 100644 --- a/src/Propellor/PrivData.hs +++ b/src/Propellor/PrivData.hs @@ -54,6 +54,8 @@ import Utility.FileMode import Utility.Env import Utility.Table import Utility.FileSystemEncoding +import Utility.ConcurrentOutput +import Utility.Process -- | Allows a Property to access the value of a specific PrivDataField, -- for use in a specific Context or HostContext. @@ -192,7 +194,8 @@ editPrivData field context = do hClose th maybe noop (\p -> writeFileProtected' f (`L.hPut` privDataByteString p)) v editor <- getEnvDefault "EDITOR" "vi" - unlessM (boolSystem editor [File f]) $ + (_, _, _, p) <- createProcessForeground $ proc editor [f] + unlessM (checkSuccessProcess p) $ error "Editor failed; aborting." PrivData <$> readFile f setPrivDataTo field context v' diff --git a/src/Propellor/Spin.hs b/src/Propellor/Spin.hs index 6048a1cd..ae7e7af5 100644 --- a/src/Propellor/Spin.hs +++ b/src/Propellor/Spin.hs @@ -33,7 +33,8 @@ import Utility.SafeCommand commitSpin :: IO () commitSpin = do void $ actionMessage "Git commit" $ - gitCommit [Param "--allow-empty", Param "-a", Param "-m", Param spinCommitMessage] + gitCommit (Just spinCommitMessage) + [Param "--allow-empty", Param "-a"] -- Push to central origin repo first, if possible. -- The remote propellor will pull from there, which avoids -- us needing to send stuff directly to the remote host. @@ -336,8 +337,9 @@ mergeSpin = do old_head <- getCurrentGitSha1 branch old_commit <- findLastNonSpinCommit rungit "reset" [Param old_commit] - rungit "commit" [Param "-a", Param "--allow-empty"] - rungit "merge" =<< gpgSignParams [Param "-s", Param "ours", Param old_head] + unlessM (gitCommit Nothing [Param "-a", Param "--allow-empty"]) $ + error "git commit failed" + rungit "merge" =<< gpgSignParams [Param "-s", Param "ours", Param old_head, Param "--no-edit"] current_commit <- getCurrentGitSha1 branch rungit "update-ref" [Param branchref, Param current_commit] rungit "checkout" [Param branch] -- cgit v1.2.3