@@ -221,7 +221,25 @@ def is_exec(fpath):
221
221
return progs
222
222
223
223
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 ):
225
243
if osp .isabs (path ) and not drive :
226
244
## Invoked from `cygpath()` directly with `D:Apps\123`?
227
245
# It's an error, leave it alone just slashes)
@@ -235,7 +253,7 @@ def _cygexpath(drive, path):
235
253
else :
236
254
p = cygpath (p )
237
255
elif drive :
238
- p = '/cygdrive/%s/ %s' % (drive . lower () , p )
256
+ return _cygpath ( '%s: \\ %s' % (drive , p ) )
239
257
240
258
return p .replace ('\\ ' , '/' )
241
259
@@ -249,12 +267,12 @@ def _cygexpath(drive, path):
249
267
),
250
268
251
269
(re .compile (r"\\\\\?\\(\w):[/\\](.*)" ),
252
- _cygexpath ,
270
+ _cyg_regex_path ,
253
271
False
254
272
),
255
273
256
274
(re .compile (r"(\w):[/\\](.*)" ),
257
- _cygexpath ,
275
+ _cyg_regex_path ,
258
276
False
259
277
),
260
278
@@ -270,16 +288,15 @@ def _cygexpath(drive, path):
270
288
271
289
def cygpath (path ):
272
290
"""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 )
283
300
284
301
return path
285
302
0 commit comments