Skip to content

Commit f11b01b

Browse files
committed
Merge branch 'mh/send-email-reset-in-reply-to' into maint
Even when running "git send-email" without its own threaded discussion support, a threading related header in one message is carried over to the subsequent message to result in an unwanted threading, which has been corrected. * mh/send-email-reset-in-reply-to: send-email: avoid incorrect header propagation
2 parents e4bea4a + e082113 commit f11b01b

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
@@ -1697,7 +1697,6 @@ sub send_message {
16971697

16981698
$in_reply_to = $initial_in_reply_to;
16991699
$references = $initial_in_reply_to || '';
1700-
$subject = $initial_subject;
17011700
$message_num = 0;
17021701

17031702
# Prepares the email, prompts the user, sends it out
@@ -1720,6 +1719,7 @@ sub process_file {
17201719
@xh = ();
17211720
my $input_format = undef;
17221721
my @header = ();
1722+
$subject = $initial_subject;
17231723
$message = "";
17241724
$message_num++;
17251725
# First unfold multiline header fields
@@ -1926,15 +1926,23 @@ sub process_file {
19261926
}
19271927

19281928
# set up for the next message
1929-
if ($thread && $message_was_sent &&
1930-
($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
1931-
$message_num == 1)) {
1932-
$in_reply_to = $message_id;
1933-
if (length $references > 0) {
1934-
$references .= "\n $message_id";
1935-
} else {
1936-
$references = "$message_id";
1929+
if ($thread) {
1930+
if ($message_was_sent &&
1931+
($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
1932+
$message_num == 1)) {
1933+
$in_reply_to = $message_id;
1934+
if (length $references > 0) {
1935+
$references .= "\n $message_id";
1936+
} else {
1937+
$references = "$message_id";
1938+
}
19371939
}
1940+
} elsif (!defined $initial_in_reply_to) {
1941+
# --thread and --in-reply-to manage the "In-Reply-To" header and by
1942+
# extension the "References" header. If these commands are not used, reset
1943+
# the header values to their defaults.
1944+
$in_reply_to = undef;
1945+
$references = '';
19381946
}
19391947
$message_id = undef;
19401948
$num_sent++;

t/t9001-send-email.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,6 +2227,51 @@ test_expect_success $PREREQ 'test shell expression with --sendmail-cmd' '
22272227
test_path_is_file commandline1
22282228
'
22292229

2230+
test_expect_success $PREREQ 'set up in-reply-to/references patches' '
2231+
cat >has-reply.patch <<-\EOF &&
2232+
From: A U Thor <[email protected]>
2233+
Subject: patch with in-reply-to
2234+
Message-ID: <[email protected]>
2235+
In-Reply-To: <[email protected]>
2236+
References: <[email protected]>
2237+
2238+
This is the body.
2239+
EOF
2240+
cat >no-reply.patch <<-\EOF
2241+
From: A U Thor <[email protected]>
2242+
Subject: patch without in-reply-to
2243+
Message-ID: <[email protected]>
2244+
2245+
This is the body.
2246+
EOF
2247+
'
2248+
2249+
test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
2250+
clean_fake_sendmail &&
2251+
git send-email \
2252+
--no-thread \
2253+
2254+
--smtp-server="$(pwd)/fake.sendmail" \
2255+
has-reply.patch no-reply.patch &&
2256+
grep "In-Reply-To: <[email protected]>" msgtxt1 &&
2257+
grep "References: <[email protected]>" msgtxt1 &&
2258+
! grep [email protected] msgtxt2
2259+
'
2260+
2261+
test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
2262+
clean_fake_sendmail &&
2263+
git send-email \
2264+
--no-thread \
2265+
--in-reply-to="<[email protected]>" \
2266+
2267+
--smtp-server="$(pwd)/fake.sendmail" \
2268+
has-reply.patch no-reply.patch &&
2269+
grep "In-Reply-To: <[email protected]>" msgtxt1 &&
2270+
grep "References: <[email protected]>" msgtxt1 &&
2271+
grep "In-Reply-To: <[email protected]>" msgtxt2 &&
2272+
grep "References: <[email protected]>" msgtxt2
2273+
'
2274+
22302275
test_expect_success $PREREQ 'invoke hook' '
22312276
mkdir -p .git/hooks &&
22322277

0 commit comments

Comments
 (0)