fix(version): suppress staleness warning for fork builds

When the gt binary is built from a local fork (e.g., ~/src/gastown),
the staleness check would incorrectly warn about being stale because
it compared against the rig's repo HEAD. This confused agents.

The fix detects fork builds by checking if the binary's embedded
commit exists in the target repo. If not, the binary was built from
a different repo and we report "fork build" instead of "stale".

Changes:
- Add IsForkBuild field to StaleBinaryInfo
- Add commitExistsInRepo helper to detect fork scenarios
- Update gt stale command to show "Binary built from fork" status
- Update doctor check to report fork builds as OK

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
furiosa
2026-01-26 11:10:35 -08:00
committed by John Ogle
parent d0036b0768
commit 5ab01f383a
3 changed files with 37 additions and 2 deletions

View File

@@ -21,6 +21,7 @@ var (
// StaleBinaryInfo contains information about binary staleness.
type StaleBinaryInfo struct {
IsStale bool // True if binary commit doesn't match repo HEAD
IsForkBuild bool // True if binary was built from a different repo (fork)
BinaryCommit string // Commit hash the binary was built from
RepoCommit string // Current repo HEAD commit
CommitsBehind int // Number of commits binary is behind (0 if unknown)
@@ -66,6 +67,15 @@ func commitsMatch(a, b string) bool {
return strings.HasPrefix(a, b[:minLen]) || strings.HasPrefix(b, a[:minLen])
}
// commitExistsInRepo checks if a commit hash exists in the given repository.
// This is used to detect fork builds - if the binary's commit doesn't exist
// in the target repo, the binary was likely built from a different repo.
func commitExistsInRepo(commit, repoDir string) bool {
cmd := exec.Command("git", "cat-file", "-t", commit)
cmd.Dir = repoDir
return cmd.Run() == nil
}
// CheckStaleBinary compares the binary's embedded commit with the repo HEAD.
// It returns staleness info including whether the binary needs rebuilding.
// This check is designed to be fast and non-blocking - errors are captured
@@ -93,6 +103,14 @@ func CheckStaleBinary(repoDir string) *StaleBinaryInfo {
// Compare commits using prefix matching (handles short vs full hash)
// Use the shorter of the two commit lengths for comparison
if !commitsMatch(info.BinaryCommit, info.RepoCommit) {
// Check if the binary's commit exists in this repo.
// If it doesn't, the binary was built from a different repo (fork).
// Don't warn about staleness in that case.
if !commitExistsInRepo(info.BinaryCommit, repoDir) {
info.IsForkBuild = true
return info
}
info.IsStale = true
// Try to count commits between binary and HEAD