fix(version): build.rs resolves worktree HEAD via git rev-parse --git-dir (closes #1862)#1867
Merged
Merged
Conversation
…t-dir` (closes #1862) The previous `cargo:rerun-if-changed=../../.git/HEAD` check assumed `.git` is always a directory, but in git worktrees it's a file pointer like `gitdir: <common>/worktrees/<name>`. The hardcoded path didn't exist, so build.rs never registered a rerun trigger, and `apr --version` reported a stale commit hash from the previous build whenever HEAD moved without a source-file change. Fix: resolve the actual git directory via `git rev-parse --git-dir` (per- worktree HEAD) and `git rev-parse --git-common-dir` (shared refs). Works identically for primary checkouts (where both return the same path) and worktrees (where they diverge). Contract: apr-version-traceability-v1 bumped to v1.1.0: - new equation `worktree_head_freshness` (apr --version SHA == HEAD post-rebuild) - new proof obligation: "Embedded SHA matches HEAD in any git layout" - new falsifier FALSIFY-VERSION-004: build.rs must invoke `--git-dir` / `--git-common-dir` and not rely on a hardcoded `../../.git/HEAD` path. Verified: `apr --version` reports `0d8d52b25` matching `git rev-parse --short HEAD` after rebuild in worktree `/tmp/aprender-release-v0.35.0`. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
3 tasks
noahgift
added a commit
that referenced
this pull request
May 22, 2026
…itstream-io) (#1878) `cargo deny check advisories` started failing on every PR (and on main) 2026-05-22 with: error[unmaintained]: core2 is unmaintained, all versions yanked ├ ID: RUSTSEC-2026-0105 ├ Advisory: https://rustsec.org/advisories/RUSTSEC-2026-0105 The dep is pulled in transitively via `bitstream-io` (image/media decoding stack — `cargo tree` shows `bitstream-io v4.9.0 → core2 v0.4.0`). No first-party use; no drop-in replacement until upstream `bitstream-io` migrates off core2. This commit unblocks the in-flight PR cascade (#1867 #1868 #1870 #1873 #1875 #1876) which all failed CI's `ci / lint` step on this advisory. The deny entry is structured per the existing pattern in this file (id + human reason mentioning the transitive path) so revisiting the ignore in 6-12 months is straightforward. Co-authored-by: Claude Opus 4.7 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #1862 —
apr --versionreported stale commit hashes in git worktrees becausebuild.rsused a hardcoded../../.git/HEADpath. In worktrees.gitis a file pointer (gitdir: <common>/worktrees/<name>), so the path didn't exist, norerun-if-changedtrigger was registered, and cargo silently reused the previous binary on subsequent builds.Fix
crates/apr-cli/build.rs: resolve the actual git directory viagit rev-parse --git-dir(per-worktree HEAD) andgit rev-parse --git-common-dir(shared refs). Works for both primary checkouts and worktrees.contracts/apr-version-traceability-v1.yaml: bump v1.0.0 → v1.1.0worktree_head_freshnessFALSIFY-VERSION-004: build.rs must invoke--git-dir/--git-common-dirand not rely on a hardcoded../../.git/HEADpath.Verification
In the worktree at
/tmp/aprender-release-v0.35.0(HEAD =0d8d52b25):Falsifier FALSIFY-VERSION-004 passes:
Surfaced by v0.35.0 release dogfood, 2026-05-22.
Test plan
python3 -c "import yaml; yaml.safe_load(open('contracts/apr-version-traceability-v1.yaml'))")cargo fmt --all --check,cargo test -p aprender-contracts --lib, workspace-test🤖 Generated with Claude Code