MCPcopy
hub / github.com/jisaacks/GitGutter / version

Method version

modules/handler.py:96–161  ·  view source on GitHub ↗

Return git executable version. The version string is used to check, whether git executable exists and works properly. It may also be used to enable functions with newer git versions. As the "git_binary" setting may be view/project specific and may change at

(self, validate)

Source from the content-addressed store, hash-verified

94 self._git_wsl = False
95
96 def version(self, validate):
97 """Return git executable version.
98
99 The version string is used to check, whether git executable exists and
100 works properly. It may also be used to enable functions with newer git
101 versions.
102
103 As the "git_binary" setting may be view/project specific and may change
104 at each time it needs to be checked in proper situations to validate
105 whether git still works properly.
106
107 Arguments:
108 validate (bool): If True force updating version string. Use cached
109 value otherwise.
110 Returns:
111 tuple: PEP-440 conform git version (major, minor, patch)
112 """
113 if not validate:
114 return self._git_version
115
116 # check if the git binary setting has changed
117 git_binary = self.settings.git_binary
118 if self._git_binary != git_binary:
119 self._git_binary = git_binary
120 self._git_version = None
121 # a unix like path on windows means running git via WSL
122 self._git_wsl = WIN32 and self._git_binary.startswith('/')
123
124 if self._git_version is None:
125 is_missing = self._git_binary in self._missing_binaries
126 git_version = ''
127
128 # Query git version synchronously
129 try:
130 proc = self.popen([self._git_binary, '--version'])
131 if _HAVE_TIMEOUT:
132 proc.wait(1.0)
133 git_version = proc.stdout.read().decode('utf-8')
134
135 except TimeoutExpired as error:
136 proc.kill()
137 git_version = proc.stdout.read().decode('utf-8')
138 if not is_missing and self.settings.get('debug'):
139 utils.log_message(str(error))
140
141 except Exception as error:
142 if not is_missing and self.settings.get('debug'):
143 utils.log_message(str(error))
144
145 # Parse version string like (git version 2.12.2.windows.1)
146 match = re.match(r'git version (\d+)\.(\d+)\.(\d+)', git_version)
147 if match:
148 # PEP-440 conform git version (major, minor, patch)
149 self._git_version = tuple(int(g) for g in match.groups())
150 if is_missing:
151 utils.log_message(self._git_binary + ' is back on duty!')
152 self._missing_binaries.discard(self._git_binary)
153

Callers 4

is_enabledMethod · 0.80
utils.pyFile · 0.80
runMethod · 0.80
__init__.pyFile · 0.80

Calls 2

popenMethod · 0.95
getMethod · 0.80

Tested by

no test coverage detected