What
make fmt-check (a prerequisite of make check, the documented pre-push tier) runs both formatters over the whole working tree:
@diff="$(gofmt -s -l . 2>/dev/null)"; \
...
@drift="$($(GO) run golang.org/x/tools/cmd/goimports@$(GOIMPORTS_VERSION) -local github.com/tracebloc/cli -l .)"; \
. includes untracked directories. Anything containing Go files under a scratch path — a nested git worktree, a vendored copy, a go build sandbox — is reported as drift even when every tracked file in the repo is correctly formatted:
==> goimports (import grouping) needed on:
<untracked-scratch-dir>/internal/cli/data.go
==> run `make fmt` to fix
make fmt has the mirrored bug in write mode (gofmt -s -w ., goimports -w .): the suggested remedy rewrites files outside the repo's tracked content.
Why it matters
CI never sees this — a fresh checkout has no untracked Go files — so it is a local-only false failure. The Makefile header states the invariant this violates: "Anything that fails in make ci would have failed on a PR, and vice versa. Divergence between local and CI is the bug this file exists to prevent."
The practical damage is that the pre-push gate cries wolf, which trains people to ignore make check output or to run make fmt and reformat content that is not theirs.
Fix
Scope both formatter invocations (check and write mode) to files git actually tracks — a git ls-files '*.go'-driven file list. Requirements:
- works when the list is large (no
ARG_MAX blowup) - fails closed when the list is empty — an empty list must never be laundered into a clean pass (backend#1729)
- tracked-but-deleted index entries must not error the gate
Acceptance criteria
Context
Encountered while working on #548. Not fixed there to keep that PR scoped to the offboard telemetry bug (backend#2314).
What
make fmt-check(a prerequisite ofmake check, the documented pre-push tier) runs both formatters over the whole working tree:.includes untracked directories. Anything containing Go files under a scratch path — a nested git worktree, a vendored copy, ago buildsandbox — is reported as drift even when every tracked file in the repo is correctly formatted:make fmthas the mirrored bug in write mode (gofmt -s -w .,goimports -w .): the suggested remedy rewrites files outside the repo's tracked content.Why it matters
CI never sees this — a fresh checkout has no untracked Go files — so it is a local-only false failure. The
Makefileheader states the invariant this violates: "Anything that fails inmake ciwould have failed on a PR, and vice versa. Divergence between local and CI is the bug this file exists to prevent."The practical damage is that the pre-push gate cries wolf, which trains people to ignore
make checkoutput or to runmake fmtand reformat content that is not theirs.Fix
Scope both formatter invocations (check and write mode) to files git actually tracks — a
git ls-files '*.go'-driven file list. Requirements:ARG_MAXblowup)Acceptance criteria
make checkpasses with an untracked directory present containing deliberately misformatted Gomake checkstill fails when a genuinely tracked file is misformattedmake fmtleaves untracked scratch directories untouchedContext
Encountered while working on #548. Not fixed there to keep that PR scoped to the offboard telemetry bug (backend#2314).