* Find bash executable on Windows. * Priority: * 1. CODEBUFF_GIT_BASH_PATH environment variable (user override) * 2. Common Git Bash installation locations (most reliable) * 3. Non-WSL bash in PATH (e.g., Git Bash added to PATH) * 4. WSL bash in PATH (last resort - System32, WindowsApps) * *
(env: NodeJS.ProcessEnv)
| 41 | * - UTF-16 encoding mismatches |
| 42 | */ |
| 43 | function findWindowsBash(env: NodeJS.ProcessEnv): string | null { |
| 44 | // Check for user-specified path via environment variable |
| 45 | const customPath = env.CODEBUFF_GIT_BASH_PATH |
| 46 | if (customPath && fs.existsSync(customPath)) { |
| 47 | return customPath |
| 48 | } |
| 49 | |
| 50 | // Check common Git Bash installation locations first (most reliable) |
| 51 | for (const commonPath of GIT_BASH_COMMON_PATHS) { |
| 52 | if (fs.existsSync(commonPath)) { |
| 53 | return commonPath |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | // Fall back to bash.exe in PATH, but skip WSL paths initially |
| 58 | const pathEnv = env.PATH || env.Path || '' |
| 59 | const pathDirs = pathEnv.split(path.delimiter) |
| 60 | const wslFallbackPaths: string[] = [] |
| 61 | |
| 62 | for (const dir of pathDirs) { |
| 63 | const dirLower = dir.toLowerCase() |
| 64 | const isWslPath = WSL_BASH_PATH_PATTERNS.some(pattern => dirLower.includes(pattern)) |
| 65 | |
| 66 | const bashPath = path.join(dir, 'bash.exe') |
| 67 | if (fs.existsSync(bashPath)) { |
| 68 | if (isWslPath) { |
| 69 | // Save WSL paths for last resort |
| 70 | wslFallbackPaths.push(bashPath) |
| 71 | } else { |
| 72 | // Non-WSL bash in PATH (e.g., Git Bash added to PATH) |
| 73 | return bashPath |
| 74 | } |
| 75 | } |
| 76 | |
| 77 | // Also check for just 'bash' (without .exe) |
| 78 | const bashPathNoExt = path.join(dir, 'bash') |
| 79 | if (fs.existsSync(bashPathNoExt)) { |
| 80 | if (isWslPath) { |
| 81 | wslFallbackPaths.push(bashPathNoExt) |
| 82 | } else { |
| 83 | return bashPathNoExt |
| 84 | } |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | // Last resort: use WSL bash if nothing else is available |
| 89 | // WSL can be unreliable (VM not running, quote escaping issues, UTF-16 encoding) |
| 90 | if (wslFallbackPaths.length > 0) { |
| 91 | return wslFallbackPaths[0] |
| 92 | } |
| 93 | |
| 94 | return null |
| 95 | } |
| 96 | |
| 97 | /** |
| 98 | * Create an error message for Windows users when bash is not available. |
no outgoing calls
no test coverage detected