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
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-04 22:54:50 +00:00
1 parent a988275347
commit 1ccf246598
3 files changed
+38 -3

No files matched your search

+5 -1
View File
@@ -57,7 +57,11 @@ The hook is a guardrail against accidents. Server-side branch protection is the
- git aliases, shell variables such as `$BRANCH`, scripts, `bash -c`, command substitution inside double quotes, or pushes made through an MCP server
- git config that redirects a push (`push.default=upstream`, `remote.<name>.push`)
- a push behind a wrapper option that takes a separate value, such as `sudo -u <user>` or `env -u <name>`
- a bare `git push`, `HEAD` or `@` when the branch is not known: after a branch change in the same command other than a literal `git switch main` or `git checkout main`, after a `cd` to a path that is not literal, or with `--git-dir` or `GIT_DIR=`
- a command line the hook cannot parse, for example `$'...'` with an escaped quote
- a bare `git push`, `HEAD` or `@` in a command that makes the branch unknown:
- an earlier `git switch` or `git checkout` to anything but a literal `main`, `git branch -m`, `git rebase <upstream> <branch>`, `gh pr checkout` or `tea pr checkout`
- an earlier `cd` to a path that is not literal
- `--git-dir`, `GIT_DIR=` or `xargs` on the push itself
### Opt-out