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',
33 """Returns an entry from the known versions table"""
34 return _versions
.get(key
)
38 """Returns the current version"""
43 def check_version(min_ver
, ver
):
44 """Check whether ver is greater or equal to min_ver
46 min_ver_list
= version_to_list(min_ver
)
47 ver_list
= version_to_list(ver
)
48 return min_ver_list
<= ver_list
53 """Checks if a version is greater than the known version for <what>"""
54 return check_version(get(key
), ver
)
57 def version_to_list(version
):
58 """Convert a version string to a list of numbers or strings
61 for p
in version
.split('.'):
71 def git_version_str():
72 """Returns the current GIT version"""
73 return git
.version()[STDOUT
].strip()
78 """Returns the current GIT version"""
79 parts
= git_version_str().split()
80 if parts
and len(parts
) >= 3:
83 # minimum supported version
88 return 'cola version %s' % version()
91 def print_version(brief
=False):
96 sys
.stdout
.write('%s\n' % msg
)
99 if __name__
== '__main__':
100 print_version(brief
=True)