From 5020a86907ade611324c66c82cf4ee074789bdd5 Mon Sep 17 00:00:00 2001 From: Joey Hess Date: Sat, 20 Aug 2016 14:52:08 -0400 Subject: add gitVersion --- src/Propellor/Git.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'src/Propellor/Git.hs') diff --git a/src/Propellor/Git.hs b/src/Propellor/Git.hs index c3257b31..1d81c157 100644 --- a/src/Propellor/Git.hs +++ b/src/Propellor/Git.hs @@ -3,7 +3,10 @@ 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 @@ -26,3 +29,13 @@ hasOrigin = catchDefaultIO False $ do 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 -- cgit v1.2.3