Re-stamp the version after a pull, not only after switching branches - #118
Merged
Merged
Conversation
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
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.
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.
Why
crates/colonizer/build.rsstamps the binary with the commit it was built from, and tells Cargo to re-run it when.git/HEADor.git/packed-refschanges. But a commit,git pullor reset on the current branch changes neither. It moves only.git/refs/heads/<branch>, andHEADstill readsref: refs/heads/main. So Cargo reuses the cached output of the build script, andgit pull && scripts/install.sh(the documented way to update a source install) builds a binary with the new code and the old commit./api/versionand the update check then compare against the wrong commit.I saw this on a real update: after fast-forwarding
mainfromd4551c3to44067b0, the rebuilt binary contained #109's code and still reportedd4551c3. Onlytouch crates/colonizer/build.rsfixed the stamp.In a worktree it was worse:
../../.gitis a file there, so neither path existed, nothing was watched, and the build script never re-ran on git changes at all.What changed
HEADpoints to (git symbolic-ref -q HEAD). A detachedHEADhas none, and there a commit rewritesHEADitself, which is already watched.git rev-parse --path-format=absolute --git-path <name>instead of../../.git/.... In a worktree that gives the worktree's ownHEADand the sharedpacked-refsand branch refs.Testing
git worktree, the three paths resolve to.git/worktrees/<name>/HEAD,.git/packed-refsand.git/refs/heads/main, and all exist.cargo clippy -p colonizer-harnessis clean.