MCPcopy Create free account
hub / github.com/block/builderbot / run

Function run

staged/src-tauri/src/git/cli.rs:24–50  ·  view source on GitHub ↗

Run a git command and return stdout as a string

(repo: &Path, args: &[&str])

Source from the content-addressed store, hash-verified

22
23/// Run a git command and return stdout as a string
24pub fn run(repo: &Path, args: &[&str]) -> Result<String, GitError> {
25 let repo_str = repo
26 .to_str()
27 .ok_or_else(|| GitError::InvalidPath(repo.display().to_string()))?;
28
29 let output = Command::new("git")
30 .args(["-C", repo_str])
31 .args(args)
32 .output()
33 .map_err(|e| {
34 if e.kind() == std::io::ErrorKind::NotFound {
35 GitError::GitNotFound
36 } else {
37 GitError::CommandFailed(e.to_string())
38 }
39 })?;
40
41 if !output.status.success() {
42 let stderr = String::from_utf8_lossy(&output.stderr);
43 if stderr.contains("not a git repository") {
44 return Err(GitError::NotARepo(repo.display().to_string()));
45 }
46 return Err(GitError::CommandFailed(stderr.into_owned()));
47 }
48
49 String::from_utf8(output.stdout).map_err(|_| GitError::InvalidUtf8)
50}

Callers 15

search_filesFunction · 0.70
get_file_at_refFunction · 0.70
get_repo_rootFunction · 0.70
list_refsFunction · 0.70
list_branchesFunction · 0.70
merge_baseFunction · 0.70
resolve_refFunction · 0.70
get_current_branchFunction · 0.70
get_unified_diffFunction · 0.70
list_diff_filesFunction · 0.70
expand_untracked_dirFunction · 0.70

Calls 1

displayMethod · 0.80

Tested by

no test coverage detected