Skip to content

Re-stamp the version after a pull, not only after switching branches - #118

Merged
ParallelEntrepreneur merged 1 commit into
mainfrom
fix/restamp-on-branch-move
Sep 18, 2026
Merged

ParallelEntrepreneur merged 1 commit into
mainfrom
fix/restamp-on-branch-move

Conversation

@ParallelEntrepreneur

@ParallelEntrepreneur ParallelEntrepreneur commented Sep 18, 2026 •

Copy link
Copy Markdown
Collaborator

Why

crates/colonizer/build.rs stamps the binary with the commit it was built from, and tells Cargo to re-run it when .git/HEAD or .git/packed-refs changes. But a commit, git pull or reset on the current branch changes neither. It moves only .git/refs/heads/<branch>, and HEAD still reads ref: refs/heads/main. So Cargo reuses the cached output of the build script, and git pull && scripts/install.sh (the documented way to update a source install) builds a binary with the new code and the old commit. /api/version and the update check then compare against the wrong commit.

I saw this on a real update: after fast-forwarding main from d4551c3 to 44067b0, the rebuilt binary contained #109's code and still reported d4551c3. Only touch crates/colonizer/build.rs fixed the stamp.

In a worktree it was worse: ../../.git is a file there, so neither path existed, nothing was watched, and the build script never re-ran on git changes at all.

What changed

  • The build script also watches the ref file of the branch HEAD points to (git symbolic-ref -q HEAD). A detached HEAD has none, and there a commit rewrites HEAD itself, which is already watched.
  • All the watched paths come from git rev-parse --path-format=absolute --git-path <name> instead of ../../.git/.... In a worktree that gives the worktree's own HEAD and the shared packed-refs and branch refs.
  • A source package with no repository gets no paths, so nothing is watched, as before.

Testing

  • Built, committed this change (which moves only the branch ref), rebuilt without touching anything: the second binary is stamped with the new commit. Before this change it kept the old one.
  • In a git worktree, the three paths resolve to .git/worktrees/<name>/HEAD, .git/packed-refs and .git/refs/heads/main, and all exist.
  • cargo clippy -p colonizer-harness is clean.

build.rs watched .git/HEAD and .git/packed-refs, but a commit, pull or
reset on the current branch moves only .git/refs/heads/<branch>. Cargo
kept the cached build script output, so `git pull && scripts/install.sh`
produced a binary with the new code and the old commit, and the update
check compared against the wrong commit.

Watch the current branch's ref file too, and ask git for all three paths
(`rev-parse --git-path`) instead of assuming ../../.git, which is a file
in a worktree, where nothing was watched at all.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@ParallelEntrepreneur
ParallelEntrepreneur merged commit 338b4d1 into main Sep 18, 2026
2 checks passed
@ParallelEntrepreneur
ParallelEntrepreneur deleted the fix/restamp-on-branch-move branch September 18, 2026 06:26
ParallelEntrepreneur added a commit that referenced this pull request Sep 23, 2026
…118)

build.rs watched .git/HEAD and .git/packed-refs, but a commit, pull or
reset on the current branch moves only .git/refs/heads/<branch>. Cargo
kept the cached build script output, so `git pull && scripts/install.sh`
produced a binary with the new code and the old commit, and the update
check compared against the wrong commit.

Watch the current branch's ref file too, and ask git for all three paths
(`rev-parse --git-path`) instead of assuming ../../.git, which is a file
in a worktree, where nothing was watched at all.
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.

1 participant