Subject: Re: [PATCH] send-email: disable option auto-abbreviation

From: Junio C Hamano <[email-masked]>
Date: Fri, 25 Nov 2022 16:11:06 +0900

Kyle Meyer <[email-masked]> writes:

> send-email supports specifying format-patch options.  However, some
> valid format-patch short options trigger an error because Getopt's
> default auto-abbreviation is enabled.  For example, with
>
>   git send-email -v 3 @{u}
>
> the -v is consumed as send-email's --validate, and 3 is passed on to
> the format-patch call, leading to
>
>   fatal: ambiguous argument '3': unknown revision or path not in the
>   working tree.  [...]
>
> Disable Getopt's auto-abbreviation feature so that such options are
> properly relayed to format-patch.  With this change, there is some
> risk of breaking external scripts that rely on the abbreviation, but
> that is hopefully unlikely given that Git does not advertise support
> for auto-abbreviation and most subcommands do not support it.

I personally have no sympathy to those who drive "format-patch" from
inside "send-email".

Having said that.

Many subcommands of "git" do take uniquely abbreviated double-dashed
option names, but it is true that we do not allow --vanything to be
given as -v even when there is no other double-dashed option that
begins with 'v', so "git send-email -v" that stands for "git
send-email --validate" indeed is an odd thing.

But robbing "git send-email --val" that expands to "--validate" from
the users is going a bit too far, I am afraid.  The right solution
for allowing "-v 3" given to "format-patch" I think is to make
send-email understand it and pass that through.  The presence of
both ("validate" => \$validate) and ("v" => \$reroll_count) in the
GetOptions() argument would prevent "-v" to be taken as "--validate"
while still allowing "--val" to be used as an abbrevatiion, no?

By the way, do we advertise support for any and all options to
format-patch when the feature to drive it from send-email is used?
Some of the options (e.g. "-o <directory>") do not make any sense in
the context I would suspect.