fix: /diff shows changes since the most recent message, not the previous one#5394
Open
nolanchic wants to merge 1 commit into
Open
fix: /diff shows changes since the most recent message, not the previous one#5394nolanchic wants to merge 1 commit into
nolanchic wants to merge 1 commit into
Conversation
…ous one raw_cmd_diff used commit_before_message[-2] as the diff base, but that entry is the head recorded before the PREVIOUS message. Once two or more messages had been processed in a session, /diff (and the auto-shown post-commit diff) displayed changes accumulated since the previous message rather than the current one. For messages that produced multiple commits (reflections), the old `current_head + "^"` fallback only went back a single commit, so it showed just the last reflection's diff. Use commit_before_message[-1] (matching show_undo_hint) and fall back to `current_head + "^"` only when no message has been recorded yet. Adds a regression test.
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
/diff(and the diff aider auto-shows after each commit) displayed changes accumulated since the previous message instead of the current one, once two or more messages had been processed in a session.raw_cmd_diffusedcommit_before_message[-2]as the diff base. Butcommit_before_messageis appended exactly once per top-level message (ininit_before_message, before the message is processed), so:[-1]= head recorded before the most recent message (correct base for "diff since the last message")[-2]= head recorded before the previous message (what the code used)The sibling method
show_undo_hintalready uses[-1], so the two disagreed.There was a second, related defect on the same path: the
len(...) < 2fallback usedcurrent_head + "^", which only goes back a single commit. For a message that produced multiple commits (e.g. via reflections), that showed just the last reflection's diff rather than the whole message's changes.Fix
aider/commands.py—raw_cmd_diff:This matches
show_undo_hint(base_coder.py), and only falls back tocurrent_head + "^"when no message has been recorded yet (empty list).Test plan
test_cmd_diff_since_last_message_not_previous— builds three commitsC0 -> C1 -> C2, setscommit_before_message = [C0, C1](HEAD =C2), and asserts/diffproduces theC1..C2diff (notC0..C2). Fails onmain, passes with the fix.pytest tests/basic/test_commands.py— 71 passed (incl. the existingtest_cmd_diff).pytest tests/basic/ -k "diff or undo or commit"— 30 passed.pre-commit run --files aider/commands.py tests/basic/test_commands.py— isort / black / flake8 / codespell all pass.