use std::process::Command;
fn git(args: &[&str]) -> Option<String> {
Command::new("git")
.args(args)
.output()
.ok()
.filter(|out| out.status.success())
.and_then(|out| String::from_utf8(out.stdout).ok())
.map(|s| s.trim().to_string())
.filter(|s| !s.is_empty())
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
for path in ["HEAD", "refs/heads", "packed-refs"] {
if let Some(path) = git(&["rev-parse", "--git-path", path]) {
println!("cargo:rerun-if-changed={path}");
}
}
let sha = git(&["rev-parse", "--short", "HEAD"]).unwrap_or_else(|| "unknown".to_string());
println!("cargo:rustc-env=AGENTP_GIT_SHA={sha}");
}