@matheusbsbs / matheus-bagliano / commits / a03bc5b6ad
Fork 0

send-email: Refuse to send cover-letter template subject

Every so often, someone sends out an unedited cover-letter template. Add a simple check to send-email that refuses to send if the subject contains "*** SUBJECT HERE ***", with an option --force to override. Signed-off-by: Thomas Rast <trast@student.ethz.ch> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thomas Rast committed Jun 8, 2009 at 23:34 UTC a03bc5b6ad4ada4eb0669289429a9bc21ff6cdb0
2 files changed +49
git-send-email.perl
+13
@@ -85,6 +85,7 @@ git send-email [options] <file | directory | rev-list options >
85 --[no-]validate * Perform patch sanity checks. Default on.
86 --[no-]format-patch * understand any non optional arguments as
87 `git format-patch` ones.
88 + --force * Send even if safety checks would prevent it.
89
90 EOT
91 exit(1);
@@ -162,6 +163,7 @@ if ($@) {
163 my ($quiet, $dry_run) = (0, 0);
164 my $format_patch;
165 my $compose_filename;
166 +my $force = 0;
167
168 # Handle interactive edition of files.
169 my $multiedit;
@@ -301,6 +303,7 @@ my $rc = GetOptions("sender|from=s" => \$sender,
303 "validate!" => \$validate,
304 "format-patch!" => \$format_patch,
305 "8bit-encoding=s" => \$auto_8bit_encoding,
306 + "force" => \$force,
307 );
308
309 unless ($rc) {
@@ -702,6 +705,16 @@ if (!defined $auto_8bit_encoding && scalar %broken_encoding) {
705 default => "UTF-8");
706 }
707
708 +if (!$force) {
709 + for my $f (@files) {
710 + if (get_patch_subject($f) =~ /\*\*\* SUBJECT HERE \*\*\*/) {
711 + die "Refusing to send because the patch\n\t$f\n"
712 + . "has the template subject '*** SUBJECT HERE ***'. "
713 + . "Pass --force if you really want to send.\n";
714 + }
715 + }
716 +}
717 +
718 my $prompting = 0;
719 if (!defined $sender) {
720 $sender = $repoauthor || $repocommitter || '';
t/t9001-send-email.sh
+36
@@ -995,4 +995,40 @@ test_expect_success '--8bit-encoding also treats subject' '
995 test_cmp expected actual
996 '
997
998 +# Note that the patches in this test are deliberately out of order; we
999 +# want to make sure it works even if the cover-letter is not in the
1000 +# first mail.
1001 +test_expect_success 'refusing to send cover letter template' '
1002 + clean_fake_sendmail &&
1003 + rm -fr outdir &&
1004 + git format-patch --cover-letter -2 -o outdir &&
1005 + test_must_fail git send-email \
1006 + --from="Example <nobody@example.com>" \
1007 + --to=nobody@example.com \
1008 + --smtp-server="$(pwd)/fake.sendmail" \
1009 + outdir/0002-*.patch \
1010 + outdir/0000-*.patch \
1011 + outdir/0001-*.patch \
1012 + 2>errors >out &&
1013 + grep "SUBJECT HERE" errors &&
1014 + test -z "$(ls msgtxt*)"
1015 +'
1016 +
1017 +test_expect_success '--force sends cover letter template anyway' '
1018 + clean_fake_sendmail &&
1019 + rm -fr outdir &&
1020 + git format-patch --cover-letter -2 -o outdir &&
1021 + git send-email \
1022 + --force \
1023 + --from="Example <nobody@example.com>" \
1024 + --to=nobody@example.com \
1025 + --smtp-server="$(pwd)/fake.sendmail" \
1026 + outdir/0002-*.patch \
1027 + outdir/0000-*.patch \
1028 + outdir/0001-*.patch \
1029 + 2>errors >out &&
1030 + ! grep "SUBJECT HERE" errors &&
1031 + test -n "$(ls msgtxt*)"
1032 +'
1033 +
1034 test_done