Ensure git is installed. Downloads and installs git if not found.
()
| 39 | |
| 40 | /// Ensure git is installed. Downloads and installs git if not found. |
| 41 | pub fn ensure_git_installed() -> Result<()> { |
| 42 | // Fast path: already checked and available |
| 43 | if GIT_AVAILABLE.get().copied().unwrap_or(false) { |
| 44 | return Ok(()); |
| 45 | } |
| 46 | |
| 47 | if is_git_available() { |
| 48 | let _ = GIT_AVAILABLE.set(true); |
| 49 | return Ok(()); |
| 50 | } |
| 51 | |
| 52 | // Try to download and install git |
| 53 | let install_result = if cfg!(target_os = "macos") { |
| 54 | install_git_macos() |
| 55 | } else if cfg!(target_os = "linux") { |
| 56 | install_git_linux() |
| 57 | } else if cfg!(target_os = "windows") { |
| 58 | install_git_windows() |
| 59 | } else { |
| 60 | Err(anyhow!( |
| 61 | "Unsupported platform: {}. Please install git manually from https://git-scm.com", |
| 62 | std::env::consts::OS |
| 63 | )) |
| 64 | }; |
| 65 | |
| 66 | if install_result.is_ok() { |
| 67 | let _ = GIT_AVAILABLE.set(true); |
| 68 | } |
| 69 | |
| 70 | install_result |
| 71 | } |
| 72 | |
| 73 | fn install_git_macos() -> Result<()> { |
| 74 | // Download official macOS git installer |
no test coverage detected