1 # Copyright (c) David Aguilar
2 """Provide git-cola's version number"""
3 from __future__
import division
, absolute_import
, unicode_literals
8 if __name__
== '__main__':
9 srcdir
= os
.path
.dirname(os
.path
.dirname(__file__
))
10 sys
.path
.insert(1, srcdir
)
13 from .git
import STDOUT
14 from .decorators
import memoize
15 from ._version
import VERSION
17 # minimum version requirements
19 # git diff learned --patience in 1.6.2
20 # git mergetool learned --no-prompt in 1.6.2
21 # git difftool moved out of contrib in git 1.6.3
24 # git diff --submodule was introduced in 1.6.6
25 'diff-submodule': '1.6.6',
26 # git check-ignore was introduced in 1.8.2, but did not follow the same
27 # rules as git add and git status until 1.8.5
28 'check-ignore': '1.8.5',
29 # git for-each-ref --sort=version:refname
30 'version-sort': '2.0.0',
35 """Returns an entry from the known versions table"""
36 return _versions
.get(key
)
40 """Returns the current version"""
45 def check_version(min_ver
, ver
):
46 """Check whether ver is greater or equal to min_ver
48 min_ver_list
= version_to_list(min_ver
)
49 ver_list
= version_to_list(ver
)
50 return min_ver_list
<= ver_list
55 """Checks if a version is greater than the known version for <what>"""
56 return check_version(get(key
), ver
)
60 """Checks if Git has a specific feature"""
61 return check(key
, git_version())
64 def version_to_list(version
):
65 """Convert a version string to a list of numbers or strings
68 for p
in version
.split('.'):
78 def git_version_str():
79 """Returns the current GIT version"""
80 return git
.version()[STDOUT
].strip()
85 """Returns the current GIT version"""
86 parts
= git_version_str().split()
87 if parts
and len(parts
) >= 3:
90 # minimum supported version
95 return 'cola version %s' % version()
98 def print_version(brief
=False):
103 sys
.stdout
.write('%s\n' % msg
)
106 if __name__
== '__main__':
107 print_version(brief
=True)