magus v0.4.3 is out. See what's new
¶ View markdown source · ✎ Suggest an edit
2 min read

MGS4009: commit left formatting stale

A commit changed a Go file, and gofmt -l reports that file as needing reformatting. This is the drift-notice hooks' finding (post-commit, pre-push; see the git integration guide), never a build or CI failure - nothing here exits non-zero or blocks anything.

commit 8f963f1 left formatting stale (gofmt would reformat): internal/foo.go
Reformat: magus run format:rw .

Why this is not lint's question

golangci-lint's formatters already answer "is this file formatted", against the whole tree, right now. This code answers a different, narrower question: did THIS COMMIT leave a file it touched unformatted, at the moment it was made. The two disagree in both directions - a commit can touch an already-misformatted file and leave it exactly as unformatted as it found it (lint's problem, not this commit's, and this code stays silent), and a commit can format its own file correctly while lint still fails on a dozen files elsewhere nobody touched today (also silent here). Keying on the commit's own diff, not the tree, is what a notice fired once per commit needs and a tree-wide lint pass does not give it.

Resolution

Reformat and fold it in: magus run format:rw ., then commit the result. The drift-notice hook names the exact fold command for the commit's amend safety (unpublished and still HEAD: amend; unpublished but something now sits on top of it: fixup + autosquash; already pushed: a new commit) - see MGS4006, whose fold-safety rules this class reuses unchanged. The two classes share one notice per commit; this one just carries its own remedy line.

What it checks, and what it does not

Scoped to the commit's changed files that the format target's own ctx.modifiesExistingFiles declares governed, narrowed further to .go files. Never writes: gofmt -l, never -w, so it cannot race a concurrent edit to the same file the way a write could.

Markdown is governed by the same declaration and formatted with dprint, not gofmt, and is not checked yet - a real gap, not a design choice, tracked alongside this code rather than silently absent.

See also

  • MGS4006: the sibling class in the same notice - a declared SOURCE changed with no matching declared OUTPUT change, generated-output drift rather than formatting.
  • MGS4007: a different question entirely - a target rewriting a declared source it did not declare as an edit, checked after a target RUNS, not after a commit is made.
MGS4009driftformattinggofmtcommithooks
Last updated (d966bfce)
Glossary

Target

A named operation (build, test, ...) you invoke with magus run <target>; it may compose a spell's tool-native operations and depend on other targets. See targets.

Op

A single tool-native command a target composes (long form: operation); the middle of the work hierarchy (Spell to Op to Target). See operations.

CI

An ordinary magusfile-defined target you compose yourself with magus\needs - magus does not hardcode its stages. Magus.RunCI treats it specially only in that it strips the rw charm, it is the anchor magus affected ci keys off, and a selected scope with no project declaring it is a load error rather than a silent no-op. See targets.

Run

One target executing under one magus invocation, such as magus run test web or magus affected ci. A run keeps its captured output behind an output reference. Every magus run is a run whether or not any job asked for it; see Job for how the two relate.

Conventions

This page uses none of the site's convention markers. The full set is on the conventions page.