Runs `git -C rev-parse ` and returns the trimmed stdout.
(path: &Path, args: &[&str])
| 3 | |
| 4 | /// Runs `git -C <path> rev-parse <args>` and returns the trimmed stdout. |
| 5 | fn 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`. |
| 26 | struct GitRepoInfo { |
no test coverage detected