Skip to content

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

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

FlorianBruniaux merged 1 commit into
rtk-ai:developfrom
ousamabenyounes:fix/issue-1215

Conversation

@ousamabenyounes

@ousamabenyounes ousamabenyounes commented Apr 11, 2026 •

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 Ora Studio
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 (#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 <[email protected]>

@FlorianBruniaux FlorianBruniaux left a comment

Copy link
Copy Markdown
Contributor

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
FlorianBruniaux added a commit that referenced this pull request Apr 14, 2026
Follow-up to #1217. The original heuristic classified any arg containing
'/' as a file-system path, so 'rtk git diff origin/main' became
'git diff -- origin/main' — git then looked for a file named origin/main,
returned nothing, and the diff was silently empty.

Fix: use cheap syntactic signals first (explicit path prefixes, range
syntax with '..'  or '^'), then for ambiguous slash/@ args delegate to
'git rev-parse --verify --quiet'. If git confirms the arg is a valid ref,
no '--' is injected. If git doesn't know the arg, it is treated as a path.

This preserves the original #1215 fix (clap consuming '--' before paths)
while correctly handling remote branch refs, feature branches, and reflog
syntax.

Added 6 regression tests covering origin/master, ranges, parent syntax,
and the ref-then-path combination.

Signed-off-by: Florian BRUNIAUX <[email protected]>
Signed-off-by: Florian BRUNIAUX <[email protected]>
thehoff pushed a commit to thehoff/contextcrawler that referenced this pull request May 14, 2026
thehoff pushed a commit to thehoff/contextcrawler that referenced this pull request May 14, 2026
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