Translate a Git Bash-style path (``/c/Users/...``) to the native Windows form (``C:\\Users\\...``) that Python's ``subprocess.Popen`` and ``pathlib.Path`` accept. No-op on non-Windows and for paths that already look native. Git on native Windows normally emits forward-slash Windows
(p: Optional[str])
| 1197 | |
| 1198 | |
| 1199 | def _normalize_git_bash_path(p: Optional[str]) -> Optional[str]: |
| 1200 | """Translate a Git Bash-style path (``/c/Users/...``) to the native |
| 1201 | Windows form (``C:\\Users\\...``) that Python's ``subprocess.Popen`` |
| 1202 | and ``pathlib.Path`` accept. |
| 1203 | |
| 1204 | No-op on non-Windows and for paths that already look native. Git on |
| 1205 | native Windows normally emits forward-slash Windows paths |
| 1206 | (``C:/Users/...``) which both bash and Python handle, but certain |
| 1207 | configurations (Git Bash shells, MSYS2, WSL-mounted repos) surface |
| 1208 | ``/c/...`` or ``/cygdrive/c/...`` variants. |
| 1209 | """ |
| 1210 | if not p: |
| 1211 | return p |
| 1212 | if sys.platform != "win32": |
| 1213 | return p |
| 1214 | import re as _re |
| 1215 | # /c/Users/... or /C/Users/... |
| 1216 | m = _re.match(r"^/([a-zA-Z])/(.*)$", p) |
| 1217 | if m: |
| 1218 | drive, rest = m.group(1), m.group(2) |
| 1219 | return f"{drive.upper()}:\\{rest.replace('/', chr(92))}" |
| 1220 | # /cygdrive/c/... or /mnt/c/... |
| 1221 | m = _re.match(r"^/(?:cygdrive|mnt)/([a-zA-Z])/(.*)$", p) |
| 1222 | if m: |
| 1223 | drive, rest = m.group(1), m.group(2) |
| 1224 | return f"{drive.upper()}:\\{rest.replace('/', chr(92))}" |
| 1225 | return p |
| 1226 | |
| 1227 | |
| 1228 | def _git_repo_root() -> Optional[str]: |