Re: [PATCH] help.c: help.autocorrect=prompt waits for user action
- From
Azeem Bande-Ali <me@azeemba.com>
- Date
- Aug 14, 2021, 03:07 UTC
- Message-ID
- <CABye9140=jnkERq8MLEcr_umW1+oaE5Wi39_iQnM3jevV3Hraw@mail.gmail.com>
- In-Reply-To
- <xmqqh7fu314a.fsf@gitster.g>
On Thu, Aug 12, 2021 at 3:38 PM Junio C Hamano <gitster@pobox.com> wrote:
Show 5 quoted lines
> > 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.
Thanks for the suggestion. I think it makes sense to skip the autocorrection completely when the setting is "prompt" and the user is not running interactively.
Show 12 quoted lines
> > + 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);
>I looked at the behavior for other settings and they all behave pretty compactly. So I think this suggested solution does fit better.
Show 7 quoted lines
> + /* > + * Disable autocorrection prompt in a non-interactive session > + */ > + if ((autocorrect != AUTOCORRECT_PROMPT) && > + (!isatty(0) || !isatty(2))) > + autocorrect = AUTOCORRECT_NEVER; > +
That should be `(autocorrect == AUTOCORRECT_PROMPT)` right? So we skip the autocorrect if the user is not running interactively and has the "prompt" setting.
Thanks for all the feedback! I will send out a patch incorporating this feedback soon.