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

Skip to content

Commit 1fbcf36

Browse files
committed
fix(cygwin): pass through cygpath.exe -w also in reverse
1 parent 38883e0 commit 1fbcf36

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

git/util.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,14 +225,17 @@ def is_exec(fpath):
225225
return progs
226226

227227

228-
def _cygpath(winpath):
228+
def _cygpath(winpath, inverse=False):
229229
"""Invokes `cygpath` cmd to parse Windoews paths."""
230230
import subprocess as sbp
231231

232232
cmd = ['cygpath', winpath]
233+
if inverse:
234+
cmd.insert(1, '-w')
233235
try:
234236
cygpath = sbp.check_output(cmd, universal_newlines=True)
235-
cygpath = cygpath and cygpath[:-1]
237+
if cygpath and cygpath[-1] == '\n':
238+
cygpath = cygpath[:-1]
236239
except Exception as ex:
237240
log.warning("`cygpath.exe` failed on '%s' due to: %s"
238241
" Using winpath as it is.",
@@ -290,7 +293,7 @@ def _cyg_regex_path(drive, path):
290293
)
291294

292295

293-
@lru_cache(500) # Sice arg required only for py3.2 backport `repoze.lru` lib.
296+
@lru_cache(500) # Size arg required only for py3.2 backport `repoze.lru` lib.
294297
def cygpath(path):
295298
"""Use :meth:`git.cmd.Git.polish_url()` instead, that works on any environment."""
296299
for regex, parser, recurse in _cygpath_parsers:
@@ -309,20 +312,23 @@ def cygpath(path):
309312
_decygpath_regex = re.compile(r"/cygdrive/(\w)(/.*)?")
310313

311314

315+
@lru_cache(500) # Size arg required only for py3.2 backport `repoze.lru` lib.
312316
def decygpath(path):
313-
m = _decygpath_regex.match(path)
314-
if m:
315-
drive, rest_path = m.groups()
316-
path = '%s:%s' % (drive.upper(), rest_path or '')
317+
if path:
318+
winpath = _cygpath(path, inverse=True)
319+
if path[-1] in '/\\' and winpath[-1] not in '/\\':
320+
winpath += '\\'
321+
path = winpath
317322

318-
return path.replace('/', '\\')
323+
return path
319324

320325

321326
#: Store boolean flags denoting if a specific Git executable
322327
#: is from a Cygwin installation (since `cache_lru()` unsupported on PY2).
323328
_is_cygwin_cache = {}
324329

325330

331+
@lru_cache(50) # Size arg required only for py3.2 backport `repoze.lru` lib.
326332
def is_cygwin_git(git_executable):
327333
if not is_win:
328334
return False

0 commit comments

Comments
 (0)