Repository navigation
Conversation
`filter_status_with_args` joins kept lines with \n and has no terminal
newline; `never_worse` may instead return git's raw stdout, which does.
`print!` on either is wrong in one of the two cases, so the arg-carrying
status path (--short / -s / --porcelain) dropped the final newline.
The last entry then glues to whatever prints next, and — worse than
cosmetic — any pipeline that counts lines undercounts by one:
git status --porcelain | cat -A -> ?? handoff/$ (1 line)
rtk git status --porcelain | cat -A -> ?? handoff/ (0 lines)
On a tree with a single change, `rtk git status --porcelain | wc -l`
therefore reports 0 — a false 'clean' on the exact question the command
is usually asked. Anything gating a commit/no-commit decision on piped
porcelain output takes the wrong branch.
Normalize to exactly one trailing newline via a pure, unit-tested
`with_trailing_newline`. Empty output stays empty: --porcelain on a
clean tree correctly prints nothing.
strickdd
marked this pull request as ready for review
August 23, 2026 20:39
kylehgc
added a commit
to kylehgc/rtk
that referenced
this pull request
Sep 7, 2026
…aches Amendment to the adopted upstream rtk-ai#3682 commit, kept separate to preserve its authorship. On this fork `--porcelain` and `-z` are machine-output passthrough (`status_args_request_machine_output`) and never reach `with_trailing_newline`; the forms that undercounted were `-s`, `--short` and the path-operand forms. The doc comment and the test comments said `--porcelain`, so a later bisect running that repro on develop would have found it already correct and read the fix as a no-op. Also: `str::lines()` ignores a trailing newline, so the line-count assertion passed without the fix -- count `\n` like `wc -l` does; and pin the composed clean-tree case (`filter_status_with_args("")` is `"ok"`, only `never_worse` returns git's empty stdout) so a clean `git status -s` never prints `ok`. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
kylehgc
added a commit
to kylehgc/rtk
that referenced
this pull request
Sep 7, 2026
fix(git): keep the trailing newline on filtered 'git status' output (adopt upstream rtk-ai#3682)
Contributor
|
One case this changes that it probably shouldn't:
Leaving NUL-terminated output alone fixes it: if output.is_empty() || output.ends_with('\n') || output.ends_with('\0') { |
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 statusdrops the trailing newline on the arg-carrying path (--short/-s/--porcelain), so the last entry glues to whatever prints next.rtk git status --porcelain | wc -lreports0— a false "clean" — on a tree with exactly one change. Anything gating a commit/no-commit decision on piped porcelain output takes the wrong branch.--porcelainon a clean tree still correctly prints nothing.Root cause
In
run_status, the non-compact path ends with:filter_status_with_argsjoins its kept lines with\nand so has no terminal newline, whilenever_worsemay instead hand back git's raw stdout, which does.print!is therefore wrong in exactly one of the two cases. This is also why barestatus,diff --stat,logandbranchare unaffected — they end inprintln!.with_trailing_newlinehandles both inputs, which is why the fix is a helper rather than swappingprint!forprintln!(that would double the newline whenevernever_worsefalls back to raw).Reproduction
Test plan
cargo fmt --all -- --check— cleancargo clippy --all-targets— cleancargo test— 2708 passed, 8 ignored (9 suites)--releaseand compared against/usr/bin/gitby md5 and line count for--short/-s/--porcelain/--porcelain=v1across clean, single-untracked, 10-modified, staged, deleted, untracked-directory and 252-entry trees, plus inside a linked worktree. Byte-identical in every case.--longand barestatusstill take the compact path and are unchanged — this PR does not touch rtk's intended compaction, only restores fidelity where rtk already passes git's own output through.Scope
One function plus its tests, in
src/cmds/git/git.rs. No behavior change to any other command, and no change to how much rtk compacts.