blob: c446f67a5f6a7557dc5486c9a377284d9cb4142c (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
module Propellor.Git where
import Utility.Process
import Utility.Exception
import Utility.Directory
import Utility.Misc
import Utility.PartialPrelude
import Data.Maybe
import Control.Applicative
import Prelude
getCurrentBranch :: IO String
getCurrentBranch = takeWhile (/= '\n')
<$> readProcess "git" ["symbolic-ref", "--short", "HEAD"]
getCurrentBranchRef :: IO String
getCurrentBranchRef = takeWhile (/= '\n')
<$> readProcess "git" ["symbolic-ref", "HEAD"]
getCurrentGitSha1 :: String -> IO String
getCurrentGitSha1 branchref = takeWhile (/= '\n')
<$> readProcess "git" ["show-ref", "--hash", branchref]
hasOrigin :: IO Bool
hasOrigin = hasRemote "origin"
hasRemote :: String -> IO Bool
hasRemote remotename = catchDefaultIO False $ do
rs <- lines <$> readProcess "git" ["remote"]
return $ remotename `elem` rs
remoteUrl :: String -> IO (Maybe String)
remoteUrl remotename = catchDefaultIO Nothing $ headMaybe . lines
<$> readProcess "git" ["config", "remote." ++ remotename ++ ".url"]
hasGitRepo :: IO Bool
hasGitRepo = doesFileExist ".git/HEAD"
type Version = [Int]
gitVersion :: IO Version
gitVersion = extract <$> readProcess "git" ["--version"]
where
extract s = case lines s of
[] -> []
(l:_) -> mapMaybe readish $ segment (== '.') $
unwords $ drop 2 $ words l
|