summaryrefslogtreecommitdiff
path: root/configure.hs
diff options
context:
space:
mode:
authorGravatar Joey Hess <joey@kitenet.net>2011-10-12 00:25:05 -0400
committerGravatar Joey Hess <joey@kitenet.net>2011-10-12 00:28:33 -0400
commit82d127de99767a8a6387cb923eb964fa51474aa6 (patch)
treed555ff44685fbb7c8d7660a8fc623d68f37f61aa /configure.hs
parentfa5c016585b61e84c9ef7e7f6e6814693599a66a (diff)
add git version check to configure
Rather ugly dotted version comparison method, but it does work.
Diffstat (limited to 'configure.hs')
-rw-r--r--configure.hs24
1 files changed, 24 insertions, 0 deletions
diff --git a/configure.hs b/configure.hs
index b68fa12db..1d1c02335 100644
--- a/configure.hs
+++ b/configure.hs
@@ -2,12 +2,16 @@
import System.Directory
import Data.List
+import Data.String.Utils
+import System.Cmd.Utils
import Build.TestConfig
tests :: [TestCase]
tests =
[ TestCase "version" getVersion
+ , TestCase "git" $ requireCmd "git" "git --version >/dev/null"
+ , TestCase "git version" checkGitVersion
, testCp "cp_a" "-a"
, testCp "cp_p" "-p"
, testCp "cp_reflink_auto" "--reflink=auto"
@@ -53,6 +57,26 @@ getVersionString = do
where
middle = drop 1 . init
+{- Checks for a new enough version of git. -}
+checkGitVersion :: Test
+checkGitVersion = do
+ (_, s) <- pipeFrom "git" ["--version"]
+ let version = last $ words $ head $ lines s
+ if dotted version < dotted need
+ then error $ "git version " ++ version ++ " too old; need " ++ need
+ else return $ Config "gitversion" (StringConfig version)
+ where
+ -- for git-check-attr behavior change
+ need = "1.7.7"
+ dotted = sum . mult 1 . reverse . extend 10 . map readi . split "."
+ extend n l = l ++ take (n - length l) (repeat 0)
+ mult _ [] = []
+ mult n (x:xs) = (n*x) : (mult (n*100) xs)
+ readi :: String -> Integer
+ readi s = case reads s of
+ ((x,_):_) -> x
+ _ -> 0
+
{- Set up cabal file with version. -}
cabalSetup :: IO ()
cabalSetup = do