Skip to content

Commit 21802cd

Browse files
bebarinogitster
authored andcommitted
send-email: Use To: headers in patch files
It's a minor annoyance when you take the painstaking time to setup To: headers for each patch in a large series, and then go out to send the series with git-send-email and watch git ignore the To: headers in the patch files. Therefore, always add To: headers from a patch file to the To: headers for that message. Keep the prompt for the blanket To: header so as to not break scripts (and user expectations). This means even if a patch has a To: header, git will prompt for the To: address. Otherwise, we'll need to introduce interface breakage to either request the header for each patch missing a To: header or default the header to whatever To: address is found first (be it in a patch or from user input). Both of these options don't seem very obvious/useful. Reported-by: Viresh Kumar <[email protected]> Signed-off-by: Stephen Boyd <[email protected]> Tested-by: Viresh Kumar <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 442cb08 commit 21802cd

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

git-send-email.perl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1176,6 +1176,13 @@ sub send_message {
11761176
$1, $_) unless $quiet;
11771177
push @cc, $1;
11781178
}
1179+
elsif (/^To:\s+(.*)$/) {
1180+
foreach my $addr (parse_address_line($1)) {
1181+
printf("(mbox) Adding to: %s from line '%s'\n",
1182+
$addr, $_) unless $quiet;
1183+
push @to, sanitize_address($addr);
1184+
}
1185+
}
11791186
elsif (/^Cc:\s+(.*)$/) {
11801187
foreach my $addr (parse_address_line($1)) {
11811188
if (unquote_rfc2047($addr) eq $sender) {

t/t9001-send-email.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -947,6 +947,30 @@ test_expect_success $PREREQ '--no-bcc overrides sendemail.bcc' '
947947
! grep "RCPT TO:<[email protected]>" stdout
948948
'
949949

950+
test_expect_success $PREREQ 'patches To headers are used by default' '
951+
patch=`git format-patch -1 --to="[email protected]"` &&
952+
test_when_finished "rm $patch" &&
953+
git send-email \
954+
--dry-run \
955+
--from="Example <[email protected]>" \
956+
--smtp-server relay.example.com \
957+
$patch >stdout &&
958+
grep "RCPT TO:<[email protected]>" stdout
959+
'
960+
961+
test_expect_success $PREREQ 'patches To headers are appended to' '
962+
patch=`git format-patch -1 --to="[email protected]"` &&
963+
test_when_finished "rm $patch" &&
964+
git send-email \
965+
--dry-run \
966+
--from="Example <[email protected]>" \
967+
968+
--smtp-server relay.example.com \
969+
$patch >stdout &&
970+
grep "RCPT TO:<[email protected]>" stdout &&
971+
grep "RCPT TO:<[email protected]>" stdout
972+
'
973+
950974
test_expect_success $PREREQ 'setup expect' '
951975
cat >email-using-8bit <<EOF
952976
From fe6ecc66ece37198fe5db91fa2fc41d9f4fe5cc4 Mon Sep 17 00:00:00 2001

0 commit comments

Comments
 (0)