fix: gate remote branch deletion pushed as an empty refspec - #130
Open
Arakiss wants to merge 3 commits into
Open
fix: gate remote branch deletion pushed as an empty refspec#130Arakiss wants to merge 3 commits into
Arakiss wants to merge 3 commits into
Conversation
git push origin :main deletes the remote branch. The bash-git-push mapper captured the whole refspec, so that command emitted git.push:refs/heads/:main, which matches no branch gate. The result was that deleting main was allowed outright while an ordinary push to the same branch required a picto. Adds a mapper for the empty-source refspec that emits the destination branch, so existing branch gates apply, plus a git.push.delete capability. The new gate-remote-branch-delete rule covers every branch rather than only protected ones: deleting a colleague's feature branch destroys shared work even where pushing to it is allowed. Verified against a copy of a real policy tree: git push origin :main, :dev and :feat/algo all move from allow to ask_picto, while git push origin main, git push --force origin main and git push origin feat/x keep their previous decisions. Two regression fixtures cover the deletion cases.
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.
git push origin :maindeletes the remote branch. Today that command is allowed outright, while an ordinarygit push origin mainrequires a signed picto.Cause.
bash-git-pushcaptures the whole refspec intoref, so:mainemitsgit.push:refs/heads/:main. No branch gate matches that string and the call falls through to allow.Fix. A mapper for the empty-source refspec that emits the destination branch, so the existing branch gates apply, plus a dedicated
git.push.deletecapability. The newgate-remote-branch-deleterule covers every branch, not only protected ones: deleting a colleague's feature branch destroys shared work even where pushing to it is allowed.Mappers accumulate rather than short-circuit (
mapper.rs:154), so adding one does not alter existing rules.Verified against a copy of a real policy tree, comparing the shipped binary with the built one:
git push origin :maingit push origin :devgit push origin :feat/algogit push origin maingit push --force origin maingit push origin feat/xTwo regression fixtures added to
examples/policy-fixtures.yaml, which CI already runs.cargo fmt --checkclean,cargo clippy --all-targets -- -D warningsclean, 155 tests pass.