Skip to content

fix(git): preserve patch content when git log -p is used#2296

Open
ousamabenyounes wants to merge 2 commits into
rtk-ai:developfrom
ousamabenyounes:fix/issue-2275-git-log-p-patch
Open

fix(git): preserve patch content when git log -p is used#2296
ousamabenyounes wants to merge 2 commits into
rtk-ai:developfrom
ousamabenyounes:fix/issue-2275-git-log-p-patch

Conversation

@ousamabenyounes
Copy link
Copy Markdown
Contributor

@ousamabenyounes ousamabenyounes commented Jun 6, 2026

Problem

When agents use git log -p to inspect git history, RTK strips the patch/diff content, replacing it with [+N lines omitted] markers. The -p flag explicitly requests patch output, and this diff context is vital for diagnosing problems.

Root cause: with no format flag, RTK injects --pretty=format:…%b%n---END--- and then runs filter_log_output, which treats the diff hunks as commit body — keeping only 3 lines and discarding the rest behind [+N lines omitted].

Fix

When -p / --patch is detected, RTK skips its --pretty/limit/--no-merges defaults and the commit-block filter, printing git's raw output verbatim. Normal git log / --oneline behaviour is unchanged.

The filter-vs-passthrough decision is now a single pure function (finalize_log_output), and run_log builds the command once instead of duplicating the exec/error/print/timer block.

Testing — RED → GREEN

New unit tests over a real git log -p fixture (tests/fixtures/git_log_p_raw.txt).

GREEN — with the fix:

running 3 tests
test ...test_wants_patch_detects_explicit_flags ... ok
test ...test_finalize_preserves_patch_when_requested ... ok
test ...test_finalize_filters_when_no_patch_flag ... ok
test result: ok. 3 passed; 0 failed

RED — fix reverted (finalize_log_output always filters):

test ...test_finalize_preserves_patch_when_requested ... FAILED

assertion `left == right` failed: patch output must be byte-identical passthrough
  left: "commit a1ef0ef…\n  Author: …\n  Date:   …\n  [+17 lines omitted]"
 right: "commit a1ef0ef…\n…\ndiff --git a/Cargo.toml b/Cargo.toml\n@@ -1,6 +1,6 @@\n-version = \"0.42.1\"\n+version = \"0.42.2\"\n…"

test result: FAILED. 2 passed; 1 failed

The reverted code collapses the entire diff into [+17 lines omitted]; the fix preserves every hunk.

Full suite + lint:

cargo test --bin rtk   → 2070 passed; 0 failed; 7 ignored   (was 2067)
cargo fmt --all -- --check                 → clean
cargo clippy --all-targets -- -D warnings  → clean

Note: no token-savings test here — patch passthrough is intentionally a 0%-reduction path (the diff is the payload).

Closes #2275

ousamabenyounes and others added 2 commits June 6, 2026 15:43
When a user passes -p/--patch to git log, RTK no longer injects its own
--pretty=format markers or filters the output. The raw git output is
passed through directly, preserving the full diff/patch content that
agents need for diagnosing problems via git history.

Previously, RTK's filter_log_output would compress patch lines into
'[+N lines omitted]' markers, stripping vital diff context.

Closes rtk-ai#2275
…pe run_log

The original fix had ZERO tests. This adds real, revertible coverage and
removes the duplicated exec/error/print/timer block the patch branch copied.

- Extract `wants_patch()` and `finalize_log_output()` — the single
  filter-vs-passthrough decision — so the fix is unit-testable without
  shelling out to git.
- `run_log` now builds the command once and only injects RTK's
  --pretty/limit/--no-merges defaults on the non-patch path; the patch path
  prints git's raw output verbatim.
- tests/fixtures/git_log_p_raw.txt: real `git log -p` capture.
- test_finalize_preserves_patch_when_requested: GREEN with the fix, RED when
  reverted (diff content collapses to `[+17 lines omitted]`).
- test_finalize_filters_when_no_patch_flag + test_wants_patch_detects_explicit_flags.

Full suite: 2070 passed, 0 failed (was 2067). fmt + clippy -D warnings clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
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.

"git log -p" omits the patch requested by the -p flag

1 participant