From 2ec00b92724982708071dc0eed707659468d2bcf Mon Sep 17 00:00:00 2001 From: "Shawn O. Pearce" Date: Fri, 12 Jun 2009 09:32:50 -0700 Subject: Refactor git version detection for reuse This way we can use it to detect feature support in the underlying git, such as new options or commands that have been added in more recent versions. Signed-off-by: Shawn O. Pearce --- git_command.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) (limited to 'git_command.py') diff --git a/git_command.py b/git_command.py index 7ff1abac..d56ad0a8 100644 --- a/git_command.py +++ b/git_command.py @@ -68,6 +68,30 @@ class _GitCall(object): return fun git = _GitCall() +_git_version = None + +def git_require(min_version, fail=False): + global _git_version + + if _git_version is None: + ver_str = git.version() + if ver_str.startswith('git version '): + _git_version = tuple( + map(lambda x: int(x), + ver_str[len('git version '):].strip().split('.')[0:3] + )) + else: + print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str + sys.exit(1) + + if min_version <= _git_version: + return True + if fail: + need = '.'.join(map(lambda x: str(x), min_version)) + print >>sys.stderr, 'fatal: git %s or later required' % need + sys.exit(1) + return False + class GitCommand(object): def __init__(self, project, -- cgit v1.2.3-54-g00ecf