diff options
author | Shawn O. Pearce <sop@google.com> | 2009-06-12 09:32:50 -0700 |
---|---|---|
committer | Shawn O. Pearce <sop@google.com> | 2009-06-12 09:32:50 -0700 |
commit | 2ec00b92724982708071dc0eed707659468d2bcf (patch) | |
tree | 4af657b8164ea30575b99852a60012ea9ad8e24e /git_command.py | |
parent | 2a3a81b51f1aee5a2da789d07d14cde61c96e8b7 (diff) | |
download | git-repo-2ec00b92724982708071dc0eed707659468d2bcf.tar.gz |
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 <sop@google.com>
Diffstat (limited to 'git_command.py')
-rw-r--r-- | git_command.py | 24 |
1 files changed, 24 insertions, 0 deletions
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): | |||
68 | return fun | 68 | return fun |
69 | git = _GitCall() | 69 | git = _GitCall() |
70 | 70 | ||
71 | _git_version = None | ||
72 | |||
73 | def git_require(min_version, fail=False): | ||
74 | global _git_version | ||
75 | |||
76 | if _git_version is None: | ||
77 | ver_str = git.version() | ||
78 | if ver_str.startswith('git version '): | ||
79 | _git_version = tuple( | ||
80 | map(lambda x: int(x), | ||
81 | ver_str[len('git version '):].strip().split('.')[0:3] | ||
82 | )) | ||
83 | else: | ||
84 | print >>sys.stderr, 'fatal: "%s" unsupported' % ver_str | ||
85 | sys.exit(1) | ||
86 | |||
87 | if min_version <= _git_version: | ||
88 | return True | ||
89 | if fail: | ||
90 | need = '.'.join(map(lambda x: str(x), min_version)) | ||
91 | print >>sys.stderr, 'fatal: git %s or later required' % need | ||
92 | sys.exit(1) | ||
93 | return False | ||
94 | |||
71 | class GitCommand(object): | 95 | class GitCommand(object): |
72 | def __init__(self, | 96 | def __init__(self, |
73 | project, | 97 | project, |