Skip to content

ci(pre-commit): protect main and versions/ branches from direct commits - #24

Closed
nstarman wants to merge 4 commits into
mainfrom
add-no-commit-to-branch
Closed

nstarman wants to merge 4 commits into
mainfrom
add-no-commit-to-branch

Conversation

@nstarman

Copy link
Copy Markdown
Contributor

Summary

  • Adds the no-commit-to-branch hook from pre-commit-hooks to .pre-commit-config.yaml
  • Protects main (--branch main) and any versions/* maintenance branch (--pattern ^versions/.*) from direct commits
  • Runs both locally (pre-commit run) and on pre-commit.ci

Test plan

🤖 Generated with Claude Code

nstarman and others added 4 commits September 15, 2026 10:23
Adds the no-commit-to-branch hook from pre-commit-hooks, blocking
direct commits to main and any versions/* branch. Runs on pre-commit.ci
and locally via `pre-commit run`.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
always_run is already the hook's shipped default, but setting it
explicitly documents that this hook intentionally ignores any
files/exclude/types filtering (and would still allow --allow-empty
commits through).

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
With default_stages: [pre-commit, pre-push] set repo-wide, this hook
would also run on pre-push. It checks the currently checked-out
branch, not the ref being pushed, so a maintainer sitting on main and
pushing a release tag (or anything else) would be blocked even though
they aren't committing to main. Restricting to stages: [pre-commit]
keeps the guard at the point it's meant for -- a local `git commit` --
without touching pre-push at all.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
The archaeology (why pre-commit's nodeenv/pyyaml floors mattered, why
--skip clobbers, the full CI-checkout explanation) belongs in commit
history, not permanently inline. Keeps just enough to orient a future
reader without re-litigating the whole investigation.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@nstarman nstarman added this to the infinity and beyond milestone Sep 15, 2026
@nstarman nstarman closed this Sep 15, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant