propellor

propellor config for hosts.
git clone git://git.ricketyspace.net/propellor.git
Log | Files | Refs | LICENSE

Git.hs (1296B)


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