use std::process::Command;
fn main() {
let hash = Command::new("git")
.args(["rev-parse", "--short", "HEAD"])
.output()
.ok()
.filter(|o| o.status.success())
.and_then(|o| String::from_utf8(o.stdout).ok())
.map(|s| s.trim().to_owned())
.filter(|s| !s.is_empty())
.unwrap_or_else(|| "unknown".into());
println!("cargo:rustc-env=WHYCANT_GIT_HASH={hash}");
println!("cargo:rerun-if-changed=.git/HEAD");
if let Ok(head) = std::fs::read_to_string(".git/HEAD") {
if let Some(reference) = head.trim().strip_prefix("ref: ") {
println!("cargo:rerun-if-changed=.git/{reference}");
println!("cargo:rerun-if-changed=.git/packed-refs");
}
}
}