diff --git a/firmware/build.rs b/firmware/build.rs index fb286be..84d0f5a 100644 --- a/firmware/build.rs +++ b/firmware/build.rs @@ -1,4 +1,14 @@ -use std::{env, process::Command}; +use std::{env, path::Path, process::Command}; + +/// Paths that change when `HEAD`, a branch, or a tag moves. `HEAD` itself is only rewritten on +/// checkout, so commits are tracked through the reflog and the ref directories. +const GIT_WATCH: [&str; 5] = [ + "../.git/HEAD", + "../.git/logs/HEAD", + "../.git/refs/heads", + "../.git/refs/tags", + "../.git/packed-refs", +]; fn git_output(args: &[&str], dir: &str) -> Option { let output = Command::new("git") @@ -28,6 +38,13 @@ fn main() { "cargo:rustc-env=GUAC_VERSION={}", firmware_version(&manifest_dir) ); - println!("cargo:rerun-if-changed=../.git/HEAD"); + + for path in GIT_WATCH { + let path = Path::new(&manifest_dir).join(path); + + if path.exists() { + println!("cargo:rerun-if-changed={}", path.display()); + } + } } }