send-email: validate patches before sending anything
[gitweb.git] / git-send-email.perl
index 7a86977ef104da807743c879532ca942dd2c939a..4e62c3f0e77387c0c8b2b24a9e4abd79fd18f7f4 100755 (executable)
@@ -332,6 +332,11 @@ sub read_config {
        }
 }
 
+foreach my $f (@files) {
+       my $error = validate_patch($f);
+       $error and die "fatal: $f: $error\nwarning: no patches were sent\n";
+}
+
 if (@files) {
        unless ($quiet) {
                print $_,"\n" for (@files);
@@ -837,3 +842,15 @@ (@)
        }
        return @emails;
 }
+
+sub validate_patch {
+       my $fn = shift;
+       open(my $fh, '<', $fn)
+               or die "unable to open $fn: $!\n";
+       while (my $line = <$fh>) {
+               if (length($line) > 998) {
+                       return "$.: patch contains a line longer than 998 characters";
+               }
+       }
+       return undef;
+}