fix(git): re-insert -- separator when clap consumes it from git diff args (#1215)#1217
Merged
FlorianBruniaux merged 1 commit intortk-ai:developfrom Apr 13, 2026
Merged
Conversation
Collaborator
📊 Automated PR Analysis
SummaryFixes a bug where clap's trailing_var_arg silently consumes the Review Checklist
Linked issues: #1215 Analyzed automatically by wshm · This is an automated analysis, not a human review. |
…args (rtk-ai#1215) clap's trailing_var_arg=true silently drops -- when it appears as the first positional argument. This caused `rtk git diff -- <path>` to arrive in run_diff without the separator, making git treat the path as a revision and emit "fatal: ambiguous argument". Adds normalize_diff_args() which re-inserts -- before the first path-like argument (contains /, \, starts with . or ~) when -- is absent from the args vec. The fix is a no-op when -- is already present (e.g. rtk git diff HEAD -- file preserves the separator correctly). Generated by Claude Code Vibe coded by ousamabenyounes Co-Authored-By: Claude <noreply@anthropic.com>
c61f19f to
9979c69
Compare
FlorianBruniaux
approved these changes
Apr 13, 2026
Collaborator
FlorianBruniaux
left a comment
There was a problem hiding this comment.
LGTM — clean fix, tests pass.
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.
Summary
Fixes #1215
normalize_diff_args()which re-inserts--before the first path-like argument when clap'strailing_var_arg = truesilently consumed itlooks_like_path()heuristic: args containing/,\, or starting with./~are treated as paths--is already present — sortk git diff HEAD -- file(where clap preserves the separator) is unaffectedRoot cause
clap'strailing_var_arg = truetreats--as the option terminator and drops it when it appears as the first positional argument. Result:The fix normalises
argsat the start ofrun_diffbefore any git command is built.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test --allnormalize_diff_args: no-op, path-with-slash, ref+path, flag+path, pure-flags, dotfile, bare-refFiles changed
src/cmds/git/git.rslooks_like_path,normalize_diff_args, call inrun_diff, 7 testsGenerated by Claude Code
Vibe coded by ousamabenyounes