]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: avoid incorrect header propagation
authorMarvin Häuser <mhaeuser@posteo.de>
Mon, 30 Aug 2021 15:30:01 +0000 (15:30 +0000)
committerJunio C Hamano <gitster@pobox.com>
Mon, 30 Aug 2021 20:25:28 +0000 (13:25 -0700)
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 <peff@peff.net>
Signed-off-by: Marvin Häuser <mhaeuser@posteo.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
git-send-email.perl
t/t9001-send-email.sh

index 1f425c08091d400e1d2e94533411c1b778f561de..29910576d71d8b9ab7959b610e3e7bac8d261695 100755 (executable)
@@ -1608,7 +1608,6 @@ EOF
 
 $in_reply_to = $initial_in_reply_to;
 $references = $initial_in_reply_to || '';
-$subject = $initial_subject;
 $message_num = 0;
 
 # Prepares the email, prompts the user, sends it out
@@ -1631,6 +1630,7 @@ sub process_file {
        @xh = ();
        my $input_format = undef;
        my @header = ();
+       $subject = $initial_subject;
        $message = "";
        $message_num++;
        # First unfold multiline header fields
@@ -1837,15 +1837,23 @@ sub process_file {
        }
 
        # set up for the next message
-       if ($thread && $message_was_sent &&
-               ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
-               $message_num == 1)) {
-               $in_reply_to = $message_id;
-               if (length $references > 0) {
-                       $references .= "\n $message_id";
-               } else {
-                       $references = "$message_id";
+       if ($thread) {
+               if ($message_was_sent &&
+                 ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
+                 $message_num == 1)) {
+                       $in_reply_to = $message_id;
+                       if (length $references > 0) {
+                               $references .= "\n $message_id";
+                       } else {
+                               $references = "$message_id";
+                       }
                }
+       } elsif (!defined $initial_in_reply_to) {
+               # --thread and --in-reply-to manage the "In-Reply-To" header and by
+               # extension the "References" header. If these commands are not used, reset
+               # the header values to their defaults.
+               $in_reply_to = undef;
+               $references = '';
        }
        $message_id = undef;
        $num_sent++;
index 4eee9c3dcb5383b2d709c6f7aac1e1416322426f..35be6b019037a8c89288ebdb738d58c062eab1aa 100755 (executable)
@@ -2097,6 +2097,51 @@ test_expect_success $PREREQ 'leading and trailing whitespaces are removed' '
        test_cmp expected-list actual-list
 '
 
+test_expect_success $PREREQ 'set up in-reply-to/references patches' '
+       cat >has-reply.patch <<-\EOF &&
+       From: A U Thor <author@example.com>
+       Subject: patch with in-reply-to
+       Message-ID: <patch.with.in.reply.to@example.com>
+       In-Reply-To: <replied.to@example.com>
+       References: <replied.to@example.com>
+
+       This is the body.
+       EOF
+       cat >no-reply.patch <<-\EOF
+       From: A U Thor <author@example.com>
+       Subject: patch without in-reply-to
+       Message-ID: <patch.without.in.reply.to@example.com>
+
+       This is the body.
+       EOF
+'
+
+test_expect_success $PREREQ 'patch reply headers correct with --no-thread' '
+       clean_fake_sendmail &&
+       git send-email \
+               --no-thread \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               has-reply.patch no-reply.patch &&
+       grep "In-Reply-To: <replied.to@example.com>" msgtxt1 &&
+       grep "References: <replied.to@example.com>" msgtxt1 &&
+       ! grep replied.to@example.com msgtxt2
+'
+
+test_expect_success $PREREQ 'cmdline in-reply-to used with --no-thread' '
+       clean_fake_sendmail &&
+       git send-email \
+               --no-thread \
+               --in-reply-to="<cmdline.reply@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               has-reply.patch no-reply.patch &&
+       grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt1 &&
+       grep "References: <cmdline.reply@example.com>" msgtxt1 &&
+       grep "In-Reply-To: <cmdline.reply@example.com>" msgtxt2 &&
+       grep "References: <cmdline.reply@example.com>" msgtxt2
+'
+
 test_expect_success $PREREQ 'invoke hook' '
        mkdir -p .git/hooks &&