Skip to content

Commit

Permalink
Handle detached HEADs
Browse files Browse the repository at this point in the history
  • Loading branch information
Michael-F-Bryan committed Jul 23, 2022
1 parent e5447dd commit 0648cd6
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions crates/fj-app/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ fn git_description() -> Option<String> {
println!("cargo:rerun-if-changed={}", head_file.display());

if let Ok(contents) = std::fs::read_to_string(&head_file) {
let (_, branch) = contents
.split_once(' ')
.expect(".git/HEAD should point to a valid head file");
let commit_hash_file = project_root.join(".git").join(branch.trim());
println!("cargo:rerun-if-changed={}", commit_hash_file.display());
// Most of the time the HEAD file will be `ref: refs/heads/$branch`, but
// when it's a detached head we'll only get the commit hash and can skip
// the rerun-if-changed logic.

if let Some((_, branch)) = contents.split_once(' ') {
let commit_hash_file =
project_root.join(".git").join(branch.trim());
println!("cargo:rerun-if-changed={}", commit_hash_file.display());
}
}

Some(stdout.trim().to_string())
Expand Down

0 comments on commit 0648cd6

Please sign in to comment.