Repository navigation
Conversation
There was a problem hiding this comment.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR updates the diff command to return meaningful process-style exit codes (0/1/2) instead of always returning success, and threads those exit codes back through the CLI dispatcher.
Changes:
- Change
diff_cmd::runanddiff_cmd::run_stdinto returnResult<i32>exit codes (0 identical, 1 different, 2 trouble). - Update CLI
Commands::Diffhandling to return the diff command’s exit code rather than always0. - Add unit tests validating the new exit-code behavior for identical, different, and missing-file scenarios.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main.rs | Returns the diff subcommand’s exit code from the CLI match arm. |
| src/cmds/git/diff_cmd.rs | Implements exit-code semantics for diff operations and adds tests for the new behavior. |
Comments suppressed due to low confidence (1)
src/cmds/git/diff_cmd.rs:1
- The exit-code values (
0and1here, plus2elsewhere) are currently “magic numbers”. Consider introducing named constants (e.g.,EXIT_OK,EXIT_DIFF,EXIT_TROUBLE) or a small enum to centralize and self-document the exit-code mapping—this also reduces the chance of future inconsistencies between call sites and tests.
//! Compares two files and shows only the changed lines.
| /// Ultra-condensed diff - only changed lines, no context | ||
| pub fn run(file1: &Path, file2: &Path, verbose: u8) -> Result<()> { | ||
| pub fn run(file1: &Path, file2: &Path, verbose: u8) -> Result<i32> { |
| let content1 = match fs::read_to_string(file1) { | ||
| Ok(content) => content, | ||
| Err(err) => { | ||
| eprintln!("rtk diff: failed to read {}: {}", file1.display(), err); | ||
| return Ok(2); | ||
| } | ||
| }; | ||
| let content2 = match fs::read_to_string(file2) { | ||
| Ok(content) => content, | ||
| Err(err) => { | ||
| eprintln!("rtk diff: failed to read {}: {}", file2.display(), err); | ||
| return Ok(2); | ||
| } | ||
| }; |
4bb84c2 to
3201982
Compare
3201982 to
feb4fbc
Compare
|
Closing as a duplicate of #2473, which makes the same fix: a read failure on either operand returns POSIX diff's exit 2 instead of collapsing into exit 1. Confirmed still live on 0.46.0 — #2473 was picked because its tests exercise the |
Fixes #2446.
Summary
rtk diffcompact output while returning POSIX-compatible exit codes.0when compared files are identical.1when compared files differ.2when either input file cannot be read.Verification
git diff --checkI could not run
cargo test diff_cmdlocally because this Windows environment does not have a Rust toolchain available.