1 """Provide git-cola's version number"""
2 from __future__
import absolute_import
, division
, print_function
, unicode_literals
6 from .git
import STDOUT
7 from .decorators
import memoize
8 from ._version
import VERSION
11 if sys
.version_info
< (3, 8):
12 import importlib_metadata
as metadata
14 from importlib
import metadata
15 except (ImportError, OSError):
19 if __name__
== '__main__':
20 srcdir
= os
.path
.dirname(os
.path
.dirname(__file__
))
21 sys
.path
.insert(1, srcdir
)
24 # minimum version requirements
26 # git diff learned --patience in 1.6.2
27 # git mergetool learned --no-prompt in 1.6.2
28 # git difftool moved out of contrib in git 1.6.3
31 # new: git cat-file --filters --path=<path> SHA1
32 # old: git cat-file --filters blob SHA1:<path>
33 'cat-file-filters-path': '2.11.0',
34 # git diff --submodule was introduced in 1.6.6
35 'diff-submodule': '1.6.6',
36 # git check-ignore was introduced in 1.8.2, but did not follow the same
37 # rules as git add and git status until 1.8.5
38 'check-ignore': '1.8.5',
39 # git push --force-with-lease
40 'force-with-lease': '1.8.5',
41 # git submodule update --recursive was introduced in 1.6.5
42 'submodule-update-recursive': '1.6.5',
43 # git include.path pseudo-variable was introduced in 1.7.10.
44 'config-includes': '1.7.10',
45 # git config --show-scope was introduced in 2.26.0
46 'config-show-scope': '2.26.0',
47 # git config --show-origin was introduced in 2.8.0
48 'config-show-origin': '2.8.0',
49 # git for-each-ref --sort=version:refname
50 'version-sort': '2.7.0',
51 # Qt support for QT_AUTO_SCREEN_SCALE_FACTOR and QT_SCALE_FACTOR
52 'qt-hidpi-scale': '5.6.0',
53 # git rev-parse --show-superproject-working-tree was added in 2.13.0
54 'show-superproject-working-tree': '2.13.0',
55 # git rebase --update-refs was added in 2.38.0
56 'rebase-update-refs': '2.38.0',
61 """Returns an entry from the known versions table"""
62 return _versions
.get(key
)
66 """Returns the current version"""
68 if metadata
is not None:
70 pkg_version
= metadata
.version('git-cola')
71 except (ImportError, OSError):
77 def check_version(min_ver
, ver
):
78 """Check whether ver is greater or equal to min_ver"""
79 min_ver_list
= version_to_list(min_ver
)
80 ver_list
= version_to_list(ver
)
81 return min_ver_list
<= ver_list
86 """Checks if a version is greater than the known version for <what>"""
87 return check_version(get(key
), ver
)
90 def check_git(context
, key
):
91 """Checks if Git has a specific feature"""
92 return check(key
, git_version(context
))
95 def version_to_list(value
):
96 """Convert a version string to a list of numbers or strings"""
98 for p
in value
.split('.'):
108 def git_version_str(context
):
109 """Returns the current GIT version"""
111 return git
.version(_readonly
=True)[STDOUT
].strip()
115 def git_version(context
):
116 """Returns the current GIT version"""
117 parts
= git_version_str(context
).split()
118 if parts
and len(parts
) >= 3:
121 # minimum supported version
128 return 'cola version %s' % suffix
131 def print_version(brief
=False):
136 sys
.stdout
.write('%s\n' % msg
)