Repository navigation
fix(git): propagate exit code when commit fails instead of reporting ok - #2496
Merged
aeppling merged 3 commits intoJun 26, 2026
Merged
Conversation
run_commit had a branch that printed 'ok (nothing to commit)' and fell through to Ok(0) whenever git exited non-zero with a 'nothing to commit' message — so a no-op or hook-aborted commit was reported as success with exit 0. Gate strictly on output.status.success() via a CommitOutcome helper: any failure surfaces git's message and propagates the real exit code, matching native git. Same bug class as rtk-ai#1581 (push) and rtk-ai#1535 (stash). Fixes rtk-ai#2494
Contributor
|
Otherwise LGTM :) Thanks for your contribution to make git filter more transparent and faithful |
Merged
aeppling
approved these changes
Jun 26, 2026
| if !stdout.trim().is_empty() { | ||
| eprint!("{}", stdout); | ||
| CommitOutcome::Failed(code) => { | ||
| eprintln!("FAILED: git commit"); |
Contributor
There was a problem hiding this comment.
drop custom error messages, should return the git error message
| enum CommitOutcome { | ||
| /// Commit succeeded; carries the compact one-line summary for stdout. | ||
| Ok(String), | ||
| /// Commit failed; carries git's real exit code to propagate. |
Contributor
There was a problem hiding this comment.
clean up code comments, most of code is explicit enough
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 #2494.
rtk git commitreportedok (...)and returned exit 0 when the commit actually failed — same masking-failure class as #1581 (push) and #1535 (stash).Root cause
run_commitbranched like this:The
nothing to commitarm is only reachable whenoutput.status.success()is false (git exits 1 when there's nothing staged), yet it printedokand fell through toOk(0). A pre-commit hook abort hit the same masking.Fix
Gate strictly on
output.status.success()via a smallCommitOutcomehelper. Success keeps the compactok <hash>line; any failure surfaces git's own message and propagates its real exit code (with aFAILED: git commitheader, matchingrun_add/run_pull/run_stash). No success path can return non-zero, no failure path can return 0.Testing
classify_commit_outcome(success→ok <hash>, empty stdout→ok, nothing-to-commit→Failed(1), hook-abort→Failed(2)).cargo fmt --all --check && cargo clippy --all-targets && cargo test— clean, 2203 passed.FAILED+ exit 1 (was exit 0)ok <hash>+ exit 0 (no regression)FAILED+ exit 1No output-format change on the success path, so token savings are unaffected.