You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* feat: block force pushes via pre-push hook
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
* docs: add push safety section to README and examples
* test: add coverage for validate_push API and push rule fallback
* Add force option to documentation for next version
* fix: fetch remote ref before force-push check
* chore: revert labeler.yml changes
* fix: use pre-commit push metadata
* fix: ensure pre-push hook always runs and remove -p short flag
- 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
0 commit comments