1 """Provide git-cola's version number"""
2 from __future__
import absolute_import
, division
, print_function
, unicode_literals
6 if sys
.version_info
< (3, 8):
7 import importlib_metadata
as metadata
9 from importlib
import metadata
10 except (ImportError, OSError):
14 if __name__
== '__main__':
15 srcdir
= os
.path
.dirname(os
.path
.dirname(__file__
))
16 sys
.path
.insert(1, srcdir
)
18 from .git
import STDOUT
# noqa
19 from .decorators
import memoize
# noqa
20 from ._version
import VERSION
# noqa
22 # minimum version requirements
24 # git diff learned --patience in 1.6.2
25 # git mergetool learned --no-prompt in 1.6.2
26 # git difftool moved out of contrib in git 1.6.3
29 # new: git cat-file --filters --path=<path> SHA1
30 # old: git cat-file --filters blob SHA1:<path>
31 'cat-file-filters-path': '2.11.0',
32 # git diff --submodule was introduced in 1.6.6
33 'diff-submodule': '1.6.6',
34 # git check-ignore was introduced in 1.8.2, but did not follow the same
35 # rules as git add and git status until 1.8.5
36 'check-ignore': '1.8.5',
37 # git push --force-with-lease
38 'force-with-lease': '1.8.5',
39 # git submodule update --recursive was introduced in 1.6.5
40 'submodule-update-recursive': '1.6.5',
41 # git include.path pseudo-variable was introduced in 1.7.10
42 'config-includes': '1.7.10',
43 # git for-each-ref --sort=version:refname
44 'version-sort': '2.7.0',
45 # Qt support for QT_AUTO_SCREEN_SCALE_FACTOR and QT_SCALE_FACTOR
46 'qt-hidpi-scale': '5.6.0',
47 # git rev-parse --show-superproject-working-tree was added in 2.13.0
48 'show-superproject-working-tree': '2.13.0',
53 """Returns an entry from the known versions table"""
54 return _versions
.get(key
)
58 """Returns the current version"""
60 if metadata
is not None:
62 pkg_version
= metadata
.version('git-cola')
63 except (ImportError, OSError):
69 def check_version(min_ver
, ver
):
70 """Check whether ver is greater or equal to min_ver"""
71 min_ver_list
= version_to_list(min_ver
)
72 ver_list
= version_to_list(ver
)
73 return min_ver_list
<= ver_list
78 """Checks if a version is greater than the known version for <what>"""
79 return check_version(get(key
), ver
)
82 def check_git(context
, key
):
83 """Checks if Git has a specific feature"""
84 return check(key
, git_version(context
))
87 def version_to_list(value
):
88 """Convert a version string to a list of numbers or strings"""
90 for p
in value
.split('.'):
100 def git_version_str(context
):
101 """Returns the current GIT version"""
103 return git
.version()[STDOUT
].strip()
107 def git_version(context
):
108 """Returns the current GIT version"""
109 parts
= git_version_str(context
).split()
110 if parts
and len(parts
) >= 3:
113 # minimum supported version
120 return 'cola version %s' % suffix
123 def print_version(brief
=False):
128 sys
.stdout
.write('%s\n' % msg
)