use std::path::Path;
use std::process::Command;
use anyhow::{Context, Result};
pub fn capture(cwd: &Path, args: &[&str]) -> Result<String> {
let out = Command::new("git")
.arg("-C")
.arg(cwd)
.args(args)
.output()
.with_context(|| format!("spawn git {}", args.join(" ")))?;
if !out.status.success() {
anyhow::bail!(
"git {} failed in {}: {}",
args.join(" "),
cwd.display(),
String::from_utf8_lossy(&out.stderr).trim()
);
}
String::from_utf8(out.stdout).context("git stdout was not utf-8")
}
pub fn run(cwd: &Path, args: &[&str]) -> Result<()> {
let status = Command::new("git")
.arg("-C")
.arg(cwd)
.args(args)
.status()
.with_context(|| format!("spawn git {}", args.join(" ")))?;
if !status.success() {
anyhow::bail!("git {} failed in {}", args.join(" "), cwd.display());
}
Ok(())
}