hooks: cover -f and +refspec force-push spellings#132
Open
truffle-dev wants to merge 1 commit into
Open
Conversation
The dangerous-command blocker catches `--force` (including the `--force-with-lease` and `--force-if-includes` superstring forms) but misses two equivalent spellings: the short flag `-f`, and the refspec prefix `+<src>:<dst>` that tells the remote to accept a non-fast-forward update. Adds two patterns. The `-f` form uses a token-walk `(?:\\S+\\s+)*` + boundary lookahead so substrings like `--force-if-includes` and `-fwoo` don't trip it. The `+refspec` form requires whitespace (or a wrapping quote) immediately before the `+`, so a token like `tag+sign:main` is not a false positive. Closes ghostwright#131.
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.
Closes #131.
Problem
The dangerous-command blocker has one force-push pattern,
/git\s+push\s+.*--force/, which catches--force,--force-with-lease, and--force-if-includesvia substringprefix. It misses two equivalent spellings:
-f, same semantics as--force.+<src>:<dst>, where a leading+tellsthe remote to accept a non-fast-forward update.
The asymmetric coverage blocks the verbose-and-safer spellings
while letting the bare-and-riskier ones through.
Fix
Two additional patterns in
DANGEROUS_COMMANDS:The
-fpattern uses a token-walk(?:\S+\s+)*+ boundarylookahead so it matches
-fas a standalone flag and doesn'ttrip on substrings like
--force-if-includesor-fwoo.The
+refspecpattern requires whitespace (or a wrapping quote)immediately before the
+, so a+inside a token liketag+sign:maindoes not false-positive.Tests
Six new cases in
src/agent/__tests__/hooks.test.ts:git push -f origin maingit push origin +main:maingit push origin "+HEAD:refs/heads/main"git push --force-with-lease origin maingit push origin tag+sign:main+in token)ls -f /tmp-foutside push)Also prototype-tested 21 cases off-tree before edit covering
git fetch --force,git stash push --force,git config push.default current, quoted-refspec forms, and multi-flagpush lines.
Verification
bun test src/agent/__tests__/hooks.test.ts— 17/17 passorigin/main(handleEmailLogin Resend, loadConfig fixture-env, phantom init
yaml, assemblePrompt bare-metal); none touched by this PR