MCPcopy Create free account
hub / github.com/dtormoen/tsk-tsk / run_git_rev_parse

Function run_git_rev_parse

src/repo_utils.rs:5–23  ·  view source on GitHub ↗

Runs `git -C rev-parse ` and returns the trimmed stdout.

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

Source from the content-addressed store, hash-verified

3
4/// Runs `git -C <path> rev-parse <args>` and returns the trimmed stdout.
5fn run_git_rev_parse(path: &Path, args: &[&str]) -> Result<String, Box<dyn Error>> {
6 let output = std::process::Command::new("git")
7 .arg("-C")
8 .arg(path)
9 .arg("rev-parse")
10 .args(args)
11 .output()
12 .map_err(|e| format!("Failed to run git rev-parse: {e}"))?;
13 if !output.status.success() {
14 let stderr = String::from_utf8_lossy(&output.stderr);
15 return Err(format!(
16 "git rev-parse failed in {}: {}",
17 path.display(),
18 stderr.trim()
19 )
20 .into());
21 }
22 Ok(String::from_utf8_lossy(&output.stdout).trim().to_string())
23}
24
25/// Parsed output from `git rev-parse --show-toplevel --git-dir --git-common-dir`.
26struct GitRepoInfo {

Callers 2

detect_git_repoFunction · 0.85
resolve_git_common_dirFunction · 0.85

Calls 1

successMethod · 0.80

Tested by

no test coverage detected