Skip to content

fix(git): re-insert -- separator when clap consumes it from git diff args (#1215)#1217

Merged
FlorianBruniaux merged 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1215
Apr 13, 2026
Merged

fix(git): re-insert -- separator when clap consumes it from git diff args (#1215)#1217
FlorianBruniaux merged 1 commit intortk-ai:developfrom
ousamabenyounes:fix/issue-1215

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

Summary

Fixes #1215

  • Adds normalize_diff_args() which re-inserts -- before the first path-like argument when clap's trailing_var_arg = true silently consumed it
  • Adds looks_like_path() heuristic: args containing /, \, or starting with ./~ are treated as paths
  • No-op when -- is already present — so rtk git diff HEAD -- file (where clap preserves the separator) is unaffected

Root cause

clap's trailing_var_arg = true treats -- as the option terminator and drops it when it appears as the first positional argument. Result:

rtk git diff -- apps/.../MyComponent.tsx
  → args = ["apps/.../MyComponent.tsx"]   # -- was consumed
  → git diff --stat apps/.../MyComponent.tsx
  → fatal: ambiguous argument 'apps/...': unknown revision or path

The fix normalises args at the start of run_diff before any git command is built.

Test plan

  • cargo fmt --all && cargo clippy --all-targets && cargo test --all
  • 7 new unit tests for normalize_diff_args: no-op, path-with-slash, ref+path, flag+path, pure-flags, dotfile, bare-ref
  • 1380 tests pass (baseline: 1373), 0 regressions

Files changed

File Change
src/cmds/git/git.rs Add looks_like_path, normalize_diff_args, call in run_diff, 7 tests

Generated by Claude Code
Vibe coded by ousamabenyounes

@pszymkowiak pszymkowiak added bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal labels Apr 11, 2026
@pszymkowiak
Copy link
Copy Markdown
Collaborator

[w] wshm · Automated triage by AI

📊 Automated PR Analysis

🐛 Type bug-fix
🟡 Risk medium

Summary

Fixes a bug where clap's trailing_var_arg silently consumes the -- separator in git diff args, causing git to misinterpret file paths as revisions. Also fixes a secondary issue where user-format git log output was being incorrectly truncated, corrupting programmatic output like SHA hashes.

Review Checklist

  • Tests present
  • Breaking change
  • Docs updated

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>
Copy link
Copy Markdown
Collaborator

@FlorianBruniaux FlorianBruniaux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — clean fix, tests pass.

@FlorianBruniaux FlorianBruniaux merged commit f2985ac into rtk-ai:develop Apr 13, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working effort-small Quelques heures, 1 fichier filter-quality Filter produces incorrect/truncated signal

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants