Skip to content

Commit 8774aa5

Browse files
kyleamgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c000d91 commit 8774aa5

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

git-send-email.perl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,10 @@ sub format_2822_time {
220220
my $force = 0;
221221
my $dump_aliases = 0;
222222

223+
# Variables to prevent short format-patch options from being captured
224+
# as abbreviated send-email options
225+
my $reroll_count;
226+
223227
# Handle interactive edition of files.
224228
my $multiedit;
225229
my $editor;
@@ -542,6 +546,7 @@ sub config_regexp {
542546
"batch-size=i" => \$batch_size,
543547
"relogin-delay=i" => \$relogin_delay,
544548
"git-completion-helper" => \$git_completion_helper,
549+
"v=s" => \$reroll_count,
545550
);
546551
$rc = GetOptions(%options);
547552

@@ -782,7 +787,9 @@ sub is_format_patch_arg {
782787
die __("Cannot run git format-patch from outside a repository\n")
783788
unless $repo;
784789
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);
786793
}
787794

788795
@files = handle_backup_files(@files);

t/t9001-send-email.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2334,6 +2334,12 @@ test_expect_success $PREREQ 'test that send-email works outside a repo' '
23342334
"$(pwd)/0001-add-main.patch"
23352335
'
23362336

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+
23372343
test_expect_success $PREREQ 'test that sendmail config is rejected' '
23382344
test_config sendmail.program sendmail &&
23392345
test_must_fail git send-email \

0 commit comments

Comments
 (0)