From: Junio C Hamano <gitster@pobox.com>
To: "Azeem Bande-Ali via GitGitGadget" <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, David Barr <b@rr-dav.id.au>,
Azeem Bande-Ali <A.BandeAli@gmail.com>,
Azeem Bande-Ali <me@azeemba.com>
Subject: Re: [PATCH] help.c: help.autocorrect=prompt waits for user action
Date: Thu, 12 Aug 2021 12:37:57 -0700 [thread overview]
Message-ID: <xmqqh7fu314a.fsf@gitster.g> (raw)
In-Reply-To: <pull.1012.git.1628640954160.gitgitgadget@gmail.com> (Azeem Bande-Ali via GitGitGadget's message of "Wed, 11 Aug 2021 00:15:53 +0000")
> @@ -618,7 +622,18 @@ const char *help_unknown_cmd(const char *cmd)
> _("Continuing under the assumption that "
> "you meant '%s'."),
> assumed);
> - else {
> + else if (autocorrect == AUTOCORRECT_PROMPT) {
> + if (!isatty(STDIN_FILENO) | !isatty(STDERR_FILENO))
Don't do bitwise or when you only care about boolean outcome.
> + exit(1);
This is not a new issue, but I think it is probably a bug in the
original design of the help-unknown that we do not do this check
much early in help_unknown_cmd(), to disable auto-correction in
a non-interactive session. If we did so, we do not have to have
this check here.
If we cannot yet come to consensus that disabling autocorrection
when running non-interactively is a good idea, at least we should be
able to do so only for _PROMPT case, like the attached patch at the
end.
> + char *answer;
This is decl-after-statement, but as I am suggesting to get rid of
the tty check done inside this block, it will become OK.
> + fprintf_ln(stderr, _("Assuming you meant: '%s'."),
> + assumed);
> + answer = git_prompt(_("Continue? (y/N)"), PROMPT_ECHO);
Hmph, the above does not look WRONG per-se, but I wonder if it is
easier for the users to see a single line, e.g.
struct strbuf msg = STRBUF_INIT;
strbuf_addf(&msg, _("Run '%s' instead? (y/N)"), assumed);
answer = git_prompt(msg.buf, PROMPT_ECHO);
strbuf_release(&msg);
Thanks.
diff --git i/help.c w/help.c
index e22ba1d246..3629cb8796 100644
--- i/help.c
+++ w/help.c
@@ -540,6 +540,13 @@ const char *help_unknown_cmd(const char *cmd)
read_early_config(git_unknown_cmd_config, NULL);
+ /*
+ * Disable autocorrection prompt in a non-interactive session
+ */
+ if ((autocorrect != AUTOCORRECT_PROMPT) &&
+ (!isatty(0) || !isatty(2)))
+ autocorrect = AUTOCORRECT_NEVER;
+
if (autocorrect == AUTOCORRECT_NEVER) {
fprintf_ln(stderr, _("git: '%s' is not a git command. See 'git --help'."), cmd);
exit(1);
next prev parent reply other threads:[~2021-08-12 19:38 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-08-11 0:15 [PATCH] help.c: help.autocorrect=prompt waits for user action Azeem Bande-Ali via GitGitGadget
2021-08-12 10:52 ` Bagas Sanjaya
2021-08-14 2:57 ` Azeem Bande-Ali
2021-08-12 19:37 ` Junio C Hamano [this message]
2021-08-14 3:07 ` Azeem Bande-Ali
2021-08-14 5:11 ` [PATCH v2] " Azeem Bande-Ali via GitGitGadget
2021-08-14 5:50 ` Bagas Sanjaya
2021-08-14 18:20 ` Junio C Hamano
2021-08-14 18:40 ` Azeem Bande-Ali
2021-08-16 12:28 ` Johannes Schindelin
2021-08-15 1:50 ` [PATCH v3] " Azeem Bande-Ali via GitGitGadget
2021-09-08 0:18 ` Junio C Hamano
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=xmqqh7fu314a.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=A.BandeAli@gmail.com \
--cc=b@rr-dav.id.au \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=me@azeemba.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.