Repository navigation
fix(agent-guard): read the empty-rebase refs where the push runs - #2033
Merged
potiuk merged 2 commits intoNov 9, 2026
Merged
Conversation
The empty-rebase guard ran its git checks in the hook's cwd. A branch rebased in a linked worktree and pushed with `cd <worktree> && git push` or `git -C <worktree> push` was judged by the main checkout's HEAD, which sits on the default branch, so a valid push was refused as empty. The guard now resolves `git -C`, and dispatch follows a literal `cd` earlier on the line, so the refs are read in the directory the push runs in. Generated-by: Claude Opus 5
Segments carry no separators or subshell depth, so a `cd` in a subshell (`(cd x); git push --force …`) would have moved the guard to a directory the push never runs in, and let an empty push through. Keep only the exact `git -C` resolution, and name `git -C <dir> push` in the deny message for a push made after a `cd`. Generated-by: Claude Opus 5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
git rev-parse/merge-base/rev-listchecks in the hook'scwdand ignoredgit -C. A branch rebased in a linked worktree and pushed withgit -C <worktree> push --force-with-lease … HEAD:<branch>was judged by the main checkout'sHEAD. That checkout sits on the default branch, so it has 0 commits over its merge-base and the valid push was refused: "refusing to force-push 'HEAD' — it has 0 commits over its merge-base with origin/main". Hit while rebasing a contributor's PR from apr-managementsession.guard_empty_rebasenow resolvesgit -Cwith the existing_git_start_dirhelper, asguard_commit_traileralready does.cd <worktree> && git push …is still judged in the hook's directory. Segments carry no separators or subshell depth, so the guard cannot tell it from(cd <worktree>); git push …, which pushes from the hook's directory. Following thecdwould let that empty push through. An earlier commit on this branch did follow it; the second commit takes that back. The deny message now namesgit -C <dir> pushas the spelling to use.The plugin copy and the secure-setup fingerprint are regenerated.
Type of change
tools/*/withpyproject.toml)Test plan
prek run --all-filespasses (not run: the checkout is sparse, because the sandbox denies writes to.apache-magpie-overrides/tools/vetted-ops/)uv run pytest/ruff check/mypypassesprek run --fileson the four changed files passes, includingcheck-family-pluginsandisolated-setup-fingerprint.test_empty_rebase_reads_the_repository_git_c_namesfails onmainand passes with this change.test_empty_rebase_still_denied_in_the_repository_git_c_nameschecks that an empty push is still refused in the directory-Cnames.test_empty_rebase_does_not_follow_cd_and_names_git_cpins thecdand subshell cases to the old directory and checks the new hint.RFC-AI-0004 compliance
No principles affected: this corrects where an existing guard reads state. It never allows a push the guard refused before, apart from a
git -Cpush whose named repository has commits, and it adds no mutation, host access or outbound message.Linked issues
None.
🤖 Generated with Claude Code