From d5c8e05b750e4251b96becd78bd9faef634482f3 Mon Sep 17 00:00:00 2001 From: FĂ©lix Sipma Date: Sun, 3 Jan 2016 16:13:11 +0100 Subject: Gpg: use gpg.program from git config (cherry picked from commit dd572a741f1ca4bce8f984c350d9045d979f1813) --- src/Propellor/Gpg.hs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'src/Propellor/Gpg.hs') diff --git a/src/Propellor/Gpg.hs b/src/Propellor/Gpg.hs index 4c7ccc9c..0fd8c9ce 100644 --- a/src/Propellor/Gpg.hs +++ b/src/Propellor/Gpg.hs @@ -13,6 +13,7 @@ import Prelude import Propellor.PrivData.Paths import Propellor.Message +import Utility.Exception import Utility.SafeCommand import Utility.Process import Utility.Monad @@ -22,7 +23,11 @@ import Utility.FileSystemEncoding import Utility.Env getGpgBin :: IO String -getGpgBin = getEnvDefault "GNUPGBIN" "gpg" +getGpgBin = do + gitGpgBin <- getGitConfigValue "gpg.program" + case gitGpgBin of + Nothing -> getEnvDefault "GNUPGBIN" "gpg" + Just b -> return b type KeyId = String @@ -113,6 +118,15 @@ reencryptPrivData = ifM (doesFileExist privDataFile) , return True ) +getGitConfigValue :: String -> IO (Maybe String) +getGitConfigValue key = do + value <- catchMaybeIO $ + takeWhile (/= '\n') + <$> readProcess "git" ["config", key] + return $ case value of + Just v | not (null v) -> Just v + _ -> Nothing + gitAdd :: FilePath -> IO Bool gitAdd f = boolSystem "git" [ Param "add" -- cgit v1.2.3