send-email: relay '-v N' to format-patch

send-email relays unrecognized arguments to its format-patch call. Passing '-v N' leads to an error because -v is consumed as send-email's --validate. For example, git send-email -v 3 @{u} fails with fatal: ambiguous argument '3': unknown revision or path not in the working tree. [...] To prevent this, add the short --reroll-count option to send-email's main option list and explicitly provide it to the format-patch call. There other format-patch options that send-email doesn't relay properly, including at least -n, -N, and the diff option -D. Punt on these because dealing with them is more complicated: * they would require configuring send-email to not ignore option case * send-email makes three GetOptions() calls with different sets of options, the last being the main set of options. Unlike -v, which is consumed by the last GetOptions call, the -n, -N, and -D options are consumed as abbreviations by the earlier calls. Signed-off-by: Kyle Meyer <kyle@kyleam.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Kyle Meyer committed Nov 26, 2022 at 15:21 UTC 8774aa56ad1af286b34e6ac7f1e65c75a4477fdd
2 files changed +14 -1
git-send-email.perl
+8 -1
@@ -220,6 +220,10 @@ my $compose_filename;
220 my $force = 0;
221 my $dump_aliases = 0;
222
223 +# Variables to prevent short format-patch options from being captured
224 +# as abbreviated send-email options
225 +my $reroll_count;
226 +
227 # Handle interactive edition of files.
228 my $multiedit;
229 my $editor;
@@ -542,6 +546,7 @@ my %options = (
546 "batch-size=i" => \$batch_size,
547 "relogin-delay=i" => \$relogin_delay,
548 "git-completion-helper" => \$git_completion_helper,
549 + "v=s" => \$reroll_count,
550 );
551 $rc = GetOptions(%options);
552
@@ -782,7 +787,9 @@ if (@rev_list_opts) {
787 die __("Cannot run git format-patch from outside a repository\n")
788 unless $repo;
789 require File::Temp;
785 - push @files, $repo->command('format-patch', '-o', File::Temp::tempdir(CLEANUP => 1), @rev_list_opts);
790 + push @files, $repo->command('format-patch', '-o', File::Temp::tempdir(CLEANUP => 1),
791 + defined $reroll_count ? ('-v', $reroll_count) : (),
792 + @rev_list_opts);
793 }
794
795 @files = handle_backup_files(@files);
t/t9001-send-email.sh
+6
@@ -2334,6 +2334,12 @@ test_expect_success $PREREQ 'test that send-email works outside a repo' '
2334 "$(pwd)/0001-add-main.patch"
2335 '
2336
2337 +test_expect_success $PREREQ 'send-email relays -v 3 to format-patch' '
2338 + test_when_finished "rm -f out" &&
2339 + git send-email --dry-run -v 3 -1 >out &&
2340 + grep "PATCH v3" out
2341 +'
2342 +
2343 test_expect_success $PREREQ 'test that sendmail config is rejected' '
2344 test_config sendmail.program sendmail &&
2345 test_must_fail git send-email \