feat: block force pushes via pre-push hook#412
Conversation
Adds a `check-no-force-push` pre-push hook that detects and blocks `git push --force` / `git push -f` by inspecting pushed ref ancestry via `git merge-base --is-ancestor`. ## Detection logic Reads git's pre-push stdin (<local ref> <local sha> <remote ref> <remote sha>) and evaluates: - Remote SHA is zero -> new branch push -> pass - merge-base returns 0 -> fast-forward -> pass - Returns 1 -> force push detected -> fail - Returns 128 -> git error, pass (safe default) ## Standalone mode When run without stdin, --no-force-push checks whether pushing HEAD to its configured upstream would require force, using git ls-remote and optional git fetch to resolve the remote commit. Closes #203
✅ Deploy Preview for commit-check ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (19)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #412 +/- ##
==========================================
+ Coverage 95.51% 95.74% +0.22%
==========================================
Files 10 10
Lines 1004 1152 +148
==========================================
+ Hits 959 1103 +144
- Misses 45 49 +4 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
- Add always_run: true to check-no-force-push hook in .pre-commit-hooks.yaml to prevent pre-commit from skipping the hook when zero files changed (e.g. force push with identical tree, different history) - Remove -p short flag from --no-force-push CLI argument; the flag is exclusively used in pre-commit hooks, not interactive CLI use
|



Supersedes #410 with the same branch now hosted directly in commit-check/commit-check instead of the fork.
Includes the force-push blocking pre-push hook, CLI/API support, configuration handling, docs, and tests from the original PR.
Closes #203