Skip to content

fix(version): build.rs resolves worktree HEAD via git rev-parse --git-dir (closes #1862)#1867

Merged
noahgift merged 5 commits into
mainfrom
fix/version-traceability-worktree-1862
May 22, 2026
Merged

fix(version): build.rs resolves worktree HEAD via git rev-parse --git-dir (closes #1862)#1867
noahgift merged 5 commits into
mainfrom
fix/version-traceability-worktree-1862

Conversation

@noahgift

Copy link
Copy Markdown
Contributor

Summary

Fixes #1862apr --version reported stale commit hashes in git worktrees because build.rs used a hardcoded ../../.git/HEAD path. In worktrees .git is a file pointer (gitdir: <common>/worktrees/<name>), so the path didn't exist, no rerun-if-changed trigger was registered, and cargo silently reused the previous binary on subsequent builds.

Fix

  • crates/apr-cli/build.rs: resolve the actual git directory via git rev-parse --git-dir (per-worktree HEAD) and git 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.0
    • new equation worktree_head_freshness
    • 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.

Verification

In the worktree at /tmp/aprender-release-v0.35.0 (HEAD = 0d8d52b25):

$ apr --version
apr 0.34.0 (0d8d52b25)
$ git rev-parse --short HEAD
0d8d52b25
✓ MATCH

Falsifier FALSIFY-VERSION-004 passes:

$ grep -qE 'rev-parse.*--git-(dir|common-dir)' crates/apr-cli/build.rs \
    && ! grep -qE '\.\./\.\./\.git/HEAD' crates/apr-cli/build.rs && echo PASS
PASS

Surfaced by v0.35.0 release dogfood, 2026-05-22.

Test plan

  • Local build in worktree picks up correct HEAD SHA
  • FALSIFY-VERSION-004 grep test passes against new build.rs
  • Contract YAML parses (python3 -c "import yaml; yaml.safe_load(open('contracts/apr-version-traceability-v1.yaml'))")
  • FALSIFY-VERSION-{001,002,003} still pass on new binary
  • CI: cargo fmt --all --check, cargo test -p aprender-contracts --lib, workspace-test

🤖 Generated with Claude Code

…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>
@noahgift noahgift enabled auto-merge (squash) May 22, 2026 06:51
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>
@noahgift noahgift merged commit f8a97a9 into main May 22, 2026
10 checks passed
@noahgift noahgift deleted the fix/version-traceability-worktree-1862 branch May 22, 2026 10:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

apr --version: build.rs doesn't pick up HEAD changes in worktrees without source-file modification

1 participant