()
| 258 | } |
| 259 | |
| 260 | fn install_git_windows() -> Result<()> { |
| 261 | let install_dir = git_install_dir(); |
| 262 | let bin_dir = install_dir.join("bin"); |
| 263 | let git_exe = bin_dir.join("git.exe"); |
| 264 | |
| 265 | // If already installed, verify and return |
| 266 | if git_exe.exists() { |
| 267 | return Ok(()); |
| 268 | } |
| 269 | |
| 270 | std::fs::create_dir_all(&bin_dir)?; |
| 271 | |
| 272 | // Download portable Git for Windows (MinGit) |
| 273 | let version = "2.39.3.windows.1"; |
| 274 | let zip_name = format!("MinGit-{}-portable.zip", version); |
| 275 | let download_url = format!( |
| 276 | "https://github.com/git-for-windows/git/releases/download/{}/{}", |
| 277 | version, zip_name |
| 278 | ); |
| 279 | |
| 280 | let temp_zip = std::env::temp_dir().join(&zip_name); |
| 281 | |
| 282 | download_with_curl(&download_url, &temp_zip)?; |
| 283 | |
| 284 | // Extract zip |
| 285 | let output = Command::new("tar") |
| 286 | .args([ |
| 287 | "-xf", |
| 288 | &temp_zip.display().to_string(), |
| 289 | "-C", |
| 290 | &bin_dir.display().to_string(), |
| 291 | ]) |
| 292 | .output()?; |
| 293 | |
| 294 | if !output.status.success() { |
| 295 | // Try with PowerShell Expand-Archive on Windows |
| 296 | let ps_script = format!( |
| 297 | "Expand-Archive -Path '{}' -DestinationPath '{}' -Force", |
| 298 | temp_zip.display(), |
| 299 | bin_dir.display() |
| 300 | ); |
| 301 | |
| 302 | let output = Command::new("powershell") |
| 303 | .args(["-Command", &ps_script]) |
| 304 | .output()?; |
| 305 | |
| 306 | if !output.status.success() { |
| 307 | return Err(anyhow!("Failed to extract git zip archive")); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | // Find git.exe in the extracted contents |
| 312 | let extracted_dir = bin_dir.join(format!("MinGit-{}", version)); |
| 313 | if extracted_dir.exists() { |
| 314 | // Move contents up one level |
| 315 | for entry in std::fs::read_dir(&extracted_dir)?.flatten() { |
| 316 | let dest = bin_dir.join(entry.file_name()); |
| 317 | let _ = std::fs::rename(entry.path(), dest); |
no test coverage detected