Repository navigation
Conversation
The commit-count step measured BASE..HEAD from the event's pull_request.base.sha. A re-run replays the original event, so once the branch is rebased past that base, the range spans every main commit in between: kirodotdev#30034's one commit was counted as 62. The checkout is GitHub's merge commit, whose first parent is the base tip it was built on, and the diff-base step has already fetched its history. Count from that parent when the second parent is the PR head, as the diff-scoped gates do since kirodotdev#38678; otherwise keep base.sha. Fixes kirodotdev#39016 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Contributor
Author
|
Closing as superseded: #38997 (merged) dropped the PR Hygiene commit-count check this PR corrected, so there is nothing left to fix. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem / Motivation
Goal: PR Hygiene's commit-count gate counts only the PR's own commits, even when the event's
base.shais older than the base the branch was rebased onto.On #30034 a one-commit PR failed
Enforce commit countwithPR must contain 1 or 2 commits (has 62), and re-running gave the same result. The step countedgit rev-list --count "$BASE".."$HEAD"withBASE= the event'spull_request.base.sha(758622b385), while the branch sat onbddefa36fb, 61 main commits later. The run's checkout was the current merge commitMerge 51af78ce1d into 654781f6c2; onlybase.shawas stale.Why it matters
A contributor who did exactly what the gate asks (rebase, one commit) is told to squash commits that are not theirs, and a re-run cannot clear it because it replays the same event. PR Hygiene is a PR Readiness lane, so the red holds the PR.
Not a goal
MAX_COMMITS) or the remedy text.code-review-history.sh) resolves its merge-base, or which base the Proof line / Sibling sweep steps read.base.sha.What changed (motivation → approach → change)
BASE..HEADfrom a stalebase.shaincludes every main commit between thatbase.shaand the commit the branch was rebased onto. The ci(review): diff base is the base-branch tip, so gates scan files the PR never touched #4968 note on this step ("a non-ancestor base still yields only the PR's own commits") holds when the base is ahead of the branch, not when the branch is ahead of the base.Resolve diff basestep has unshallowed the history. WhenHEAD's second parent is the PR head, the step now counts from that first parent and prints a notice saying so. Otherwise (no merge commit, or a different second parent) it keepsbase.sha.git cat-file -p HEADreads the parents from the commit object, asresolve-i18n-base.shdoes. TheBASEenv comment now saysbase.shais the fallback.Backwards compatibility
Compatible: when
base.shaalready equals the merge commit's first parent the count is unchanged; when it differs, the first parent is the newer base tip, so the range can only lose main commits that were never the PR's.Removes nothing: the gate, its limit and its message are unchanged; only the base of the range moves.
Tests
test/test_code_review_history_fetch.py:rebased-past-stale-base: the event'sbase_tipis the old fork point, the branch has one commit on top of a main that moved 31 commits, and the merge commit's first parent is that moved main.test_the_commit_range_and_the_rule_greps_run_on_the_fetched_historynow runsEnforce commit counton that case, handed the stalebase.shaasBASE, after the real diff-base step, and asserts it counts 1. The new case also runs throughtest_every_read_matches_a_full_clone_with_no_further_fetch.Negative control: with
pr-hygiene.ymlreverted to main, the test fails with('rebased-past-stale-base', "::error::PR must contain 1 or 2 commits (has 32). ..."), the #30034 shape.Proof: not provable -- other: the fix is a workflow shell step, which prove.py does not revert; the manual negative control above is the equivalent.
These tests skip on Windows. I ran them on Windows with the skip lifted, under Git Bash.
-k "commit_range or every_read"passes (5 passed) with the fix. The same file fully forced on Windows has 11 unrelated failures (shim and path quoting), identical on unmodified main. Linux CI runs it normally. With the normal skip,test_code_review_history_fetch.py,test_pr_hygiene_guidance.pyand the other pr-hygiene workflow test files pass: 1072 passed.Manual verification
N/A — unit coverage sufficient: the test executes the workflow's own
Resolve diff baseandEnforce commit countsteps against a real shallow merge-commit checkout.Real-machine verification
Machine: own computer, Windows 11 Home 10.0.26200, x86_64, Git Bash
Before (main ade7524):
pytest test/test_code_review_history_fetch.py -k commit_range(Windows skip lifted) ->PR must contain 1 or 2 commits (has 32)forrebased-past-stale-base, 1 failedAfter (head 438b937): same command -> passed
Cleanup: own computer
Related Issues
Fixes #39016
Checklist
feat|fix|docs|style|refactor|perf|test|chore|ci|build|revert: ...)Contribution License Agreement
🤖 Generated with Claude Code