Skip to content

fix(git): accept native git flags in add command (including -A) - #59

Merged
pszymkowiak merged 1 commit into
rtk-ai:masterfrom
FlorianBruniaux:fix/git-add-native-flags
Feb 5, 2026
Merged

pszymkowiak merged 1 commit into
rtk-ai:masterfrom
FlorianBruniaux:fix/git-add-native-flags

Conversation

@FlorianBruniaux

Copy link
Copy Markdown
Contributor

Problem

  • rtk git add -A failed with "unexpected argument '-A' found"
  • Git flags like -A, -p, --all were rejected by Clap parser
  • Only filenames could be passed to git add

Solution

  • Add allow_hyphen_values = true to Add command args (following PR fix: pass git flags transparently to git command #5 pattern)
  • Change Add enum variant from Add { files } to Add (unified with other git commands)
  • Modify run_add() to accept args slice and pass all arguments to git
  • Add exit code propagation for consistency with other git commands

Impact

  • ✅ All native git add flags now work: -A, -p, --all, --update, etc.
  • ✅ Maintains RTK compact output format ("ok ✓ 2 files changed, ...")
  • ✅ Preserves backward compatibility (no args defaults to ".")

Testing

  • Manual: rtk git add -A works correctly
  • All existing tests pass (154 passed)
  • Smoke tests unchanged (git add not included in test-all.sh)

Files Changed

  • src/main.rs: Updated Add command to accept hyphen values
  • src/git.rs: Simplified Add enum and updated run_add() to handle all args

🤖 Generated with Claude Code

Copilot AI review requested due to automatic review settings February 4, 2026 18:08

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

Enables rtk git add to pass through native git add flags (e.g., -A, --all) by relaxing Clap parsing and routing all remaining args directly to git add.

Changes:

  • Update GitCommands::Add to capture trailing args and accept hyphen-prefixed values.
  • Simplify GitCommand::Add to a unit variant and pass args via git::run(...).
  • Update run_add() to forward all args to git add and propagate non-zero exit codes.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
src/main.rs Adjusts Clap parsing for git add to accept hyphenated flags as positional args.
src/git.rs Refactors Add command plumbing and forwards args directly to git add, with exit code propagation on failure.
Comments suppressed due to low confidence (1)

src/git.rs:480

  • git add can be interactive (e.g. -p/--patch, -i/--interactive). Using Command::output() does not attach a TTY and will typically fail or hang for these modes. To actually support those flags, run git add with inherited stdio (e.g. stdin/stdout/stderr inherit + status()/spawn().wait()), then compute the staged stat afterward if desired.
            cmd.arg(arg);
        }
    }

    let output = cmd.output().context("Failed to run git add")?;

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/main.rs
Comment on lines +436 to +438
/// Files and flags to add (supports all git add flags like -A, -p, --all, etc)
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
args: Vec<String>,

Copilot AI Feb 4, 2026

Copy link

Choose a reason for hiding this comment

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

This help text claims “supports all git add flags like -A, -p, --all…”, but (1) -p/--patch is interactive and currently won’t work with the Command::output() implementation, and (2) some short flags collide with RTK global flags (e.g. -u is taken by ultra_compact, -v by verbosity). Consider rewording to avoid “all flags” (or document the collisions and recommend long forms like --update).

Copilot uses AI. Check for mistakes.
Problem:
- `rtk git add -A` failed with "unexpected argument '-A' found"
- Git flags like -A, -p, --all were rejected by Clap parser
- Only filenames could be passed to `git add`

Solution:
- Add `allow_hyphen_values = true` to Add command args (following PR rtk-ai#5 pattern)
- Change Add enum variant from `Add { files }` to `Add` (unified with other git commands)
- Modify run_add() to accept args slice and pass all arguments to git
- Add exit code propagation for consistency with other git commands

Impact:
- All native git add flags now work: -A, -p, --all, --update, etc.
- Maintains RTK compact output format ("ok ✓ 2 files changed, ...")
- Preserves backward compatibility (no args defaults to ".")

Testing:
- Manual: `rtk git add -A` works correctly
- All existing tests pass (154 passed)
- Smoke tests unchanged (git add not included in test-all.sh)

Fixes: Argument parsing error for git add with native flags

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
@FlorianBruniaux
FlorianBruniaux force-pushed the fix/git-add-native-flags branch from 3f6ae9e to 40e7ead Compare February 5, 2026 14:54
@pszymkowiak
pszymkowiak merged commit 2ade8fe into rtk-ai:master Feb 5, 2026
2 checks passed
ahundt pushed a commit to ahundt/rtk that referenced this pull request Feb 23, 2026
…flags

fix(git): accept native git flags in add command (including -A)
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