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

Function install_git_linux

core/src/git.rs:168–258  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

166}
167
168fn install_git_linux() -> Result<()> {
169 let install_dir = git_install_dir();
170 let bin_dir = install_dir.join("bin");
171 let git_path = bin_dir.join("git");
172
173 // If already installed, verify and return
174 if git_path.exists() {
175 return Ok(());
176 }
177
178 std::fs::create_dir_all(&bin_dir)?;
179
180 // Try to download static git binary for Linux
181 // Use the official git releases from GitHub
182 let version = "2.39.3";
183 let arch = if std::process::Command::new("uname")
184 .arg("-m")
185 .output()
186 .map(|o| String::from_utf8_lossy(&o.stdout).contains("x86_64"))
187 .unwrap_or(true)
188 {
189 "amd64"
190 } else {
191 "386"
192 };
193
194 // Try GitHub releases first (has portable binaries)
195 let tarball_name = format!("git-{}-linux-{}.tar.gz", version, arch);
196 let download_url = format!(
197 "https://github.com/git/git/releases/download/v{}/{}",
198 version, tarball_name
199 );
200
201 let temp_tarball = std::env::temp_dir().join(&tarball_name);
202
203 // Try downloading from GitHub
204 if download_with_curl(&download_url, &temp_tarball).is_err() {
205 // Fallback: try official download page
206 let fallback_url = format!("https://git-scm.com/downloads?file=git-{}", tarball_name);
207 download_with_curl(&fallback_url, &temp_tarball)?;
208 }
209
210 // Extract
211 let output = Command::new("tar")
212 .args([
213 "-xzf",
214 &temp_tarball.display().to_string(),
215 "-C",
216 &bin_dir.display().to_string(),
217 ])
218 .output()?;
219
220 if !output.status.success() {
221 // Alternative: extract to temp and move
222 let temp_dir = std::env::temp_dir().join("git-extract");
223 let _ = std::fs::create_dir_all(&temp_dir);
224
225 let output = Command::new("tar")

Callers 1

ensure_git_installedFunction · 0.85

Calls 6

git_install_dirFunction · 0.85
download_with_curlFunction · 0.85
walkdirFunction · 0.85
containsMethod · 0.80
existsMethod · 0.45
successMethod · 0.45

Tested by

no test coverage detected