Skip to content

but: removed num_args from --changes#12223

Merged
krlvi merged 2 commits intogitbutlerapp:masterfrom
rsteube:buthurt
Feb 8, 2026
Merged

but: removed num_args from --changes#12223
krlvi merged 2 commits intogitbutlerapp:masterfrom
rsteube:buthurt

Conversation

@rsteube
Copy link
Contributor

@rsteube rsteube commented Feb 4, 2026

🧢 Changes

Removed num_args.

☕️ Reasoning

This consumes multiple args until another flag is encountered. Thus mininterprets a following positional argument (branch) as change unless separated with dash --.

see https://docs.rs/clap/latest/clap/struct.Arg.html#method.num_args

esh ❯ but
GitButler uses metrics to help us know what is useful and improve it. Configure with `but config metrics`.
Initiated a background sync...
╭┄zz [unstaged changes]
┊   g0 A fileA
┊   h0 A fileB
┊
┊╭┄br [branch] (no commits)
├╯
┊
┴ 791af90 (common base) [gb-local/master] 2026-02-04 Initial empty commit (checked 4 minutes ago)

Hint: run `but diff` to see uncommitted changes and `but stage <file>` to stage them to a branch
esh ❯ but commit --changes fileA branch 
Initiated a background sync...
Error: Invalid file ID(s):
  'branch' is a branch but must be an uncommitted file or hunk
Exception: but exited with 1
  [tty 35]:1:1-34: but commit --changes fileA branch

@vercel
Copy link

vercel bot commented Feb 4, 2026

@rsteube is attempting to deploy a commit to the GitButler Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions bot added the rust Pull requests that update Rust code label Feb 4, 2026
@krlvi
Copy link
Member

krlvi commented Feb 5, 2026

hey @rsteube the idea for this was to be able to do but commit --changes c1 c2 c3 - thus it always has to be the last arg (though it also supports --changes="c1,c2,c3"
Do you think another approach can be taken here?

@rsteube
Copy link
Contributor Author

rsteube commented Feb 5, 2026

@krlvi
Using comma separated values or repeating the flag is the most common approach.

but commit --changes fileA,fileB
but commit --changes fileA --changes fileB

I think num_args (flag consuming multiple arguments) is generally not a good idea due to the aformentioned problems.
It's also rarely seen in commands (nix, some based on pythons argparse).

Some ideas below.
I think I'd keep the --changes flag (comma seperated) and additionally use dash args for changes(4).

Use positional arguments for changes/target:

# but commit [change]... target
but commit branch
but commit fileA branch
but commit fileA fileB branch

In the completions both changes and branches would appear for each position though.

Invert the usage of flags:

# but commit [-t target] [change]...
but commit -t branch
but commit -t branch fileA
but commit -t branch fileA fileB

Use a bool flag to modify the behaviour of parsing positional arguments (as in 1).
Git does this overloading quite a bit and its rarely a good idea.

Explicitly use dash args for files.

# but commit [target] [-- change...]
but commit branch
but commit branch -- fileA
but commit branch -- fileA fileB
but commit -- fileA fileB

This consumes multiple args until another flag is encountered.
Thus mininterprets a following positional argument (branch) as change unless separated with dash `--`.

see https://docs.rs/clap/latest/clap/struct.Arg.html#method.num_args
@github-actions github-actions bot added the CLI The command-line program `but` label Feb 6, 2026
Copy link
Member

@krlvi krlvi left a comment

Choose a reason for hiding this comment

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

Okay now i understand the considerations. Thank you for this contribution

@krlvi krlvi enabled auto-merge February 8, 2026 11:59
@krlvi krlvi merged commit e037bb4 into gitbutlerapp:master Feb 8, 2026
23 of 24 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLI The command-line program `but` rust Pull requests that update Rust code

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants