Repository navigation
fix(git): keep the diff when git diff --no-index exits 1 - #4717
Open
coseto6125 wants to merge 1 commit into
Open
coseto6125 wants to merge 1 commit into
coseto6125 wants to merge 1 commit into
Conversation
git diff --no-index implies --exit-code, so differing inputs exit 1 with the diff on stdout. The compact path treated every non-zero exit as a failure and printed only stderr, so the diff vanished. Treat exit 1 with non-empty stdout as a difference, keep forwarding git's stderr (warnings such as core.autocrlf), and return git's exit code.
📊 Automated PR Analysis
SummaryFixes Review Checklist
Analyzed automatically by wshm · This is an automated analysis, not a human review. |
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
rtk git diff --no-index a bprinted nothing when the two files differed.--no-indeximplies--exit-code, so git exits 1 and puts the diff on stdout. The compact path inrun_diffread every non-zero exit as a failure, printed only stderr and returned. On two small differing files, plaingit diff --no-indexprinted 106 bytes;rtk git diff --no-indexprinted 0 bytes and exited 1. An agent behind the hook saw a failed command and no diff.--no-indexon a missing file) and every other non-zero exit keep the old error path. git's stderr is forwarded in both cases, so warnings such ascore.autocrlfstill reach the caller.run_diffhas two callers,git_cmd::run(rtk git diff) andgt_cmd::run_other(gt diff), and both pass the code through. Agit revertof this commit restores the old behaviour.Related: #3257 shows the same "prints nothing" symptom with a different trigger (diff size). #1981 introduced the raw passthrough for
--exit-code, which is whyrtk git diff --exit-codealready keeps its output.Test plan
cargo fmt --all && cargo clippy --all-targets && cargo test: fmt and clippy are clean. 4534 passed, 1 failed:git_log_malformed_digit_run_propagates_real_git_error, which fails the same way ondevelopwithout this change. It expects newer git'snot an integerwording, and local git 2.43.0 printsnot a non-negative integer.rtk git diff --no-index x.txt y.txtoutput inspected (stat header plus the compacted hunk, exit 1).tests/guard_integration_test.rs: differing files keep the diff and exit 1; identical files exit 0; a missing file surfaces git's error with empty stdout and exit 1; acore.autocrlfwarning reaches stderr alongside the diff. With the fix reverted, the differing-files and warning tests fail (the diff must survive git's exit 1: "").tests/rewrite_exit_code_test.rspin the exit codes ofgit diff --no-index(1 for differing files, 0 for identical) across the hook rewrite.