fix(ci): run prek over all files when a push has no base commit - #1127
Merged
Conversation
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
prek-check.ymlpassesgithub.event.beforestraight toprek run --from-ref:A push that creates a branch reports
beforeas the all-zero SHA, which is git's "this ref did not exist" sentinel rather than a commit. The resulting range is invalid, so prek dies while collecting files — before a single hook runs:The workflow triggers on
pushtonextandrelease/**.nextalways exists, sobeforeis always a real commit there and the bug stayed latent — all 30 most recent push-event runs are onnextand all passed. Cuttingrelease/0.6.0-rc0produced the first push-event run on a newly created branch, and it failed instantly (run 32810551612). Every futurerelease/**branch would fail the same way on its first push.Re-running does not help:
beforeis part of the event payload, so a re-run replays the same all-zero SHA.A force-push has the same shape —
beforecan name a commit this clone no longer has — so the guard covers that too rather than only special-casing the zero SHA.Fix
Resolve
beforefirst, and check every file when it is not a usable commit:Checking all files is the correct fallback, not merely a safe one: when there is no base commit there is no "changed files" set to narrow to, and a new branch's entire tree is what is being introduced. The SHAs move to
env:so they reach the shell as data rather than being interpolated into the script text.The incremental path is unchanged for the normal case. The checkout is
fetch-depth: 0, so a realbeforealways resolves and keeps taking the range branch; the fallback fires only when the range genuinely cannot be built.Verification
Guard evaluated against all three inputs, in a real clone:
before0000...0000dead...beefprek run --all-filespasses on the current tree — all 14 hooksPassed, exit 0 — so the fallback does not trade one failure for another.prek run --from-ref HEAD~1 --to-ref HEADstill exits 0 on the range path.prekjob's step count is unchanged at 7.Note on scope of the evidence: the
pushtrigger is restricted tonextandrelease/**, so pushing this branch produced no push-event run and this PR's own CI exercises only thepull_requeststep, which is unchanged. The fallback path is verified locally (table above); the live evidence that a branch-creation push reports the all-zero SHA is the linkedrelease/0.6.0-rc0failure. A full end-to-end check would mean creating a throwawayrelease/**branch after this merges.