1 # Copyright (C) 2007-2018 David Aguilar and contributors
2 """Provide git-cola's version number"""
3 from __future__
import division
, absolute_import
, unicode_literals
7 if __name__
== '__main__':
8 srcdir
= os
.path
.dirname(os
.path
.dirname(__file__
))
9 sys
.path
.insert(1, srcdir
)
11 from .git
import STDOUT
# noqa
12 from .decorators
import memoize
# noqa
13 from ._version
import VERSION
# noqa
15 from ._build
_version
import BUILD_VERSION
19 # minimum version requirements
21 # git diff learned --patience in 1.6.2
22 # git mergetool learned --no-prompt in 1.6.2
23 # git difftool moved out of contrib in git 1.6.3
26 # git diff --submodule was introduced in 1.6.6
27 'diff-submodule': '1.6.6',
28 # git check-ignore was introduced in 1.8.2, but did not follow the same
29 # rules as git add and git status until 1.8.5
30 'check-ignore': '1.8.5',
31 # git for-each-ref --sort=version:refname
32 'version-sort': '2.7.0',
33 # new: git cat-file --filters --path=<path> SHA1
34 # old: git cat-file --filters blob SHA1:<path>
35 'cat-file-filters-path': '2.11.0',
40 """Returns an entry from the known versions table"""
41 return _versions
.get(key
)
45 """Returns the current version"""
50 """Return the build version, which includes the Git ID"""
55 def check_version(min_ver
, ver
):
56 """Check whether ver is greater or equal to min_ver
58 min_ver_list
= version_to_list(min_ver
)
59 ver_list
= version_to_list(ver
)
60 return min_ver_list
<= ver_list
65 """Checks if a version is greater than the known version for <what>"""
66 return check_version(get(key
), ver
)
69 def check_git(context
, key
):
70 """Checks if Git has a specific feature"""
71 return check(key
, git_version(context
))
74 def version_to_list(value
):
75 """Convert a version string to a list of numbers or strings
78 for p
in value
.split('.'):
88 def git_version_str(context
):
89 """Returns the current GIT version"""
91 return git
.version()[STDOUT
].strip()
95 def git_version(context
):
96 """Returns the current GIT version"""
97 parts
= git_version_str(context
).split()
98 if parts
and len(parts
) >= 3:
101 # minimum supported version
106 def cola_version(build
=False):
108 suffix
= build_version() or version()
111 return 'cola version %s' % suffix
114 def print_version(brief
=False, build
=False):
117 msg
= build_version()
121 msg
= cola_version(build
=build
)
122 sys
.stdout
.write('%s\n' % msg
)