Skip to content

Fix git show rev:path output formatting and duplication#248

Merged
pszymkowiak merged 1 commit intortk-ai:masterfrom
stringer07:fix-bug-branch
Feb 28, 2026
Merged

Fix git show rev:path output formatting and duplication#248
pszymkowiak merged 1 commit intortk-ai:masterfrom
stringer07:fix-bug-branch

Conversation

@stringer07
Copy link
Contributor

Title: Fix duplicate and truncated output for git show rev:path commands

Description

Motivation and Context
Previously, when using this tool to view the contents of a specific file at a specific revision (e.g., git show <rev>:<path>), the tool failed to recognize it as a raw blob request. Instead, it treated the output as a standard commit diff.

This resulted in two critical bugs:

  1. Duplicated Output: Because the raw file blob was incorrectly passed down to the diff formatting/compacting logic, the file contents were printed multiple times.
  2. Corrupted File Content: In the fallback passthrough mode, the output was unconditionally printed using println!("{}", stdout.trim());. This stripped all intentional leading/trailing empty lines and forced an unwanted trailing newline.

Steps to Reproduce the Bug:
Running a command piped to grep, such as:

rtk git show develop:modules/pairs_backtest.py | grep -n "def _align_arrays"

Expected: A single line showing the matched function signature.
Actual: Duplicate matches returned because the wrapper output the entire file contents twice.

Changes Proposed

  • Added is_blob_show_arg: A helper function to detect the rev:path syntax (arguments containing : and not starting with -).
  • Introduced wants_blob_show flag: When a blob request is detected, the command execution routes to a strict passthrough mode.
  • Fixed Output Formatting: For blob outputs, the code now uses print!("{}", stdout); instead of println!("{}", stdout.trim());, ensuring the raw file content is preserved exactly as Git outputs it.
  • Added Unit Tests: Included test_is_blob_show_arg to verify the argument parsing logic handles branches, paths, and formatting flags correctly.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Refactoring

Testing

  • Added unit tests for argument detection (test_is_blob_show_arg).
  • Manually verified that rtk git show develop:modules/pairs_backtest.py | grep now correctly outputs exactly one match, and file trailing newlines are perfectly preserved.

heAdz0r added a commit to heAdz0r/rtk that referenced this pull request Feb 28, 2026
…tk-ai#217, rtk-ai#196, rtk-ai#248, rtk-ai#211, rtk-ai#200, rtk-ai#192, rtk-ai#268)

Wave 1 (critical bugs):
- fix(registry): fi/done moved to IGNORED_EXACT — find no longer shadowed (rtk-ai#246)
- fix(playwright): f64 duration, specs[] structure, --reporter=json after subcmd (rtk-ai#193)
- fix(gh): should_passthrough_gh_view for --json/--jq/--template/--web in view_pr/issue/run (rtk-ai#217+196)

Wave 2 (reliability):
- fix(git): is_blob_show_arg — blob show passthrough without trailing-newline trim (rtk-ai#248)
- fix(find): parse_find_args with native -name/-type/-maxdepth/-iname support (rtk-ai#211)
- fix(main): graceful Clap fallback + parse_failures SQLite table + rtk gain --failures (rtk-ai#200)

Wave 3 (UX):
- feat(git): global options -C/-c/--git-dir/--work-tree/--no-pager/--no-optional-locks/--bare/--literal-pathspecs (rtk-ai#192)
- feat(proxy): streaming output via spawn()+threads instead of buffered output() (rtk-ai#268)

Tests: 1091 → 1117 (+26), 0 regressions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@pszymkowiak
Copy link
Collaborator

Clean fix. The is_blob_show_arg heuristic (contains(':') && !starts_with('-')) correctly distinguishes HEAD:src/main.rs from --pretty=format:%h. Routing blob requests directly to
passthrough avoids the double-output from the compact-show pipeline, and switching to print! (no trim) preserves exact file content including intentional trailing newlines.

All git tests pass. LGTM.

@pszymkowiak pszymkowiak merged commit a6f65f1 into rtk-ai:master Feb 28, 2026
maxkulish added a commit to maxkulish/rtk that referenced this pull request Mar 2, 2026
Bug fixes (4):
- fix(registry): move "fi"/"done" to IGNORED_EXACT to prevent shadowing
  find commands (rtk-ai#246)
- fix(hook): filter docker compose rewrites to supported subcommands
  only (ps/logs/build), avoid hard failures on up/down/exec (rtk-ai#245)
- fix(git): add is_blob_show_arg() to prevent duplicate output on
  git show rev:path style args (rtk-ai#248)
- fix(go): surface build failures (build-output/build-fail/FailedBuild)
  in go test -json summary (rtk-ai#274)

Features (2):
- feat(mypy): add rtk mypy command with grouped error output, 80% token
  reduction; delegate from lint_cmd.rs; add hook rewrites and registry
  entries (rtk-ai#109)
- feat(gain): add --project/-p flag to scope rtk gain stats to the
  current working directory; add shorten_path() display helper (rtk-ai#128)

Tests: 501 passed (10 new tests added)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants