Subject: Re: [PATCH v6 8/8] update-ref: add --batch-updates flag for stdin mode

From: Junio C Hamano <[email-masked]>
Date: Tue, 08 Apr 2025 10:37:03 -0700

Karthik Nayak <[email-masked]> writes:

> Junio C Hamano <[email-masked]> writes:
>
>> Karthik Nayak <[email-masked]> writes:
>>
>>> Content-Type: text/plain; charset=y
>>
>> Please don't ;-).
>>
>> More practically, is there something we can do to avoid this
>> happening in send-email?  It may be a not-so-uncommon end user
>> mistake that we would rather help our users avoid.
>>
>
> This seems like this was in response to the following question:
>      Which 8bit encoding should I declare [UTF-8]?
>
> Which I should have just clicked 'Enter' on, but typed 'y' as 'yes
> please pick UTF-8'. Which again confirms the encoding, which I
> presumably didn't read. So I guess the problem Exists Between Keyboard
> and Chair.

OK, we have seen enough people got burned by 'y', and made 852a15d7
(send-email: ask confirmation if given encoding name is very short,
2015-02-13) as a response exactly for that problem, but it is not
effective as we wished X-<.

If there were a better validation method than "4 bytes or longer" we
currently use for valid values for "charset=$auto_8bit_encoding", we
could lose confirm_only from the call to ask() that asks the
question, but I do not know if that is feasible.

Another more obvious alternative is to do something ugly like this
patch, I suppose?  Just like <ENTER> is taken as "I take the default
value presented", this makes yes<ENTER> mean the same thing.

There is one question that asks yes/no question with default set to
'n', which would be broken by the patch below, so it needs a bit
more thought, though.

 git-send-email.perl | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git c/git-send-email.perl w/git-send-email.perl
index 798d59b84f..8b942e5bcf 100755
--- c/git-send-email.perl
+++ w/git-send-email.perl
@@ -986,7 +986,8 @@ sub ask {
 			print "\n";
 			return defined $default ? $default : undef;
 		}
-		if ($resp eq '' and defined $default) {
+		if (defined $default &&
+		    ($resp eq '' || $resp =~ /^y(?:es)$/i)) {
 			return $default;
 		}
 		if (!defined $valid_re or $resp =~ /$valid_re/) {