use std::process::Command;
fn git(arguments: &[&str]) -> Option<String> {
let output = Command::new("git").args(arguments).output().ok()?;
output
.status
.success()
.then(|| String::from_utf8_lossy(&output.stdout).trim().to_owned())
}
fn main() {
println!("cargo:rerun-if-changed=build.rs");
let revision = git(&["rev-parse", "HEAD"]).unwrap_or_default();
println!("cargo:rustc-env=GLORY_CLI_SOURCE_REV={revision}");
if let Some(head) = git(&["rev-parse", "--git-path", "HEAD"]) {
println!("cargo:rerun-if-changed={head}");
}
if let Some(reference) = git(&["symbolic-ref", "-q", "HEAD"])
&& let Some(path) = git(&["rev-parse", "--git-path", &reference])
{
println!("cargo:rerun-if-changed={path}");
}
}