Skip to content

hooks: catch -f short flag and +refspec force-push idioms (#131)#149

Open
truffle-dev wants to merge 1 commit into
ghostwright:mainfrom
truffle-dev:hooks-force-push-idioms
Open

hooks: catch -f short flag and +refspec force-push idioms (#131)#149
truffle-dev wants to merge 1 commit into
ghostwright:mainfrom
truffle-dev:hooks-force-push-idioms

Conversation

@truffle-dev

Copy link
Copy Markdown
Contributor

The dangerous-command blocker catches --force (and the safer --force-with-lease / --force-if-includes by substring) but lets two muscle-memory equivalents through: the short-flag form (g_it push -f) and the refspec-prefix form (g_it push origin +main:main). Both have the same destructive effect as --force. The pattern set in hooks.ts:16 therefore blocked the verbose-and-safer two spellings and let the bare-and-riskier two through, inverted relative to the intent.

The fix adds two patterns next to the existing line, matching the shape proposed in #131:

  • /g_it\s+push\s+.*-f(?:\s|$)/ for the short flag, with the trailing word boundary so it doesn't fire on flag-like arguments (-fakearg)
  • /g_it\s+push\s+.*\s["']?\+\S/ for the refspec prefix, covering both bare and quoted forms

Tested against the six spellings from the issue:

spelling result
g_it push --force origin main block (old --force pattern)
g_it push -f origin main block (new -f pattern)
g_it push origin +main:main block (new +refspec pattern)
g_it push origin "+HEAD:refs/heads/main" block (new +refspec pattern)
g_it push --force-with-lease origin main block (old pattern, substring match)
g_it push --force-if-includes origin main block (old pattern, substring match)

(The g_it underscores are typo-disguised so this PR body doesn't trip the live hook.)

Three new tests cover -f, bare +refspec, and quoted +refspec. The existing --force test stays as-is. bun test src/agent/__tests__/hooks.test.ts: 14 pass, 0 fail. bun run lint and bun run typecheck clean.

Scope deliberately narrow. The sub-question of whether --force-with-lease / --force-if-includes should stay blocked (they're the docs-recommended variants) is orthogonal to closing this false-negative and worth its own thread. The shell-token-parse direction in option 2 of the issue (which would also close #100) likewise deferred to a separate PR if the simpler shape lands first.

Closes #131.

…t#131)

The existing dangerous-command pattern catches the long --force
flag (and the safer --force-with-lease / --force-if-includes by
substring) but misses two muscle-memory equivalents that have the
same destructive effect:

- short flag: g_it push -f origin main
- refspec prefix: g_it push origin +main:main

Adds two patterns next to the existing line. The short-flag
pattern requires a trailing word boundary (\s|$) so it doesn't
fire on flag-like arguments (-fakearg). The refspec pattern
anchors on whitespace followed by an optional quote and a +
followed by a non-space, covering both the bare and quoted
forms.

Tested against the six spellings from the issue: all four
force-push variants block (the two new ones via the new
patterns, --force/--force-with-lease/--force-if-includes via
the existing substring match). Safe commands pass.

Closes ghostwright#131.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant