feat: block force pushes via pre-push hook#400
Draft
Copilot wants to merge 6 commits into
Draft
Conversation
✅ Deploy Preview for commit-check ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
…e-push hook Agent-Logs-Url: https://github.com/commit-check/commit-check/sessions/92e9c4ea-08b4-4f09-b433-72a19aa53f97 Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com>
…improved docs Agent-Logs-Url: https://github.com/commit-check/commit-check/sessions/92e9c4ea-08b4-4f09-b433-72a19aa53f97 Co-authored-by: shenxianpeng <3353385+shenxianpeng@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Add feature to block force pushes from users
feat: block force pushes via pre-push hook
Apr 13, 2026
Member
|
pre-commit.ci autofix |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #400 +/- ##
==========================================
- Coverage 95.66% 95.19% -0.47%
==========================================
Files 10 10
Lines 991 1082 +91
==========================================
+ Hits 948 1030 +82
- Misses 43 52 +9 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
…cumentation updates
|
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.



Adds a
check-no-force-pushpre-push hook that detects and blocksgit push --force/git push -fby inspecting pushed ref ancestry viagit merge-base --is-ancestor.Detection logic
Reads git's pre-push stdin (
<local ref> <local sha> <remote ref> <remote sha>) and evaluates:git merge-base --is-ancestor <remote_sha> <local_sha>returns 0 → fast-forward → ✅ passNew components
ForcePushValidator(engine.py) — core validator reading pre-push stdinPUSH_RULES(rules_catalog.py) — new push rule catalog, parallel toCOMMIT_RULES/BRANCH_RULES[push]config section —allow_force_push = falseto enable blocking viacchk.tomlorCCHK_ALLOW_FORCE_PUSHenv varvalidate_push()(api.py) — programmatic API entry pointcheck-no-force-push(.pre-commit-hooks.yaml) — pre-push hook definition withstages: [pre-push]Usage
Or via CLI directly (e.g. in a custom pre-push script):
git push | commit-check --no-force-pushOr opt-in via config: