Skip to content

Commit e082113

Browse files
mhaeusergitster
authored andcommitted
send-email: avoid incorrect header propagation
If multiple independent patches are sent with send-email, even if the "In-Reply-To" and "References" headers are not managed by --thread or --in-reply-to, their values may be propagated from prior patches to subsequent patches with no such headers defined. To mitigate this and potential future issues, make sure all global patch-specific variables are always either handled by command-specific code (e.g. threading), or are reset to their default values for every iteration. Signed-off-by: Jeff King <[email protected]> Signed-off-by: Marvin Häuser <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 48bf2fa commit e082113

File tree

2 files changed

+62
-9
lines changed

2 files changed

+62
-9
lines changed

git-send-email.perl

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1608,7 +1608,6 @@ sub send_message {
16081608

16091609
$in_reply_to = $initial_in_reply_to;
16101610
$references = $initial_in_reply_to || '';
1611-
$subject = $initial_subject;
16121611
$message_num = 0;
16131612

16141613
# Prepares the email, prompts the user, sends it out
@@ -1631,6 +1630,7 @@ sub process_file {
16311630
@xh = ();
16321631
my $input_format = undef;
16331632
my @header = ();
1633+
$subject = $initial_subject;
16341634
$message = "";
16351635
$message_num++;
16361636
# First unfold multiline header fields
@@ -1837,15 +1837,23 @@ sub process_file {
18371837
}
18381838

18391839
# set up for the next message
1840-
if ($thread && $message_was_sent &&
1841-
($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
1842-
$message_num == 1)) {
1843-
$in_reply_to = $message_id;
1844-
if (length $references > 0) {
1845-
$references .= "\n $message_id";
1846-
} else {
1847-
$references = "$message_id";
1840+
if ($thread) {
1841+
if ($message_was_sent &&
1842+
($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
1843+
$message_num == 1)) {
1844+
$in_reply_to = $message_id;
1845+
if (length $references > 0) {
1846+
$references .= "\n $message_id";
1847+
} else {
1848+
$references = "$message_id";
1849+
}
18481850
}
1851+
} elsif (!defined $initial_in_reply_to) {
1852+
# --thread and --in-reply-to manage the "In-Reply-To" header and by
1853+
# extension the "References" header. If these commands are not used, reset
1854+
# the header values to their defaults.
1855+
$in_reply_to = undef;
1856+
$references = '';
18491857
}
18501858
$message_id = undef;
18511859
$num_sent++;

t/t9001-send-email.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2097,6 +2097,51 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
20972097
test_cmp expected-list actual-list
20982098
'
20992099

2100+
test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2101+
cat >has-reply.patch <<-\EOF &&
2102+
From: A U Thor <[email protected]>
2103+
Subject: patch with in-reply-to
2104+
Message-ID: <[email protected]>
2105+
In-Reply-To: <[email protected]>
2106+
References: <[email protected]>
2107+
2108+
This is the body.
2109+
EOF
2110+
cat >no-reply.patch <<-\EOF
2111+
From: A U Thor <[email protected]>
2112+
Subject: patch without in-reply-to
2113+
Message-ID: <[email protected]>
2114+
2115+
This is the body.
2116+
EOF
2117+
'
2118+
2119+
test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2120+
clean_fake_sendmail &&
2121+
git send-email \
2122+
--no-thread \
2123+
2124+
--smtp-server="$(pwd)/fake.sendmail" \
2125+
has-reply.patch no-reply.patch &&
2126+
grep "In-Reply-To: <[email protected]>" msgtxt1 &&
2127+
grep "References: <[email protected]>" msgtxt1 &&
2128+
! grep [email protected] msgtxt2
2129+
'
2130+
2131+
test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2132+
clean_fake_sendmail &&
2133+
git send-email \
2134+
--no-thread \
2135+
--in-reply-to="<[email protected]>" \
2136+
2137+
--smtp-server="$(pwd)/fake.sendmail" \
2138+
has-reply.patch no-reply.patch &&
2139+
grep "In-Reply-To: <[email protected]>" msgtxt1 &&
2140+
grep "References: <[email protected]>" msgtxt1 &&
2141+
grep "In-Reply-To: <[email protected]>" msgtxt2 &&
2142+
grep "References: <[email protected]>" msgtxt2
2143+
'
2144+
21002145
test_expect_success $PREREQ 'invoke hook' '
21012146
mkdir -p .git/hooks &&
21022147

0 commit comments

Comments
 (0)