Skip to content

fix(git): keep git status --porcelain empty on a clean tree - #3498

Closed
asem89 wants to merge 1 commit into
rtk-ai:developfrom
asem89:fix/git-status-porcelain-passthrough
Closed

fix(git): keep git status --porcelain empty on a clean tree#3498
asem89 wants to merge 1 commit into
rtk-ai:developfrom
asem89:fix/git-status-porcelain-passthrough

Conversation

@asem89

@asem89 asem89 commented Aug 9, 2026

Copy link
Copy Markdown

Summary

  • rtk git status --porcelain prints ok on a clean tree instead of the zero bytes git emits.
  • For --porcelain, --porcelain=v1/v2, -z and --null, emptiness is the result — consumers parse "no output" as "no changes", so the ok compaction breaks them.
  • filter_status_with_args now takes the user's args and skips the substitution for those four machine-readable formats. Human-readable output, including short -s, is unchanged.

Why it bites

The standard clean-tree check inverts:

$ cd /tmp/clean-repo
$ git status --porcelain | wc -c
0
$ rtk git status --porcelain | wc -c
3          # "ok"

$ [ -z "$(rtk git status --porcelain)" ] && echo clean || echo dirty
dirty      # on a clean tree

--porcelain isn't routed through the compact path — uses_compact_status_path returns false for it — so it reaches filter_status_with_args and gets rewritten.

Test plan

  • cargo fmt --all --check && cargo clippy --all-targets -- -D warnings && cargo test --all — 2657 passed, 0 failed
  • Two regression tests added: test_filter_status_porcelain_clean_stays_empty (all four flags) and test_filter_status_short_still_collapses_to_ok (guards the compaction that should stay)
  • Manual, against a clean throwaway repo: rtk git status --porcelain → 0 bytes; rtk git status → still clean — nothing to commit

`filter_status_with_args` collapses empty filtered output to the literal
string `ok`. That is a good compaction for human-readable `git status`, but
`--porcelain`, `--porcelain=v1/v2`, `-z` and `--null` are machine-readable
formats where **zero bytes is the documented result**: consumers parse "no
output" as "no changes".

Today `rtk git status --porcelain` on a clean tree prints `ok`, so any script
doing `[ -z "$(git status --porcelain)" ]` — the standard clean-tree check —
sees a non-empty string and concludes the tree is dirty. `--porcelain` is not
routed through the compact path (`uses_compact_status_path` returns false for
it), so it lands here and gets rewritten.

Pass the user's args down and skip the `ok` substitution for those four
formats, echoing stdout unchanged instead. Human-readable forms, including the
short `-s` flag, are unaffected.
@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@asem89

asem89 commented Aug 9, 2026

Copy link
Copy Markdown
Author

Closing — I'm not in a position to sign the CLA, so this can't be merged as-is. Leaving the analysis here in case a maintainer wants to reimplement it; both are small and self-contained, and the reproduction steps in the description stand on their own. No response needed.

@asem89 asem89 closed this Aug 9, 2026
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.

2 participants