Skip to content

Whitespace is checked commit by commit: a merge is not blamed, a first commit is checked - #92

Merged
closer-claudio merged 1 commit into
mainfrom
claudio/20261115-whitespace-one-commit
Nov 16, 2026
Merged

closer-claudio merged 1 commit into
mainfrom
claudio/20261115-whitespace-one-commit

Conversation

@closer-claudio

@closer-claudio closer-claudio commented Nov 16, 2026 •

Copy link
Copy Markdown

🎯 Why

The dangling-whitespace rule ran git log --check X^..X on each commit. Writing the commit as that range had two consequences.

  • A merge was failed for commits that are not in the range validated. X^..X is every commit X has that its first parent has not; for a merge, that is all the second parent brings. A branch that merged main into itself, where main held a commit with a trailing blank, was reported on --range main..feature as a merge with whitespace errors. git show --check <merge>, which the report points to, shows nothing.
  • A first commit was never checked. The range cannot be written for a commit with no parent, so the rule listed the whole history of every commit to learn whether it was the first (one more git per commit), and skipped it.

🛠️ What

git.Check runs git -c log.showRoot=true log --check X^!: the commit without its parents' histories, one git, no listing of the history.

Verdicts that move:

  • a merge that brings in commits with whitespace errors passes; what it brings in is not its own, and git shows no change for a merge;
  • a first commit with whitespace errors fails, where a range reaches it, whatever the user's log.showRoot.

What does not move: a commit a shallow clone was cut at. git shows it with no parent, as adding the whole tree, so it is not checked, as before, and -D records it. It is told from a first commit by its own object, which names a parent git does not show. A clone of depth 1, as actions/checkout makes by default, passes a run with no range as it did.

That commit is still printed PASS for a check that was not made, said only under -D: #93.

Not breaking for a lane that validates origin/<base>..HEAD: such a range reaches a first commit only in a repository with no upstream history at all.

A range of n commits with nothing to report starts 2 + n gits, where it started 2 + 22n before #91. A commit git finds something in costs one more, and a second when git shows it no parent.

🧪 How

  1. V: TestContractCheckFindsWhitespaceErrors (git/contract_test.go): a first commit, a merge of others' errors, a merge that adds a line itself.
  2. V: TestContractCheckOfAFirstCommitAndOfACut: log.showRoot off; clones of depth 1 and 2 over a first commit with a trailing blank; clones that hold the first commit, one at the very depth of the history.
  3. V: TestContractWhitespaceIsEachCommitsOwn (cmd/git-validation/contract_test.go): both verdicts and the clone of depth 1, through the command.
  4. V: against the check as it was, 1 and 3 fail. With a cut commit checked as a first one, the depth 1 and 2 rows of 2 and the clone row of 3 fail. With log.showRoot left to the user, the first commit passes in 2. Each measured alone, the file restored.
  5. V: just lint and just test pass (66 tests).
  6. U: the clones on Windows; this pull request's checks are the measure.

📝 Notes

UPSTREAM.md's row on -D names the skipped check for what it now is.

For #50.

…t commit is checked

The dangling-whitespace rule ran `git log --check X^..X` on each
commit. Two things followed from writing the commit as that range.

A merge was failed for commits that are not in the range validated.
`X^..X` is every commit X has that its first parent has not: for a
merge, all that the second parent brings. A branch that merges main
into itself, where main holds a commit with a trailing blank, was
reported, on `--range main..feature`, as a merge with whitespace
errors, with `git show --check <merge>` to see them, which shows
nothing. The error is main's, merged long ago.

A first commit was never checked. The range cannot be written for a
commit with no parent, so the rule listed the whole history of every
commit, one more git a commit, to learn whether it was the first, and
skipped it: a first commit with a trailing blank passed.

git.Check now runs `git log --check X^!`, the commit without its
parents' histories. It is one git, with no listing of the history
before it. A merge answers for nothing: what it brings in is not its
own, and git shows no change for a merge. A first commit is checked as
any other, whatever the user's log.showRoot, which the command sets:
with it off git shows nothing for a first commit.

A commit a shallow clone was cut at is not a first commit. git shows it
with no parent, as adding the whole tree, so `X^!` finds there every
whitespace error of the history before it. The old listing took it for
the first commit and skipped it; it is still skipped, and `-D` still
records it. It is told from a first commit by its own object, which
names a parent git does not show; a clone as deep as the history lists
its first commit as where it was cut, and that one names none. A clone
of depth 1, as actions/checkout makes by default, passes a run with no
range as it did.

Two verdicts move:

- a merge that brings in commits with whitespace errors passes;
- a first commit with whitespace errors fails, where a range reaches
  it.

With the reader's change before this one, a range of n commits with
nothing to report starts 2 + n gits, where it started 2 + 22n. A commit
git finds something in costs one more, to see whether git shows it a
parent, and a second to read its object when git shows it none.

UPSTREAM.md's row on `-D` names the skipped check for what it now is.

TestContractCheckFindsWhitespaceErrors holds a first commit, a merge of
others' errors and a merge that adds a line itself;
TestContractCheckOfAFirstCommitAndOfACut holds log.showRoot off, clones
of depth 1 and 2 over a first commit with a trailing blank, and clones
that hold the first commit, one at the very depth of the history;
TestContractWhitespaceIsEachCommitsOwn
holds the two verdicts and the clone of depth 1 through the command.
Against the check as it was, the first and the third fail. Measured one
at a time, the file restored: with a cut commit checked as a first one,
the clones of depth 1 and 2 fail in the second and the clone of depth 1
in the third; with log.showRoot left to the user, the first commit
passes in the second.

For #50.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Signed-off-by: closer-claudio <claudio@farcloser.world>
@closer-claudio

Copy link
Copy Markdown
Author

Reviewed at cb70d59

1 similar comment
@closer-claudio

Copy link
Copy Markdown
Author

Reviewed at cb70d59

@closer-claudio
closer-claudio merged commit f16b00f into main Nov 16, 2026
14 checks passed
@closer-claudio
closer-claudio deleted the claudio/20261115-whitespace-one-commit branch November 16, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants