diff options
| author | Sean Whitton <spwhitton@spwhitton.name> | 2015-12-06 16:48:15 -0700 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-12-08 11:58:35 -0400 |
| commit | 09085c76d76f708361e3670eb6726671ed1ba845 (patch) | |
| tree | 9d12e5dcc7fdd189c7ac8b60718eb0f19decb729 | |
| parent | f28caf5f3142950e6a27bacd1f2d9b9eb4d5dae6 (diff) | |
implement getGitConfigValue & getGitConfigBool
Signed-off-by: Sean Whitton <spwhitton@spwhitton.name>
(cherry picked from commit 1828c6d987f9d499b95610311379dcbdeaa21e33)
| -rw-r--r-- | src/Propellor/Git.hs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/Propellor/Git.hs b/src/Propellor/Git.hs index a4418340..e11528fa 100644 --- a/src/Propellor/Git.hs +++ b/src/Propellor/Git.hs @@ -29,6 +29,27 @@ setRepoUrl url = do void $ boolSystem "git" [Param "config", Param (branchval "remote"), Param "origin"] void $ boolSystem "git" [Param "config", Param (branchval "merge"), Param $ "refs/heads/"++branch] +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 + +-- `git config --bool propellor.blah` outputs "false" if propellor.blah is unset +-- i.e. the git convention is that the default value of any git-config setting +-- is "false". So we don't need a Maybe Bool here. +getGitConfigBool :: String -> IO Bool +getGitConfigBool key = do + value <- catchMaybeIO $ + takeWhile (/= '\n') + <$> readProcess "git" ["config", "--bool", key] + return $ case value of + Just "true" -> True + _ -> False + getRepoUrl :: IO (Maybe String) getRepoUrl = getM get urls where |
