fix: allow git status to accept native flags - #49
Conversation
Previously, `rtk git status` was the only git subcommand that rejected all arguments. This fix aligns it with other git subcommands (diff, log, show, etc.) by accepting native git flags. Changes: - Extract format_status_output() as pure testable function - Add args variant to Clap Status command with trailing_var_arg - Modify run_status() to accept args parameter - Passthrough mode: if user provides flags (--short, -s, --porcelain), forward directly to git without RTK formatting - Default mode: no flags = RTK compact formatting (unchanged behavior) - Add 5 unit tests for format_status_output (clean, modified, untracked, mixed, truncation) - Add 4 smoke tests for flag passthrough (--short, -s, --porcelain) Test results: - 151 unit tests passed (5 new) - 69 smoke tests passed (4 new for status flags) Fixes the issue where commands like `rtk git status --short` were rejected with "unexpected argument" error. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR updates rtk git status to accept and forward native git flags, introduces a pure format_status_output() helper for compaction logic, and adds tests and minor formatting cleanups across parser-related modules.
Changes:
- Extend
GitCommands::Statusto accept arbitrary git status arguments and wire them throughgit::run, enabling passthrough behavior when any args are present. - Extract and test
format_status_output()for compact status formatting, and updaterun_status()to support both passthrough and RTK-compact modes with tracking. - Apply rustfmt-driven style cleanups in parser and command modules and add smoke tests for status flag passthrough in
scripts/test-all.sh.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/vitest_cmd.rs |
Minor import and match-arm formatting cleanup around ParseResult::Degraded handling; no behavioral changes. |
src/tracking.rs |
Formatting of the SQL prepare call for readability; query string unchanged. |
src/pnpm_cmd.rs |
Style-only reformatting of degraded parse branches in pnpm list/outdated parsers. |
src/playwright_cmd.rs |
Style-only reformatting of degraded parse branch in the Playwright parser. |
src/parser/types.rs |
Trivial whitespace tweak above the serde imports. |
src/parser/mod.rs |
Reformat truncate_output into a multi-line format! call; behavior preserved. |
src/parser/formatter.rs |
Reformat several format! calls and method chains for clarity without changing logic. |
src/main.rs |
Extend GitCommands::Status to accept args: Vec<String> with trailing_var_arg/allow_hyphen_values, and pass these args through to git::run for status. |
src/lint_cmd.rs |
Remove an extra blank line; no functional impact. |
src/git.rs |
Change run_status to accept args, add passthrough mode for any provided args, factor compact formatting into format_status_output(), and add unit tests for the formatter; however, error/exit-status handling for git status remains inconsistent and misleading in some error cases. |
scripts/test-all.sh |
Add smoke tests verifying rtk git status with --short, -s, and --porcelain now execute successfully. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| let output = Command::new("git") | ||
| .arg("status") | ||
| .args(args) | ||
| .output() | ||
| .context("Failed to run git status")?; |
There was a problem hiding this comment.
In the passthrough branch, the exit status of git status is ignored: this function returns Ok(()) and the process exits with status 0 even if git status itself failed (e.g. outside a git repo), whereas other helpers like run_diff and run_show propagate non-zero git exit codes. To keep behavior consistent with raw git and the other RTK git subcommands, consider checking output.status.success() here (and in the porcelain branch below) and exiting with git's status code on failure instead of silently treating errors as success.
| "Clean working tree", | ||
| ); | ||
| return Ok(()); | ||
| return "Clean working tree".to_string(); |
There was a problem hiding this comment.
format_status_output treats an empty porcelain string as a "Clean working tree" state, but git status --porcelain -b in a real repository always outputs at least a branch line, so an empty string is much more likely to indicate that git status failed (e.g. not a git repo) or that stdout was otherwise unavailable. This can cause RTK to report a clean working tree even when git status has actually errored. It would be safer to treat an empty porcelain payload as an error case (or have the caller check the subprocess exit status / stderr) instead of assuming cleanliness.
| return "Clean working tree".to_string(); | |
| return "Unable to determine git status (no porcelain output)".to_string(); |
…pt-flags fix: allow git status to accept native flags
Summary
rtk git statusto accept native git flags (--short, -s, --porcelain, etc.)format_status_output()as pure testable functionContext
rtk git statuswas the only git subcommand rejecting all arguments due to missingargsfield in Clap variant. This causedrtk git status --shortto fail with "unexpected argument" error.Changes
Core Implementation:
src/git.rs: Extractformat_status_output()for testability, modifyrun_status()to accept argssrc/main.rs: Addargs: Vec<String>toStatusvariant withtrailing_var_arg + allow_hyphen_valuesscripts/test-all.sh: Add smoke tests for flag passthroughFormatting:
cargo fmt(parser/*, *_cmd.rs files)Behavior
Without flags (default RTK compact):
```bash
$ rtk git status
📌 master...origin/master
📝 Modified: 3 files
src/main.rs
src/git.rs
...
```
With flags (passthrough to git):
```bash
$ rtk git status --short
M src/main.rs
M src/git.rs
$ rtk git status -s
M src/main.rs
M src/git.rs
```
Test plan
format_status_output)rtk git status→ RTK compact formatrtk git status --short→ git raw outputrtk git status -s→ git raw outputrtk git status --porcelain→ git raw outputcargo fmt && cargo clippy && cargo testRelated
Follows pattern established in PR #5 (git argument parsing fix) for other git subcommands.
🤖 Generated with Claude Code