Skip to content

Commit b886656

Browse files
committed
Merge branch 'tr/send-email-refuse-sending-unedited-cover-letter'
* tr/send-email-refuse-sending-unedited-cover-letter: send-email: Refuse to send cover-letter template subject
2 parents 34289ec + a03bc5b commit b886656

File tree

2 files changed

+49
-0
lines changed

2 files changed

+49
-0
lines changed

git-send-email.perl

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ sub usage {
8686
--[no-]validate * Perform patch sanity checks. Default on.
8787
--[no-]format-patch * understand any non optional arguments as
8888
`git format-patch` ones.
89+
--force * Send even if safety checks would prevent it.
8990
9091
EOT
9192
exit(1);
@@ -163,6 +164,7 @@ sub format_2822_time {
163164
my ($quiet, $dry_run) = (0, 0);
164165
my $format_patch;
165166
my $compose_filename;
167+
my $force = 0;
166168

167169
# Handle interactive edition of files.
168170
my $multiedit;
@@ -302,6 +304,7 @@ sub signal_handler {
302304
"validate!" => \$validate,
303305
"format-patch!" => \$format_patch,
304306
"8bit-encoding=s" => \$auto_8bit_encoding,
307+
"force" => \$force,
305308
);
306309

307310
unless ($rc) {
@@ -703,6 +706,16 @@ ($)
703706
default => "UTF-8");
704707
}
705708

709+
if (!$force) {
710+
for my $f (@files) {
711+
if (get_patch_subject($f) =~ /\*\*\* SUBJECT HERE \*\*\*/) {
712+
die "Refusing to send because the patch\n\t$f\n"
713+
. "has the template subject '*** SUBJECT HERE ***'. "
714+
. "Pass --force if you really want to send.\n";
715+
}
716+
}
717+
}
718+
706719
my $prompting = 0;
707720
if (!defined $sender) {
708721
$sender = $repoauthor || $repocommitter || '';

t/t9001-send-email.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1032,4 +1032,40 @@ test_expect_success $PREREQ '--8bit-encoding also treats subject' '
10321032
test_cmp expected actual
10331033
'
10341034

1035+
# Note that the patches in this test are deliberately out of order; we
1036+
# want to make sure it works even if the cover-letter is not in the
1037+
# first mail.
1038+
test_expect_success 'refusing to send cover letter template' '
1039+
clean_fake_sendmail &&
1040+
rm -fr outdir &&
1041+
git format-patch --cover-letter -2 -o outdir &&
1042+
test_must_fail git send-email \
1043+
--from="Example <[email protected]>" \
1044+
1045+
--smtp-server="$(pwd)/fake.sendmail" \
1046+
outdir/0002-*.patch \
1047+
outdir/0000-*.patch \
1048+
outdir/0001-*.patch \
1049+
2>errors >out &&
1050+
grep "SUBJECT HERE" errors &&
1051+
test -z "$(ls msgtxt*)"
1052+
'
1053+
1054+
test_expect_success '--force sends cover letter template anyway' '
1055+
clean_fake_sendmail &&
1056+
rm -fr outdir &&
1057+
git format-patch --cover-letter -2 -o outdir &&
1058+
git send-email \
1059+
--force \
1060+
--from="Example <[email protected]>" \
1061+
1062+
--smtp-server="$(pwd)/fake.sendmail" \
1063+
outdir/0002-*.patch \
1064+
outdir/0000-*.patch \
1065+
outdir/0001-*.patch \
1066+
2>errors >out &&
1067+
! grep "SUBJECT HERE" errors &&
1068+
test -n "$(ls msgtxt*)"
1069+
'
1070+
10351071
test_done

0 commit comments

Comments
 (0)