Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

ZhongRuoyu
Copy link
Contributor

@ZhongRuoyu ZhongRuoyu commented Oct 21, 2025

cc: Ben Knoble [email protected]

@gitgitgadget-git
Copy link

Welcome to GitGitGadget

Hi @ZhongRuoyu, and welcome to GitGitGadget, the GitHub App to send patch series to the Git mailing list from GitHub Pull Requests.

Please make sure that either:

  • Your Pull Request has a good description, if it consists of multiple commits, as it will be used as cover letter.
  • Your Pull Request description is empty, if it consists of a single commit, as the commit message should be descriptive enough by itself.

You can CC potential reviewers by adding a footer to the PR description with the following syntax:

CC: Revi Ewer <[email protected]>, Ill Takalook <[email protected]>

NOTE: DO NOT copy/paste your CC list from a previous GGG PR's description,
because it will result in a malformed CC list on the mailing list. See
example.

Also, it is a good idea to review the commit messages one last time, as the Git project expects them in a quite specific form:

  • the lines should not exceed 76 columns,
  • the first line should be like a header and typically start with a prefix like "tests:" or "revisions:" to state which subsystem the change is about, and
  • the commit messages' body should be describing the "why?" of the change.
  • Finally, the commit messages should end in a Signed-off-by: line matching the commits' author.

It is in general a good idea to await the automated test ("Checks") in this Pull Request before contributing the patches, e.g. to avoid trivial issues such as unportable code.

Contributing the patches

Before you can contribute the patches, your GitHub username needs to be added to the list of permitted users. Any already-permitted user can do that, by adding a comment to your PR of the form /allow. A good way to find other contributors is to locate recent pull requests where someone has been /allowed:

Both the person who commented /allow and the PR author are able to /allow you.

An alternative is the channel #git-devel on the Libera Chat IRC network:

<newcontributor> I've just created my first PR, could someone please /allow me? https://github.com/gitgitgadget/git/pull/12345
<veteran> newcontributor: it is done
<newcontributor> thanks!

Once on the list of permitted usernames, you can contribute the patches to the Git mailing list by adding a PR comment /submit.

If you want to see what email(s) would be sent for a /submit request, add a PR comment /preview to have the email(s) sent to you. You must have a public GitHub email address for this. Note that any reviewers CC'd via the list in the PR description will not actually be sent emails.

After you submit, GitGitGadget will respond with another comment that contains the link to the cover letter mail in the Git mailing list archive. Please make sure to monitor the discussion in that thread and to address comments and suggestions (while the comments and suggestions will be mirrored into the PR by GitGitGadget, you will still want to reply via mail).

If you do not want to subscribe to the Git mailing list just to be able to respond to a mail, you can download the mbox from the Git mailing list archive (click the (raw) link), then import it into your mail program. If you use GMail, you can do this via:

curl -g --user "<EMailAddress>:<Password>" \
    --url "imaps://imap.gmail.com/INBOX" -T /path/to/raw.txt

To iterate on your change, i.e. send a revised patch or patch series, you will first want to (force-)push to the same branch. You probably also want to modify your Pull Request description (or title). It is a good idea to summarize the revision by adding something like this to the cover letter (read: by editing the first comment on the PR, i.e. the PR description):

Changes since v1:
- Fixed a typo in the commit message (found by ...)
- Added a code comment to ... as suggested by ...
...

To send a new iteration, just add another PR comment with the contents: /submit.

Need help?

New contributors who want advice are encouraged to join [email protected], where volunteers who regularly contribute to Git are willing to answer newbie questions, give advice, or otherwise provide mentoring to interested contributors. You must join in order to post or view messages, but anyone can join.

You may also be able to find help in real time in the developer IRC channel, #git-devel on Libera Chat. Remember that IRC does not support offline messaging, so if you send someone a private message and log out, they cannot respond to you. The scrollback of #git-devel is archived, though.

As documented in git-bisect(1), `git bisect help` should display usage
information. However, since the migration of `git bisect` to a full
builtin command in 73fce29 (Turn `git bisect` into a full built-in,
2022-11-10), this behavior was broken. Running `git bisect help` would,
instead of showing usage, either fail silently if already in a bisect
session, or otherwise trigger an interactive autostart prompt asking "Do
you want me to do it for you [Y/n]?".

Similarly, since df63421 (bisect--helper: handle states directly,
2022-11-10), running invalid subcommands like `git bisect foobar` also
led to the same behavior.

This occurred because `help` and other unrecognized subcommands were
being unconditionally passed to `bisect_state`, which then called
`bisect_autostart`, triggering the interactive prompt.

Fix this by:
1. Adding explicit handling for the `help` subcommand to show usage;
2. Validating that unrecognized commands are actually valid state
   commands before calling `bisect_state`;
3. Showing an error with usage for truly invalid commands.

This ensures that `git bisect help` displays the usage as documented,
and invalid commands fail cleanly without entering interactive mode.
Alternate terms are still handled correctly through
`check_and_set_terms`.

Signed-off-by: Ruoyu Zhong <[email protected]>
@ZhongRuoyu ZhongRuoyu force-pushed the git-bisect-subcommands branch from c2b2d22 to 04a7d21 Compare October 22, 2025 06:58
@dscho
Copy link
Member

dscho commented Oct 22, 2025

/allow

@gitgitgadget-git
Copy link

User ZhongRuoyu is now allowed to use GitGitGadget.

@ZhongRuoyu
Copy link
Contributor Author

/preview

@gitgitgadget-git
Copy link

Preview email sent as [email protected]

@ZhongRuoyu
Copy link
Contributor Author

/submit

@gitgitgadget-git
Copy link

Submitted as [email protected]

To fetch this version into FETCH_HEAD:

git fetch https://github.com/gitgitgadget/git/ pr-git-2078/ZhongRuoyu/git-bisect-subcommands-v1

To fetch this version to local tag pr-git-2078/ZhongRuoyu/git-bisect-subcommands-v1:

git fetch --no-tags https://github.com/gitgitgadget/git/ tag pr-git-2078/ZhongRuoyu/git-bisect-subcommands-v1

@gitgitgadget-git
Copy link

On the Git mailing list, Ben Knoble wrote (reply to this):

> Le 22 oct. 2025 à 04:37, Ruoyu Zhong via GitGitGadget <[email protected]> a écrit :
> 
> From: Ruoyu Zhong <[email protected]>
> 
> As documented in git-bisect(1), `git bisect help` should display usage
> information. However, since the migration of `git bisect` to a full
> builtin command in 73fce29427 (Turn `git bisect` into a full built-in,
> 2022-11-10), this behavior was broken. Running `git bisect help` would,
> instead of showing usage, either fail silently if already in a bisect
> session, or otherwise trigger an interactive autostart prompt asking "Do
> you want me to do it for you [Y/n]?".

Good catch!

FWIW, in this project we describe the buggy behavior in the present tense (« is broken », « Running git bisect shows », etc.)

> 
> Similarly, since df63421be9 (bisect--helper: handle states directly,
> 2022-11-10), running invalid subcommands like `git bisect foobar` also
> led to the same behavior.
> 
> This occurred because `help` and other unrecognized subcommands were
> being unconditionally passed to `bisect_state`, which then called
> `bisect_autostart`, triggering the interactive prompt.
> 
> Fix this by:
> 1. Adding explicit handling for the `help` subcommand to show usage;
> 2. Validating that unrecognized commands are actually valid state
>   commands before calling `bisect_state`;
> 3. Showing an error with usage for truly invalid commands.
> 
> This ensures that `git bisect help` displays the usage as documented,
> and invalid commands fail cleanly without entering interactive mode.
> Alternate terms are still handled correctly through
> `check_and_set_terms`.
> 
> Signed-off-by: Ruoyu Zhong <[email protected]>
> ---
>    bisect: fix handling of help and invalid subcommands
> 
> Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-git-2078%2FZhongRuoyu%2Fgit-bisect-subcommands-v1
> Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-git-2078/ZhongRuoyu/git-bisect-subcommands-v1
> Pull-Request: https://github.com/git/git/pull/2078
> 
> builtin/bisect.c | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/builtin/bisect.c b/builtin/bisect.c
> index 8b8d870cd1..993caf545d 100644
> --- a/builtin/bisect.c
> +++ b/builtin/bisect.c
> @@ -1453,9 +1453,13 @@ int cmd_bisect(int argc,
>        if (!argc)
>            usage_msg_opt(_("need a command"), git_bisect_usage, options);
> 
> +        if (!strcmp(argv[0], "help"))
> +            usage_with_options(git_bisect_usage, options);
> +

From an extremely quick look at the code, this might be better handled with a new OPT_SUBCOMMAND, though that might mean making the options array statically scoped to this file rather than the function.

It would also be nice to update the usage to match the manual while we’re here, which presumably in turn affects the test between command usage and manuals.

>        set_terms(&terms, "bad", "good");
>        get_terms(&terms);
> -        if (check_and_set_terms(&terms, argv[0]))
> +        if (check_and_set_terms(&terms, argv[0]) ||
> +            !one_of(argv[0], terms.term_good, terms.term_bad, NULL))
>            usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
>                       options, argv[0]);
>        res = bisect_state(&terms, argc, argv);
> 
> base-commit: 81f86aacc4eb74cdb9c2c8082d36d2070c666045
> --
> gitgitgadget

I think this part is OK, since we only intend to check this when using the « git bisect <term> » form. 

@gitgitgadget-git
Copy link

User Ben Knoble <[email protected]> has been added to the cc: list.

@gitgitgadget-git
Copy link

On the Git mailing list, Junio C Hamano wrote (reply to this):

"Ruoyu Zhong via GitGitGadget" <[email protected]> writes:

> From: Ruoyu Zhong <[email protected]>
>
> As documented in git-bisect(1), `git bisect help` should display usage
> information. However, since the migration of `git bisect` to a full
> builtin command in 73fce29427 (Turn `git bisect` into a full built-in,
> 2022-11-10), this behavior was broken. Running `git bisect help` would,
> instead of showing usage, either fail silently if already in a bisect
> session, or otherwise trigger an interactive autostart prompt asking "Do
> you want me to do it for you [Y/n]?".
>
> Similarly, since df63421be9 (bisect--helper: handle states directly,
> 2022-11-10), running invalid subcommands like `git bisect foobar` also
> led to the same behavior.
>
> This occurred because `help` and other unrecognized subcommands were
> being unconditionally passed to `bisect_state`, which then called
> `bisect_autostart`, triggering the interactive prompt.

Very good observations.

> diff --git a/builtin/bisect.c b/builtin/bisect.c
> index 8b8d870cd1..993caf545d 100644
> --- a/builtin/bisect.c
> +++ b/builtin/bisect.c
> @@ -1453,9 +1453,13 @@ int cmd_bisect(int argc,
>  		if (!argc)
>  			usage_msg_opt(_("need a command"), git_bisect_usage, options);
>  
> +		if (!strcmp(argv[0], "help"))
> +			usage_with_options(git_bisect_usage, options);

I briefly wondered why

    $ git grep 'strcmp.*"help"'

gives a single hit in parse-options.c but that is simply because
"git bisect" is an oddball.  Everybody, including "git bisect"
itself, takes "git <cmd> --help", but in addition, "git bisect" also
takes "git bisect help".  So this addition is unfortunate but cannot
be helped (no pun intended).  In an ideal world, as we support the
bog standard "--help", if we could remove "help" as a subcommand,
then the other part of this patch would take care of "bisect help"
without this part by saying "unknown command" ;-) but we cannot
retroactively do so now.

I also wonder if it would be cleaner to add "help" as a genuine
subcommand to the options[] table just like all the other
subcommands.  The above would not be needed if we did so.  But I do
not see huge upside for doing so (i.e., a single strcmp() with a
call like we see above, vs. a new helper function to make the same
call, to usage_with_options()), so what is written in this patch is
perfectly fine.

>  		set_terms(&terms, "bad", "good");
>  		get_terms(&terms);
> -		if (check_and_set_terms(&terms, argv[0]))
> +		if (check_and_set_terms(&terms, argv[0]) ||
> +		    !one_of(argv[0], terms.term_good, terms.term_bad, NULL))
>  			usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
>  				       options, argv[0]);

This change is a bit hard to reason about, so let me think aloud.

If we were saying "git bisect olde" after somehow changing bad/good
to newe/olde, then we do not want to say "unknown command", and the
way it avoids that is to see if the given command is one of the
terms check_and_set_terms() have updated.  

In other words, if argv[0] caused check_and_set_terms() to return
non-zero, we do not have to do "unknown command", because the helper
would have issued a warning already.  When it returns 0, it may be
because it saw a valid command "skip", etc. that cannot be a custom
good/bad/new/old (in which case our one_of() would be false and we
end up saying "unknown command"---have I just spot a bug???), or we
haven't set custom terms and argv[0] is one of bad/good/new/old (in
which case our one_of() would be true and we avoid saying "unknown
command").

And it turns out that my finding about the 'skip' etc. is not a bug,
as these valid commands that cannot be good/bad/new/old aliases are
already caught by parse_options() call and we know argv[0] is not
such a valid subcommand.

So after all this looks good.

Thanks.  Will queue.

@gitgitgadget-git
Copy link

On the Git mailing list, Ruoyu Zhong wrote (reply to this):

Hi Ben,


Thanks for the review!

> On Oct 23, 2025, at 1:52 AM, Ben Knoble <[email protected]> wrote:
> 
> Good catch!
> 
> FWIW, in this project we describe the buggy behavior in the present tense (« is broken », « Running git bisect shows », etc.)

Thanks! Will keep this in mind.

>> diff --git a/builtin/bisect.c b/builtin/bisect.c
>> index 8b8d870cd1..993caf545d 100644
>> --- a/builtin/bisect.c
>> +++ b/builtin/bisect.c
>> @@ -1453,9 +1453,13 @@ int cmd_bisect(int argc,
>>       if (!argc)
>>           usage_msg_opt(_("need a command"), git_bisect_usage, options);
>> 
>> +        if (!strcmp(argv[0], "help"))
>> +            usage_with_options(git_bisect_usage, options);
>> +
> 
> From an extremely quick look at the code, this might be better handled with a new OPT_SUBCOMMAND, though that might mean making the options array statically scoped to this file rather than the function.

I intended to keep it simple so I did not make it an OPT_SUBCOMMAND at the first
place. Given that Junio is okay with it, I'm going to keep it as is for now.
Still happy to turn this into an OPT_SUBCOMMAND if you would like.

> It would also be nice to update the usage to match the manual while we’re here, which presumably in turn affects the test between command usage and manuals.


Thanks for pointing that out! Yes, I think so too. Will do in a separate patch,
if you agree, in order not to digress too much.


Regards,
Ruoyu

@gitgitgadget-git
Copy link

On the Git mailing list, Ruoyu Zhong wrote (reply to this):

Hi Junio,


I appreciate your detailed and thoughtful analysis and I resonate with your
points. Specifically:

> I also wonder if it would be cleaner to add "help" as a genuine
> subcommand to the options[] table just like all the other
> subcommands.  The above would not be needed if we did so.  But I do
> not see huge upside for doing so (i.e., a single strcmp() with a
> call like we see above, vs. a new helper function to make the same
> call, to usage_with_options()), so what is written in this patch is
> perfectly fine.

Agreed. Will keep this as is, as I also mentioned in my response to Ben.

>> set_terms(&terms, "bad", "good");
>> get_terms(&terms);
>> - if (check_and_set_terms(&terms, argv[0]))
>> + if (check_and_set_terms(&terms, argv[0]) ||
>> +    !one_of(argv[0], terms.term_good, terms.term_bad, NULL))
>> usage_msg_optf(_("unknown command: '%s'"), git_bisect_usage,
>>       options, argv[0]);
> 
> This change is a bit hard to reason about, so let me think aloud.
> 
> If we were saying "git bisect olde" after somehow changing bad/good
> to newe/olde, then we do not want to say "unknown command", and the
> way it avoids that is to see if the given command is one of the
> terms check_and_set_terms() have updated.  
> 
> In other words, if argv[0] caused check_and_set_terms() to return
> non-zero, we do not have to do "unknown command", because the helper
> would have issued a warning already.  When it returns 0, it may be
> because it saw a valid command "skip", etc. that cannot be a custom
> good/bad/new/old (in which case our one_of() would be false and we
> end up saying "unknown command"---have I just spot a bug???), or we
> haven't set custom terms and argv[0] is one of bad/good/new/old (in
> which case our one_of() would be true and we avoid saying "unknown
> command").
> 
> And it turns out that my finding about the 'skip' etc. is not a bug,
> as these valid commands that cannot be good/bad/new/old aliases are
> already caught by parse_options() call and we know argv[0] is not
> such a valid subcommand.
> 
> So after all this looks good.

Thank you for walking through this. This is very helpful and also matches my own
thought process when I first looked at it. The key is that this part of the code
is only reached if fn is still NULL after parse_options, i.e., argv[0] is not
one of the known subcommands.


Regards,
Ruoyu

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants