Skip to content

fix(diff): report modified-only diffs and follow diff exit convention#2394

Merged
aeppling merged 1 commit into
rtk-ai:developfrom
hgunduzoglu:fix/diff-modified-lines-false-identical
Jun 16, 2026
Merged

fix(diff): report modified-only diffs and follow diff exit convention#2394
aeppling merged 1 commit into
rtk-ai:developfrom
hgunduzoglu:fix/diff-modified-lines-false-identical

Conversation

@hgunduzoglu

Copy link
Copy Markdown
Contributor

Summary

Fixes #2364rtk diff reported 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_diff classifies similar lines (character-set similarity > 0.5, e.g. a: 1 vs a: 2) as modified, but the identical check in run() only tested added == 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 .txt repro worked only because x vs y has zero similarity and lands in added/removed.

Changes

  • src/cmds/git/diff_cmd.rs — extracted render logic into a pure, testable render_file_diff(); the identical check now uses diff.changes.is_empty(); returns the diff-convention exit code (0 = identical, 1 = differing), also fixing the secondary observation in the issue.
  • src/main.rsCommands::Diff propagates the exit code (same Result<i32> pattern as go_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

  • TDD: 4 new regression tests written first (red on the old logic), covering the exact repro cases from the issue (a: 1/a: 2 YAML, {"a": 1}/{"a": 2} JSON, identical files, added/removed .txt).
  • cargo fmt --all --check && cargo clippy --all-targets && cargo test — clean, 2154 passed.
  • Manual verification of all repro scenarios from the issue with the built binary (output + exit codes match /usr/bin/diff semantics).

Behavior change note

rtk diff previously always exited 0. It now exits 1 when files differ, matching diff convention — as requested in the issue's "Expected" section, and required by scripts using diff && echo same semantics under the hook rewrite.

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
@CLAassistant

CLAassistant commented Jun 11, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@aeppling

Copy link
Copy Markdown
Contributor

Hey @hgunduzoglu , PR look clean and solve the issue

Follow-up

Merging 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

LGTM

Thanks for contributing !

@aeppling aeppling merged commit 3a73bcd into rtk-ai:develop Jun 16, 2026
12 checks passed
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.

rtk diff reports differing YAML/JSON files as identical

3 participants