1 """Provide git-cola's version number"""
5 if sys
.version_info
< (3, 8):
6 import importlib_metadata
as metadata
8 from importlib
import metadata
9 except (ImportError, OSError):
12 from .git
import STDOUT
13 from .decorators
import memoize
14 from ._version
import VERSION
17 from ._scm
_version
import __version__
as SCM_VERSION
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 config --show-scope was introduced in 2.26.0
44 'config-show-scope': '2.26.0',
45 # git config --show-origin was introduced in 2.8.0
46 'config-show-origin': '2.8.0',
47 # git for-each-ref --sort=version:refname
48 'version-sort': '2.7.0',
49 # Qt support for QT_AUTO_SCREEN_SCALE_FACTOR and QT_SCALE_FACTOR
50 'qt-hidpi-scale': '5.6.0',
51 # git rebase --rebase-merges was added in 2.18.0
52 'rebase-merges': '2.18.0',
53 # git rebase --update-refs was added in 2.38.0
54 'rebase-update-refs': '2.38.0',
55 # git rev-parse --show-superproject-working-tree was added in 2.13.0
56 'show-superproject-working-tree': '2.13.0',
61 """Returns an entry from the known versions table"""
62 return _versions
.get(key
)
66 """Returns the current version"""
75 metadata_version
= metadata
.version('git-cola')
76 except (ImportError, OSError):
79 # Building from a tarball can end up reporting "0.0.0" or "0.1.dev*".
80 # Use the fallback version in these scenarios.
81 if not metadata_version
.startswith('0.'):
82 return metadata_version
86 def builtin_version():
87 """Returns the version recorded in cola/_version.py"""
92 def check_version(min_ver
, ver
):
93 """Check whether ver is greater or equal to min_ver"""
94 min_ver_list
= version_to_list(min_ver
)
95 ver_list
= version_to_list(ver
)
96 return min_ver_list
<= ver_list
101 """Checks if a version is greater than the known version for <what>"""
102 return check_version(get(key
), ver
)
105 def check_git(context
, key
):
106 """Checks if Git has a specific feature"""
107 return check(key
, git_version(context
))
110 def version_to_list(value
):
111 """Convert a version string to a list of numbers or strings"""
113 for part
in value
.split('.'):
118 ver_list
.append(number
)
123 def git_version_str(context
):
124 """Returns the current GIT version"""
126 return git
.version(_readonly
=True)[STDOUT
].strip()
130 def git_version(context
):
131 """Returns the current GIT version"""
132 parts
= git_version_str(context
).split()
133 if parts
and len(parts
) >= 3:
136 # minimum supported version
141 def cola_version(builtin
=False):
142 """A version string for consumption by humans"""
144 suffix
= builtin_version()
147 return 'cola version %s' % suffix
150 def print_version(builtin
=False, brief
=False):
151 if builtin
and brief
:
152 msg
= builtin_version()
156 msg
= cola_version(builtin
=builtin
)