fix(git): preserve patch content when git log -p is used#2296
Open
ousamabenyounes wants to merge 2 commits into
Open
fix(git): preserve patch content when git log -p is used#2296ousamabenyounes wants to merge 2 commits into
git log -p is used#2296ousamabenyounes wants to merge 2 commits into
Conversation
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>
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.
Problem
When agents use
git log -pto inspect git history, RTK strips the patch/diff content, replacing it with[+N lines omitted]markers. The-pflag 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 runsfilter_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/--patchis detected, RTK skips its--pretty/limit/--no-mergesdefaults and the commit-block filter, printing git's raw output verbatim. Normalgit log/--onelinebehaviour is unchanged.The filter-vs-passthrough decision is now a single pure function (
finalize_log_output), andrun_logbuilds the command once instead of duplicating the exec/error/print/timer block.Testing — RED → GREEN
New unit tests over a real
git log -pfixture (tests/fixtures/git_log_p_raw.txt).GREEN — with the fix:
RED — fix reverted (
finalize_log_outputalways filters):The reverted code collapses the entire diff into
[+17 lines omitted]; the fix preserves every hunk.Full suite + lint:
Closes #2275