git-annex/Git/Version.hs
Joey Hess 4d786ebe4a Check git version at runtime, rather than assuming it will be the same as the git version used at build time when running git-checkattr and git-branch remove.
It's ok to probe every time for git-branch remove because that's
run quite rarely. For git-checkattr, it's run only once, when
starting the --batch mode, and so again the overhead is pretty minimal.

This leaves 2 places where the build version is still used.
git merge might be interactive or fail if one skews, and --no-gpg-sign
might not be pased, or might be passed to a git that doesn't understand it
if the other skews. It seems a little expensive to check the git version
each time these are used.

This doesn't seem likely to cause many problems, at least compared with
check-attr hanging on skew.
2015-01-05 15:54:52 -04:00

30 lines
548 B
Haskell

{- git versions
-
- Copyright 2011, 2013 Joey Hess <joey@kitenet.net>
-
- Licensed under the GNU GPL version 3 or higher.
-}
module Git.Version (
installed,
older,
normalize,
GitVersion,
) where
import Common
import Utility.DottedVersion
type GitVersion = DottedVersion
installed :: IO GitVersion
installed = normalize . extract <$> readProcess "git" ["--version"]
where
extract s = case lines s of
[] -> ""
(l:_) -> unwords $ drop 2 $ words l
older :: String -> IO Bool
older n = do
v <- installed
return $ v < normalize n