Skip to content

make check fails on untracked scratch dirs — scope the gofmt/goimports gates to tracked files #549

Description

@saadqbal

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

  • make check passes with an untracked directory present containing deliberately misformatted Go
  • make check still fails when a genuinely tracked file is misformatted
  • make fmt leaves untracked scratch directories untouched
  • CI and local agree on the file set (one definition, not two)

Context

Encountered while working on #548. Not fixed there to keep that PR scoped to the offboard telemetry bug (backend#2314).

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions