All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Ruoyu Zhong via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Ruoyu Zhong <zhongruoyu@outlook.com>,
	Ruoyu Zhong <zhongruoyu@outlook.com>
Subject: [PATCH] bisect: fix handling of `help` and invalid subcommands
Date: Wed, 22 Oct 2025 08:36:13 +0000	[thread overview]
Message-ID: <pull.2078.git.git.1761122173126.gitgitgadget@gmail.com> (raw)

From: Ruoyu Zhong <zhongruoyu@outlook.com>

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>
---
    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);
+
 		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

             reply	other threads:[~2025-10-22  8:36 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-22  8:36 Ruoyu Zhong via GitGitGadget [this message]
2025-10-22 17:52 ` [PATCH] bisect: fix handling of `help` and invalid subcommands Ben Knoble
2025-10-22 20:15   ` Ruoyu Zhong
2025-10-23 15:14     ` Ben Knoble
2025-10-22 18:24 ` Junio C Hamano
2025-10-22 20:20   ` Ruoyu Zhong

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=pull.2078.git.git.1761122173126.gitgitgadget@gmail.com \
    --to=gitgitgadget@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=zhongruoyu@outlook.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.