Skip to content

Commit 00f372e

Browse files
committed
Merge branch 'ms/send-email-validate-fix'
"git send-email" did not have certain pieces of data computed yet when it tried to validate the outging messages and its recipient addresses, which has been sorted out. * ms/send-email-validate-fix: send-email: move validation code below process_address_list
2 parents dbffe54 + 0d86470 commit 00f372e

File tree

2 files changed

+51
-28
lines changed

2 files changed

+51
-28
lines changed

git-send-email.perl

Lines changed: 32 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -799,30 +799,6 @@ sub is_format_patch_arg {
799799

800800
$time = time - scalar $#files;
801801

802-
if ($validate) {
803-
# FIFOs can only be read once, exclude them from validation.
804-
my @real_files = ();
805-
foreach my $f (@files) {
806-
unless (-p $f) {
807-
push(@real_files, $f);
808-
}
809-
}
810-
811-
# Run the loop once again to avoid gaps in the counter due to FIFO
812-
# arguments provided by the user.
813-
my $num = 1;
814-
my $num_files = scalar @real_files;
815-
$ENV{GIT_SENDEMAIL_FILE_TOTAL} = "$num_files";
816-
foreach my $r (@real_files) {
817-
$ENV{GIT_SENDEMAIL_FILE_COUNTER} = "$num";
818-
pre_process_file($r, 1);
819-
validate_patch($r, $target_xfer_encoding);
820-
$num += 1;
821-
}
822-
delete $ENV{GIT_SENDEMAIL_FILE_COUNTER};
823-
delete $ENV{GIT_SENDEMAIL_FILE_TOTAL};
824-
}
825-
826802
@files = handle_backup_files(@files);
827803

828804
if (@files) {
@@ -1726,10 +1702,6 @@ sub send_message {
17261702
return 1;
17271703
}
17281704

1729-
$in_reply_to = $initial_in_reply_to;
1730-
$references = $initial_in_reply_to || '';
1731-
$message_num = 0;
1732-
17331705
sub pre_process_file {
17341706
my ($t, $quiet) = @_;
17351707

@@ -1995,6 +1967,38 @@ sub process_file {
19951967
return 1;
19961968
}
19971969

1970+
sub initialize_modified_loop_vars {
1971+
$in_reply_to = $initial_in_reply_to;
1972+
$references = $initial_in_reply_to || '';
1973+
$message_num = 0;
1974+
}
1975+
1976+
if ($validate) {
1977+
# FIFOs can only be read once, exclude them from validation.
1978+
my @real_files = ();
1979+
foreach my $f (@files) {
1980+
unless (-p $f) {
1981+
push(@real_files, $f);
1982+
}
1983+
}
1984+
1985+
# Run the loop once again to avoid gaps in the counter due to FIFO
1986+
# arguments provided by the user.
1987+
my $num = 1;
1988+
my $num_files = scalar @real_files;
1989+
$ENV{GIT_SENDEMAIL_FILE_TOTAL} = "$num_files";
1990+
initialize_modified_loop_vars();
1991+
foreach my $r (@real_files) {
1992+
$ENV{GIT_SENDEMAIL_FILE_COUNTER} = "$num";
1993+
pre_process_file($r, 1);
1994+
validate_patch($r, $target_xfer_encoding);
1995+
$num += 1;
1996+
}
1997+
delete $ENV{GIT_SENDEMAIL_FILE_COUNTER};
1998+
delete $ENV{GIT_SENDEMAIL_FILE_TOTAL};
1999+
}
2000+
2001+
initialize_modified_loop_vars();
19982002
foreach my $t (@files) {
19992003
while (!process_file($t)) {
20002004
# user edited the file

t/t9001-send-email.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -633,6 +633,25 @@ test_expect_success $PREREQ "--validate respects absolute core.hooksPath path" '
633633
test_cmp expect actual
634634
'
635635

636+
test_expect_success $PREREQ "--validate hook supports multiple addresses in arguments" '
637+
hooks_path="$(pwd)/my-hooks" &&
638+
test_config core.hooksPath "$hooks_path" &&
639+
test_when_finished "rm my-hooks.ran" &&
640+
test_must_fail git send-email \
641+
--from="Example <[email protected]>" \
642+
643+
--smtp-server="$(pwd)/fake.sendmail" \
644+
--validate \
645+
longline.patch 2>actual &&
646+
test_path_is_file my-hooks.ran &&
647+
cat >expect <<-EOF &&
648+
fatal: longline.patch: rejected by sendemail-validate hook
649+
fatal: command '"'"'git hook run --ignore-missing sendemail-validate -- <patch> <header>'"'"' died with exit code 1
650+
warning: no patches were sent
651+
EOF
652+
test_cmp expect actual
653+
'
654+
636655
test_expect_success $PREREQ "--validate hook supports header argument" '
637656
write_script my-hooks/sendemail-validate <<-\EOF &&
638657
if test "$#" -ge 2

0 commit comments

Comments
 (0)