Repository navigation
fix: make the pre-push hook actually guard the default branch - #2
Merged
Merged
Conversation
Exercised with the stdin git supplies, the hook exited 0 on a push to main. default=$(git symbolic-ref ... | sed "s|^$remote/||" || echo main) sed exits 0 even when git failed, so the fallback never fired and default was silently empty — every guard below then compared against "refs/heads/" and matched nothing. Assign first, then test. The same mistake was in scripts/agent's default_branch, where it surfaced as an empty line in doctor. Here it was invisible: a guard that never fires looks exactly like a guard with nothing to catch. Verified both directions — refuses refs/heads/main, and still runs the full check for a feature branch.
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.
Problem
The
pre-pushhook was supposed to refuse a direct push to the default branch.It never did. Exercised with the exact stdin git supplies, it exited 0:
The cause is a pipeline-status bug:
sedexits 0 even whengitfailed, so the|| echo mainfallback never firesand
defaultis silently empty. Every subsequent guard then compares againstrefs/heads/and matches nothing.The same mistake was in
scripts/agent'sdefault_branch, where it showed up asan empty line in
scripts/agent doctor— visible, and fixed before it wascommitted. Here it was invisible, because a guard that never fires looks exactly
like a guard with nothing to catch.
Approach
Assign, then test. Also dropped a dead all-zero-sha line that did nothing;
deletions are refused by branch protection.
Look at this sceptically
Verified both directions, not just the refusal — a guard that rejects
everything would also have "passed" the first test:
refs/heads/mainrefs/heads/fix/xscripts/task check, passesHooks are advisory. Anyone can
--no-verify, and an agent that never ranscripts/setuphas no hooks at all. Branch protection on the remote is thereal enforcement; this only makes the failure fast and local.