MCPcopy Index your code
hub / github.com/AI45Lab/Code / ensure_git_installed

Function ensure_git_installed

core/src/git.rs:41–71  ·  view source on GitHub ↗

Ensure git is installed. Downloads and installs git if not found.

()

Source from the content-addressed store, hash-verified

39
40/// Ensure git is installed. Downloads and installs git if not found.
41pub 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
73fn install_git_macos() -> Result<()> {
74 // Download official macOS git installer

Callers 1

run_gitFunction · 0.85

Calls 6

is_git_availableFunction · 0.85
install_git_macosFunction · 0.85
install_git_linuxFunction · 0.85
install_git_windowsFunction · 0.85
getMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected