diff options
| author | Joey Hess <joeyh@joeyh.name> | 2015-12-08 12:00:39 -0400 |
|---|---|---|
| committer | Joey Hess <joeyh@joeyh.name> | 2015-12-08 12:00:39 -0400 |
| commit | f11c4835d5952d885c678a49501b1dcc524316ad (patch) | |
| tree | b86635b1bd1bdffe530d4f3b7529cf6c564676b3 /src/Propellor/Git.hs | |
| parent | 5ecb4944a637c4f28a15746b2ea716850e63a5ab (diff) | |
| parent | 39c0073d2800e23b051188de239efdea9b17793e (diff) | |
Merge branch 'joeyconfig'
Diffstat (limited to 'src/Propellor/Git.hs')
| -rw-r--r-- | src/Propellor/Git.hs | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/src/Propellor/Git.hs b/src/Propellor/Git.hs index a4418340..a2f5aef2 100644 --- a/src/Propellor/Git.hs +++ b/src/Propellor/Git.hs @@ -29,17 +29,31 @@ 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 +getRepoUrl = getM getGitConfigValue urls where urls = ["remote.deploy.url", "remote.origin.url"] - get u = do - v <- catchMaybeIO $ - takeWhile (/= '\n') - <$> readProcess "git" ["config", u] - return $ case v of - Just url | not (null url) -> Just url - _ -> Nothing hasOrigin :: IO Bool hasOrigin = catchDefaultIO False $ do |
