ai_agent/utils/
git_diff.rs1pub fn get_diff(path: &std::path::Path) -> Result<String, String> {
2 let output = std::process::Command::new("git")
3 .args(["diff", "--no-color"])
4 .arg(path)
5 .output()
6 .map_err(|e| e.to_string())?;
7
8 if output.status.success() {
9 Ok(String::from_utf8_lossy(&output.stdout).to_string())
10 } else {
11 Err(String::from_utf8_lossy(&output.stderr).to_string())
12 }
13}
14
15pub fn get_staged_diff() -> Result<String, String> {
16 let output = std::process::Command::new("git")
17 .args(["diff", "--cached", "--no-color"])
18 .output()
19 .map_err(|e| e.to_string())?;
20
21 if output.status.success() {
22 Ok(String::from_utf8_lossy(&output.stdout).to_string())
23 } else {
24 Err(String::from_utf8_lossy(&output.stderr).to_string())
25 }
26}