Repository navigation
fix: check every commit of a forced push over unfetched commits - #703
Conversation
A forced push over commits this clone never fetched hands the pre-push hook a remote sha the clone lacks. The pushed range cannot be read from it, and only the tip was checked: a file added by an earlier commit of the same push went through. The commits no remote-tracking ref reaches are now checked in that case, the same set a new branch is checked against. The tip alone remains the last resort when that cannot be computed either.
|
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #703 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 15 15
Lines 2705 2707 +2
Branches 536 537 +1
=========================================
+ Hits 2705 2707 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Merging this PR will improve performance by 65.89%2 warnings
Performance Changes
Tip Curious why performance improved? Comment Comparing Footnotes
|
Both tests passed made-up shas through the pre-push line and left get_push_commits unpatched, so git itself was asked about commits that do not exist. They now state the range, as the first test of the class does, and no longer start a git process.
|



Before: A forced push over commits the clone never fetched (someone else, or a bot, pushed to the branch in between) checked only the last commit of the push. The pre-push hook is given the remote's current sha, the clone does not have that object, so the pushed range could not be read and
get_push_commitsfell back to the tip. A file added by an earlier commit of the same push went through:After: The same push fails on the earlier commit:
When the range from the remote's sha cannot be read, the commits no remote-tracking ref reaches are checked instead of the tip alone.
How:
get_push_commitstries<remote>..<local>first, as before. If git cannot resolve it, it asks for<local> --not --remotes, the same set a new branch is already checked against. The tip alone stays as the last resort when neither can be computed. An ordinary push is unchanged and costs no extra git call; the second call is made only after the first one fails.This applies to everything that reads the pushed range: the
[files]rules (CC302, CC303, CC304) and the tag check on pre-commit's push stage. One side effect in the same case: forcing a branch back to a commit the remote already has now carries nothing to check, where it used to re-check that old commit.Tests: a real-git test for the forced push (both commits are returned, and a push with nothing new returns none); the existing fallback test still covers the last resort. Two
TestFilesValidatorpre-push tests passed made-up shas to real git and relied on that fallback; they now state the pushed range themselves and start no git process, which is also why their benchmarks no longer move with this change.Summary by CodeRabbit