fix: don't expand numeric args that are flag values or branch names#145
fix: don't expand numeric args that are flag values or branch names#145
Conversation
scmpuff exec blindly expands any bare integer to a $eN file shortcut.
This breaks commands where the integer is a flag value ("git log -n 1"
becomes "git log -n <filepath>") or a branch name ("git checkout -b 713"
becomes "git checkout -b <filepath>", or empty string if unset).
Fixes #69, fixes #81.
Add a skipExpansion check in Expand() that recognizes when an integer
token immediately follows a flag that expects a value. This is gated on
args[0] matching SCMPUFF_GIT_CMD so it only activates for commands
routed through the shell wrapper. The flag allowlist is per-subcommand:
log: -n, --max-count, --skip, --min-parents, --max-parents
checkout: -b, -B, --orphan
blame: -L
rebase: -C
Only flags that accept a space-separated numeric value on subcommands
intercepted by the shell wrapper need coverage. Glued forms like "-n1"
are already safe because the combined token doesn't match the digit
regex. Same-named flags on other subcommands (e.g. "git rm -n" which is
--dry-run) are intentionally not listed, so their following args still
expand normally.
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
ff814bc to
253e2c6
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes scmpuff exec numeric shortcut expansion for Git commands where a bare integer token is actually a flag value (e.g. git log -n 1) or an argument like a numeric branch name (e.g. git checkout -b 713), preventing accidental expansion into $eN placeholders.
Changes:
- Add
skipExpansionlogic inarguments.Expandto avoid expanding tokens that are values for a small allowlist of Git flags (scoped to commands whereargs[0] == SCMPUFF_GIT_CMD). - Add Go unit tests covering protected numeric flag values and numeric branch names.
- Add a testscript
.txtarintegration test validatingscmpuff expandoutput for these scenarios.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/arguments/arguments.go | Adds skipExpansion and wires it into Expand to prevent incorrect numeric expansion for specific Git flag-value positions. |
| internal/arguments/arguments_test.go | Adds table-driven tests to ensure numeric flag values/branch names remain literal while still expanding true file shortcuts and ranges. |
| internal/cmd/testdata/script/command-expand-numeric-flags.txtar | Adds integration coverage verifying CLI-level expansion behavior via scmpuff expand. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
In the interest of soundness, I had Codex 5.3 (OpenAI) cross-review this PR, as the original implementation was produced by Claude Opus 4.6 (Anthropic). The review found some gaps. Below is the full review report from Codex, followed by the response plan Opus derived from it. Codex 5.3 Review Report
Claude Opus 4.6 Response Plan
|
Address review findings: remove --min-parents/--max-parents (not accepted in space-separated form on current Git), add protections for commit/merge -m, log --grep, and rebase --onto. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
82496cc to
1e18e0b
Compare
|
Followup cross-analysis from Opus 4.6, independently verifying the Codex findings and testing additional flags not covered in the original review:
|
Note
🤖 LLM Usage: I had previously attempted to tackle this years ago in #70 and got frustrated with the level of undocumented edge case tedium (see my comments in #69). With modern LLM models, it's actually a great use case for just tasking an agent loose in a container to exhaustively test different permutations and see their behavior. Thus the skipExpansion list in this PR is the results of Opus 4.6 spending a half hour trying all the flag combinations it could find from git help. I have verified the code produced and the test methodology, but additional human review on this one may be warranted. I'm still a little "meh" about introducing this level of git UI edge case parsing into scmpuff itself, so thoughts are welcome!
scmpuff execblindly expands any bare integer to a$eNfile shortcut.This breaks commands where the integer is a flag value (
git log -n 1becomes
git log -n <filepath>) or a branch name (git checkout -b 713becomes
git checkout -b <filepath>, or empty string if unset).Add a
skipExpansioncheck inExpand()that recognizes when an integertoken immediately follows a flag that expects a value. This is gated on
args[0]matching$SCMPUFF_GIT_CMDso it only activates for commandsrouted through the shell wrapper. The flag allowlist is per-subcommand:
Only flags that accept a space-separated numeric value on subcommands
intercepted by the shell wrapper need coverage. Glued forms like
-n1are already safe because the combined token doesn't match the digit
regex. Same-named flags on other subcommands (e.g.
git rm -nwhich is--dry-run) are intentionally not listed, so their following args stillexpand normally.
Fixes #69. Fixes #81. Supersedes #70.