fix(diff): report modified-only diffs and follow diff exit convention#2394
Merged
aeppling merged 1 commit intoJun 16, 2026
Merged
Conversation
rtk diff treated files whose changes were all classified as modified (similar lines, e.g. "a: 1" vs "a: 2" in YAML/JSON) as identical, because the identical check only looked at added/removed counts. Report any non-empty change set as a difference, and exit 1 when files differ per diff convention (0 when identical). Fixes rtk-ai#2364
Contributor
|
Hey @hgunduzoglu , PR look clean and solve the issue Follow-upMerging this for the fix, but git diff will need some work to avoid breaking any signal, for now this is kind of tricky and should be cleaned LGTMThanks for contributing ! |
aeppling
approved these changes
Jun 16, 2026
This was referenced Jun 17, 2026
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.
Summary
Fixes #2364 —
rtk diffreported differing YAML/JSON files as[ok] Files are identical(exit 0), hiding real changes from agents comparing config files.Root cause
Not extension-related:
compute_diffclassifies similar lines (character-set similarity > 0.5, e.g.a: 1vsa: 2) as modified, but the identical check inrun()only testedadded == 0 && removed == 0, ignoring the modified count. Structured files like YAML/JSON trigger this because their changed lines stay near-identical character-wise; the issue's.txtrepro worked only becausexvsyhas zero similarity and lands in added/removed.Changes
src/cmds/git/diff_cmd.rs— extracted render logic into a pure, testablerender_file_diff(); the identical check now usesdiff.changes.is_empty(); returns the diff-convention exit code (0 = identical, 1 = differing), also fixing the secondary observation in the issue.src/main.rs—Commands::Diffpropagates the exit code (sameResult<i32>pattern asgo_cmd/core::runner).scripts/test-all.sh— diff smoke test updated for the exit convention (identical → ok, differing → non-zero + output contains changes).README.md— exit semantics documented in the command list.Testing
a: 1/a: 2YAML,{"a": 1}/{"a": 2}JSON, identical files, added/removed.txt).cargo fmt --all --check && cargo clippy --all-targets && cargo test— clean, 2154 passed./usr/bin/diffsemantics).Behavior change note
rtk diffpreviously always exited 0. It now exits 1 when files differ, matchingdiffconvention — as requested in the issue's "Expected" section, and required by scripts usingdiff && echo samesemantics under the hook rewrite.