use anyhow::{bail, Result};
use std::process::Command;

use crate::git::cli::GitCli;

impl GitCli {
    /// Run `git status --porcelain=v2` and return the raw output.
    pub fn status_porcelain(&self, path: &str) -> Result<String> {
        let output = Command::new("git")
            .args(["-C", path, "status", "--porcelain=v2"])
            .output()?;

        if !output.status.success() {
            bail!(
                "git status failed (exit {}): {}",
                output.status,
                String::from_utf8_lossy(&output.stderr)
            );
        }

        Ok(String::from_utf8_lossy(&output.stdout).into_owned())
    }
}