git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[RFC PATCH] send-email: allow fixing the cover letter subject

From
Carlo Marcelo Arenas Belón <carenas@gmail.com>
Date
Aug 24, 2021, 11:41 UTC
Message-ID
<20210824114135.54810-1-carenas@gmail.com>

a03bc5b6ad (send-email: Refuse to send cover-letter template subject, 2009-06-08) fixes a common problem with the direct use of `git send-email` to send topics, where the cover letter will be a template by accident.

Allow using --subject to fix the --cover-letter subject and skip the safety check without having to use --force.

Note that the use of --compose is also allowed, and will also get its Subject set through the commandline, but it might make more sense to instead make them incompatible and force editing the cover letter instead, hence why sending this only as a RFC.

patch is based on another one[1] still in fly, and the documentation change is long overdue, but probably should need a better explanation; lastly using a non ASCII subject also needs fixing, but it also affects compose, so was left out for now.

Signed-off-by: Carlo Marcelo Arenas Belón <carenas@gmail.com>
[1] https://lore.kernel.org/git/4db7759c-2123-533b-9f89-954c07f5832a@posteo.de/
---
 Documentation/git-send-email.txt |  3 +--
 git-send-email.perl              |  8 ++++++--
 t/t9001-send-email.sh            | 16 +++++++++++++++-
 3 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index 3db4eab4ba..9d2bfa6095 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -113,8 +113,7 @@ is not set, this will be prompted for.
 
 --subject=<string>::
 	Specify the initial subject of the email thread.
-	Only necessary if --compose is also set.  If --compose
-	is not set, this will be prompted for.
+	Only necessary if --compose or --cover-letter are also set.
 
 --to=<address>,...::
 	Specify the primary recipient of the emails generated. Generally, this
diff --git a/git-send-email.perl b/git-send-email.perl
index fd79849530..a33328a5d9 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -997,7 +997,7 @@ sub file_declares_8bit_cte {
 				  default => "UTF-8");
 }
 
-if (!$force) {
+if (!$force and not defined $initial_subject) {
 	for my $f (@files) {
 		if (get_patch_subject($f) =~ /\Q*** SUBJECT HERE ***\E/) {
 			die sprintf(__("Refusing to send because the patch\n\t%s\n"
@@ -1719,7 +1719,6 @@ sub process_file {
 	@xh = ();
 	my $input_format = undef;
 	my @header = ();
-	$subject = $initial_subject;
 	$message = "";
 	$message_num++;
 	# First unfold multiline header fields
@@ -1747,6 +1746,11 @@ sub process_file {
 		if (defined $input_format && $input_format eq 'mbox') {
 			if (/^Subject:\s+(.*)$/i) {
 				$subject = $1;
+
+				if (defined $initial_subject &&
+				$subject =~ /\Q*** SUBJECT HERE ***\E/) {
+					$subject = $initial_subject;
+				}
 			}
 			elsif (/^From:\s+(.*)$/i) {
 				($author, $author_encoding) = unquote_rfc2047($1);
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 747872d5be..043532fe85 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -1728,7 +1728,6 @@ test_expect_success $PREREQ 'CRLF and sendemail.transferencoding=base64' '
 	test_cmp expected actual
 '
 
-
 # Note that the patches in this test are deliberately out of order; we
 # want to make sure it works even if the cover-letter is not in the
 # first mail.
@@ -1765,6 +1764,21 @@ test_expect_success $PREREQ '--force sends cover letter template anyway' '
 	test -n "$(ls msgtxt*)"
 '
 
+test_expect_success $PREREQ '--subject can be used to fix the cover letter' '
+	clean_fake_sendmail &&
+	git send-email \
+		--cover-letter -2 \
+		--subject="foo" \
+		--from="Example <nobody@example.com>" \
+		--to=nobody@example.com \
+		--smtp-server="$(pwd)/fake.sendmail" \
+		2>errors >out &&
+	! grep "SUBJECT HERE" errors &&
+	ls msgtxt* >list &&
+	test_line_count = 3 list &&
+	grep "Subject: foo" msgtxt1
+'
+
 test_cover_addresses () {
 	header="$1"
 	shift
-- 
2.33.0.481.g26d3bed244
Next: Marvin Häuser
Message 1 of 6 in “send-email: allow fixing the cover letter subject”
  1. send-email: allow fixing the cover letter subjectCarlo Marcelo Arenas Belón, Aug 24, 2021
  2. Marvin HäuserAug 24, 2021
  3. Carlo ArenasAug 24, 2021
  4. Marvin HäuserAug 25, 2021
  5. Carlo ArenasAug 26, 2021
  6. Marvin HäuserAug 26, 2021

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.