]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: handle to/cc/bcc from --compose message
authorJeff King <peff@peff.net>
Fri, 20 Oct 2023 10:15:24 +0000 (06:15 -0400)
committerJunio C Hamano <gitster@pobox.com>
Fri, 20 Oct 2023 21:31:39 +0000 (14:31 -0700)
If the user writes a message via --compose, send-email will pick up
various headers like "From", "Subject", etc and use them for other
patches as if they were specified on the command-line. But we don't
handle "To", "Cc", or "Bcc" this way; we just tell the user "those
aren't interpeted yet" and ignore them.

But it seems like an obvious thing to want, especially as the same
feature exists when the cover letter is generated separately by
format-patch. There it is gated behind the --to-cover option, but I
don't think we'd need the same control here; since we generate the
--compose template ourselves based on the existing input, if the user
leaves the lines unchanged then the behavior remains the same.

So let's fill in the implementation; like those other headers we already
handle, we just need to assign to the initial_* variables. The only
difference in this case is that they are arrays, so we'll feed them
through parse_address_line() to split them (just like we would when
reading a single string via prompting).

Signed-off-by: Jeff King <peff@peff.net>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-send-email.txt
git-send-email.perl
t/t9001-send-email.sh

index 021276329c63dd9dd80939d770f4d7a37fde69f5..f4d7166275ab7c51d285b28c8aa8851638e9c993 100644 (file)
@@ -68,11 +68,12 @@ This option may be specified multiple times.
        Invoke a text editor (see GIT_EDITOR in linkgit:git-var[1])
        to edit an introductory message for the patch series.
 +
-When `--compose` is used, git send-email will use the From, Subject,
-Reply-To, and In-Reply-To headers specified in the message. If the body
-of the message (what you type after the headers and a blank line) only
-contains blank (or Git: prefixed) lines, the summary won't be sent, but
-the headers mentioned above will be used unless they are removed.
+When `--compose` is used, git send-email will use the From, To, Cc, Bcc,
+Subject, Reply-To, and In-Reply-To headers specified in the message. If
+the body of the message (what you type after the headers and a blank
+line) only contains blank (or Git: prefixed) lines, the summary won't be
+sent, but the headers mentioned above will be used unless they are
+removed.
 +
 Missing From or In-Reply-To headers will be prompted for.
 +
index 2adaa359386c3b39190b2197399d47bc9c6fd93a..526f2dd712382e7cb330201074c353f3b59975ed 100755 (executable)
@@ -861,6 +861,9 @@ if ($compose) {
        my $tpl_subject = $initial_subject || '';
        my $tpl_in_reply_to = $initial_in_reply_to || '';
        my $tpl_reply_to = $reply_to || '';
+       my $tpl_to = join(',', @initial_to);
+       my $tpl_cc = join(',', @initial_cc);
+       my $tpl_bcc = join(', ', @initial_bcc);
 
        print $c <<EOT1, Git::prefix_lines("GIT: ", __(<<EOT2)), <<EOT3;
 From $tpl_sender # This line is ignored.
@@ -872,6 +875,9 @@ for the patch you are writing.
 Clear the body content if you don't wish to send a summary.
 EOT2
 From: $tpl_sender
+To: $tpl_to
+Cc: $tpl_cc
+Bcc: $tpl_bcc
 Reply-To: $tpl_reply_to
 Subject: $tpl_subject
 In-Reply-To: $tpl_in_reply_to
@@ -928,8 +934,14 @@ EOT3
                } elsif (/^From:\s*(.+)\s*$/i) {
                        $sender = $1;
                        next;
-               } elsif (/^(?:To|Cc|Bcc):/i) {
-                       print __("To/Cc/Bcc fields are not interpreted yet, they have been ignored\n");
+               } elsif (/^To:\s*(.+)\s*$/i) {
+                       @initial_to = parse_address_line($1);
+                       next;
+               } elsif (/^Cc:\s*(.+)\s*$/i) {
+                       @initial_cc = parse_address_line($1);
+                       next;
+               } elsif (/^Bcc:/i) {
+                       @initial_bcc = parse_address_line($1);
                        next;
                }
                print $c2 $_;
index c62f032056e29dac44ceca49a7d06f3f057e66b9..4052b28e73f76b2033b7e8f886df65f2993d1d7e 100755 (executable)
@@ -2522,7 +2522,7 @@ test_expect_success $PREREQ '--compose handles lowercase headers' '
 
 test_expect_success $PREREQ '--compose handles to headers' '
        write_script fake-editor <<-\EOF &&
-       sed "s/^$/To: edited-to@example.com\n/" <"$1" >"$1.tmp" &&
+       sed "s/^To: .*/&, edited-to@example.com/" <"$1" >"$1.tmp" &&
        echo this is the body >>"$1.tmp" &&
        mv "$1.tmp" "$1"
        EOF
@@ -2534,10 +2534,16 @@ test_expect_success $PREREQ '--compose handles to headers' '
                --to=nobody@example.com \
                --smtp-server="$(pwd)/fake.sendmail" \
                HEAD^ &&
-       # Ideally the "to" header we specified would be used,
-       # but the program explicitly warns that these are
-       # ignored. For now, just make sure we did not abort.
-       grep "To:" msgtxt1
+       # Check both that the cover letter used our modified "to" line,
+       # but also that it was picked up for the patch.
+       q_to_tab >expect <<-\EOF &&
+       To: nobody@example.com,
+       Qedited-to@example.com
+       EOF
+       grep -A1 "^To:" msgtxt1 >msgtxt1.to &&
+       test_cmp expect msgtxt1.to &&
+       grep -A1 "^To:" msgtxt2 >msgtxt2.to &&
+       test_cmp expect msgtxt2.to
 '
 
 test_done