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
This commit is contained in:
Defame1297andClaude Opus 5.5 committed 2026-12-04 22:19:49 +00:00
1 parent 038da3014e
commit a988275347
3 files changed
+167 -58

No files matched your search

+2 -1
View File
@@ -56,7 +56,8 @@ 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 bare `git push`, `HEAD` or `@` after a `cd`, `git switch` or `git checkout` in the same command, because the branch is not known yet
- 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=`
### Opt-out