Skip to content

Commit

Permalink
Add comments explaining the files we are tracking
Browse files Browse the repository at this point in the history
Also add a note on the `.git/packed-refs` file and
why we don't need to track it.
  • Loading branch information
Serock3 committed May 7, 2024
1 parent 3a6c3ac commit ae75d41
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions mullvad-version/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,14 +99,17 @@ fn get_dev_suffix(release_tag: &str) -> Option<String> {
fn rerun_if_git_ref_changed(release_tag: &str) -> std::io::Result<()> {
let git_dir = Path::new("..").join(".git");

// If we build our output on information about HEAD we need to re-run if HEAD moves
// The `.git/HEAD` file contains the position of the current head. If in 'detached HEAD' state,
// this will be the ref of the current commit. If on a branch it will just point to it, e.g.
// `ref: refs/heads/main`. Tracking changes to this file will tell us if we change branch, or
// modify the current detached HEAD state (e.g. committing or rebasing).
let head_path = git_dir.join("HEAD");
if head_path.exists() {
println!("cargo:rerun-if-changed={}", head_path.display());
}

// If we build our output on information about the ref of the current branch, we need to re-run
// on changes to it
// The above check will not cause a rebuild when modifying commits on a currently checked out
// branch. To catch this, we need to track the `.git/refs/heads/$current_branch` file.
let output = Command::new("git")
.arg("branch")
.arg("--show-current")
Expand All @@ -133,7 +136,15 @@ fn rerun_if_git_ref_changed(release_tag: &str) -> std::io::Result<()> {
if git_release_tag_ref.exists() {
println!("cargo:rerun-if-changed={}", git_release_tag_ref.display());
};
Some(())

// NOTE: As the repository has gotten quite large, you may find the contents of the
// `.git/refs/heads` and `.git/refs/tags` empty. This happens because `git pack-refs` compresses
// and moves the information into the `.git/packed-refs` file to save storage. We do not have to
// track this file, however, as any changes to the current branch, 'detached HEAD' state
// or tags will update the corresponding `.git/refs` file we are tracking, even if it had
// previously been pruned.

Ok(())
}

/// Returns the commit hash for the commit that `git_ref` is pointing to.
Expand Down

0 comments on commit ae75d41

Please sign in to comment.