@matheusbsbs / matheus-bagliano / commits / 747bbff9b9
Fork 0

send-email: validate patches before sending anything

We try to catch errors early so that we don't end up sending half of a broken patch series. Right now the only validation is checking that line-lengths are under the SMTP-mandated limit of 998. The validation parsing is very crude (it just checks each line length without understanding the mailbox format) but should work fine for this simple check. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Jan 18, 2008 at 09:19 UTC 747bbff9b9583642cd8702b7b559757a6960df00
2 files changed +37
git-send-email.perl
+17
@@ -332,6 +332,11 @@ for my $f (@ARGV) {
332 }
333 }
334
335 +foreach my $f (@files) {
336 + my $error = validate_patch($f);
337 + $error and die "fatal: $f: $error\nwarning: no patches were sent\n";
338 +}
339 +
340 if (@files) {
341 unless ($quiet) {
342 print $_,"\n" for (@files);
@@ -837,3 +842,15 @@ sub unique_email_list(@) {
842 }
843 return @emails;
844 }
845 +
846 +sub validate_patch {
847 + my $fn = shift;
848 + open(my $fh, '<', $fn)
849 + or die "unable to open $fn: $!\n";
850 + while (my $line = <$fh>) {
851 + if (length($line) > 998) {
852 + return "$.: patch contains a line longer than 998 characters";
853 + }
854 + }
855 + return undef;
856 +}
t/t9001-send-email.sh
+20
@@ -78,4 +78,24 @@ test_expect_success 'Show all headers' '
78 diff -u expected-show-all-headers actual-show-all-headers
79 '
80
81 +z8=zzzzzzzz
82 +z64=$z8$z8$z8$z8$z8$z8$z8$z8
83 +z512=$z64$z64$z64$z64$z64$z64$z64$z64
84 +test_expect_success 'reject long lines' '
85 + rm -f commandline &&
86 + cp $patches longline.patch &&
87 + echo $z512$z512 >>longline.patch &&
88 + ! git send-email \
89 + --from="Example <nobody@example.com>" \
90 + --to=nobody@example.com \
91 + --smtp-server="$(pwd)/fake.sendmail" \
92 + $patches longline.patch \
93 + 2>errors &&
94 + grep longline.patch errors
95 +'
96 +
97 +test_expect_success 'no patch was sent' '
98 + ! test -e commandline
99 +'
100 +
101 test_done