Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 29526b8

Browse files
committed
fix(cygwin): use cygpath.exe to respect different mounts (e.g. MSYS2)
+ Always process paths, not only when starting from `cygdrive`.
1 parent cf8dc25 commit 29526b8

File tree

1 file changed

+31
-14
lines changed

1 file changed

+31
-14
lines changed

git/util.py

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,25 @@ def is_exec(fpath):
221221
return progs
222222

223223

224-
def _cygexpath(drive, path):
224+
def _cygpath(winpath):
225+
"""Invokes `cygpath` cmd to parse Windoews paths."""
226+
import subprocess as sbp
227+
228+
cmd = ['cygpath', winpath]
229+
try:
230+
cygpath = sbp.check_output(cmd, universal_newlines=True)
231+
cygpath = cygpath and cygpath[:-1]
232+
except Exception as ex:
233+
log.warning("`cygpath.exe` failed on '%s' due to: %s"
234+
" Using winpath as it is.",
235+
winpath, ex)
236+
else:
237+
winpath = cygpath
238+
239+
return winpath
240+
241+
242+
def _cyg_regex_path(drive, path):
225243
if osp.isabs(path) and not drive:
226244
## Invoked from `cygpath()` directly with `D:Apps\123`?
227245
# It's an error, leave it alone just slashes)
@@ -235,7 +253,7 @@ def _cygexpath(drive, path):
235253
else:
236254
p = cygpath(p)
237255
elif drive:
238-
p = '/cygdrive/%s/%s' % (drive.lower(), p)
256+
return _cygpath('%s:\\%s' % (drive, p))
239257

240258
return p.replace('\\', '/')
241259

@@ -249,12 +267,12 @@ def _cygexpath(drive, path):
249267
),
250268

251269
(re.compile(r"\\\\\?\\(\w):[/\\](.*)"),
252-
_cygexpath,
270+
_cyg_regex_path,
253271
False
254272
),
255273

256274
(re.compile(r"(\w):[/\\](.*)"),
257-
_cygexpath,
275+
_cyg_regex_path,
258276
False
259277
),
260278

@@ -270,16 +288,15 @@ def _cygexpath(drive, path):
270288

271289
def cygpath(path):
272290
"""Use :meth:`git.cmd.Git.polish_url()` instead, that works on any environment."""
273-
if not path.startswith(('/cygdrive', '//')):
274-
for regex, parser, recurse in _cygpath_parsers:
275-
match = regex.match(path)
276-
if match:
277-
path = parser(*match.groups())
278-
if recurse:
279-
path = cygpath(path)
280-
break
281-
else:
282-
path = _cygexpath(None, path)
291+
for regex, parser, recurse in _cygpath_parsers:
292+
match = regex.match(path)
293+
if match:
294+
path = parser(*match.groups())
295+
if recurse:
296+
path = cygpath(path)
297+
break
298+
else:
299+
path = _cyg_regex_path(None, path)
283300

284301
return path
285302

0 commit comments

Comments
 (0)