feat(git): refuse git push to main with a Claude Code hook #282

Merged
Defame1297 merged 4 commits from feat/178-refuse-push-to-main into main 2026-12-05 20:33:16 +00:00
4 Commits
Author SHA1 Message Date
Defame1297andClaude Opus 5.5 1ccf246598 fix(git): treat rebase onto a named branch as a branch change
`git rebase <upstream> <branch>` checks out <branch>, so a later bare push was refused as if main
were still checked out. Pushes through xargs get refspecs the hook cannot see, so only an explicit
main is refused there.

Refs: #178

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-04 22:54:50 +00:00
Defame1297andClaude Opus 5.5 a988275347 fix(git): follow earlier branch changes in the push-to-main hook
Review found pushes refused after `gh pr checkout` or `git branch -m`, and pushes to main allowed
after `git switch main` or `cd <repo>`. The hook now follows literal branch and directory changes
and treats any other as unknown. Heredoc stripping is linear and handles several per line.

Refs: #178

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-04 22:19:49 +00:00
Defame1297andClaude Opus 5.5 038da3014e docs(adr): note the git push-to-main hook in ADR-0032
Refs: #178

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-04 21:18:12 +00:00
Defame1297andClaude Opus 5.5 77642183c2 feat(git): refuse git push to main with a PreToolUse hook
An agent on main can push straight to it when the server does not protect the branch. The git
plugin now ships a Claude Code hook that refuses such a push before it runs. It fails open, does
nothing on other runtimes, and has an opt-out read only from the hook's own environment.

Closes: #178

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_014uGZTNugst7K9Bd2FTR4Mi
2026-12-04 21:18:09 +00:00