Skip to content

fix: allow git status to accept native flags - #49

Merged
pszymkowiak merged 1 commit into
rtk-ai:masterfrom
FlorianBruniaux:fix/git-status-accept-flags
Feb 2, 2026
Merged

pszymkowiak merged 1 commit into
rtk-ai:masterfrom
FlorianBruniaux:fix/git-status-accept-flags

Conversation

@FlorianBruniaux

Copy link
Copy Markdown
Contributor

Summary

  • Fix rtk git status to accept native git flags (--short, -s, --porcelain, etc.)
  • Align behavior with other git subcommands (diff, log, show) that already support flag forwarding
  • Extract format_status_output() as pure testable function
  • Implement passthrough mode: user flags → raw git output, no flags → RTK compact formatting
  • Add comprehensive test coverage (5 unit tests + 4 smoke tests)

Context

rtk git status was the only git subcommand rejecting all arguments due to missing args field in Clap variant. This caused rtk git status --short to fail with "unexpected argument" error.

Changes

Core Implementation:

  • src/git.rs: Extract format_status_output() for testability, modify run_status() to accept args
  • src/main.rs: Add args: Vec<String> to Status variant with trailing_var_arg + allow_hyphen_values
  • scripts/test-all.sh: Add smoke tests for flag passthrough

Formatting:

  • Auto-formatted by 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

  • Unit tests: 151 passed (5 new for format_status_output)
  • Smoke tests: 69 passed (4 new for status flags)
  • Manual verification:
    • rtk git status → RTK compact format
    • rtk git status --short → git raw output
    • rtk git status -s → git raw output
    • rtk git status --porcelain → git raw output
  • Quality checks: cargo fmt && cargo clippy && cargo test

Related

Follows pattern established in PR #5 (git argument parsing fix) for other git subcommands.

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings February 2, 2026 15:44
@pszymkowiak
pszymkowiak merged commit a7ea143 into rtk-ai:master Feb 2, 2026
6 checks passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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::Status to accept arbitrary git status arguments and wire them through git::run, enabling passthrough behavior when any args are present.
  • Extract and test format_status_output() for compact status formatting, and update run_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.

Comment thread src/git.rs
Comment on lines +417 to +421
let output = Command::new("git")
.arg("status")
.args(args)
.output()
.context("Failed to run git status")?;

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment thread src/git.rs
"Clean working tree",
);
return Ok(());
return "Clean working tree".to_string();

Copilot AI Feb 2, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
return "Clean working tree".to_string();
return "Unable to determine git status (no porcelain output)".to_string();

Copilot uses AI. Check for mistakes.
@FlorianBruniaux
FlorianBruniaux deleted the fix/git-status-accept-flags branch February 2, 2026 15:50
ahundt pushed a commit to ahundt/rtk that referenced this pull request Feb 23, 2026
…pt-flags

fix: allow git status to accept native flags
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.

3 participants