diff options
| author | Ruoyu Zhong <zhongruoyu@outlook.com> | 2025-10-22 08:36:13 +0000 |
|---|---|---|
| committer | Junio C Hamano <gitster@pobox.com> | 2025-10-22 11:25:23 -0700 |
| commit | 2bb3a012f3d756ad7101c359f38285a018f9e517 (patch) | |
| tree | 915520877b606535aaf7fb21dedb6b8590f8fdf2 /builtin/bisect.c | |
| parent | Git 2.50 (diff) | |
| download | git-2bb3a012f3d756ad7101c359f38285a018f9e517.tar.gz git-2bb3a012f3d756ad7101c359f38285a018f9e517.zip | |
bisect: fix handling of `help` and invalid subcommands
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.
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 <zhongruoyu@outlook.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to '')
| -rw-r--r-- | builtin/bisect.c | 6 |
1 files changed, 5 insertions, 1 deletions
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); + 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); |
