* Ensure the bash we found appears to come from a Git for Windows install. * * (We avoid launching WSL shells via `C:\\Windows\\System32\\bash.exe`.)
(bashPath: string, existsSyncFn: ExistsSyncFn)
| 49 | * (We avoid launching WSL shells via `C:\\Windows\\System32\\bash.exe`.) |
| 50 | */ |
| 51 | function looksLikeGitForWindowsBash(bashPath: string, existsSyncFn: ExistsSyncFn): boolean { |
| 52 | if (isWslLauncherPath(bashPath)) { |
| 53 | return false; |
| 54 | } |
| 55 | |
| 56 | const normalized = WIN_PATH.normalize(bashPath); |
| 57 | const lower = normalized.toLowerCase(); |
| 58 | |
| 59 | if (lower.endsWith("\\usr\\bin\\bash.exe")) { |
| 60 | const root = WIN_PATH.dirname(WIN_PATH.dirname(WIN_PATH.dirname(normalized))); |
| 61 | return existsSyncFn(WIN_PATH.join(root, "cmd", "git.exe")); |
| 62 | } |
| 63 | |
| 64 | if (lower.endsWith("\\bin\\bash.exe")) { |
| 65 | const root = WIN_PATH.dirname(WIN_PATH.dirname(normalized)); |
| 66 | return existsSyncFn(WIN_PATH.join(root, "cmd", "git.exe")); |
| 67 | } |
| 68 | |
| 69 | // Best-effort: walk up a few levels looking for `cmd/git.exe`. |
| 70 | let dir = WIN_PATH.dirname(normalized); |
| 71 | for (let i = 0; i < 4; i++) { |
| 72 | if (existsSyncFn(WIN_PATH.join(dir, "cmd", "git.exe"))) { |
| 73 | return true; |
| 74 | } |
| 75 | |
| 76 | const parent = WIN_PATH.dirname(dir); |
| 77 | if (parent === dir) { |
| 78 | break; |
| 79 | } |
| 80 | dir = parent; |
| 81 | } |
| 82 | |
| 83 | return false; |
| 84 | } |
| 85 | |
| 86 | function findGitRootFromGitExePath(gitExePath: string, existsSyncFn: ExistsSyncFn): string | null { |
| 87 | let dir = WIN_PATH.dirname(WIN_PATH.dirname(WIN_PATH.normalize(gitExePath))); |
no test coverage detected