All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Carlo Marcelo Arenas Belón" <carenas@gmail.com>
To: git@vger.kernel.org
Cc: tr@thomasrast.ch, mhaeuser@posteo.de,
	"Carlo Marcelo Arenas Belón" <carenas@gmail.com>
Subject: [RFC PATCH] send-email: allow fixing the cover letter subject
Date: Tue, 24 Aug 2021 04:41:35 -0700	[thread overview]
Message-ID: <20210824114135.54810-1-carenas@gmail.com> (raw)

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


             reply	other threads:[~2021-08-24 11:42 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-08-24 11:41 Carlo Marcelo Arenas Belón [this message]
2021-08-24 15:19 ` [RFC PATCH] send-email: allow fixing the cover letter subject Marvin Häuser
2021-08-24 16:11   ` Carlo Arenas
2021-08-25  6:31     ` Marvin Häuser
2021-08-26 10:58       ` Carlo Arenas
2021-08-26 19:31         ` Marvin Häuser

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20210824114135.54810-1-carenas@gmail.com \
    --to=carenas@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mhaeuser@posteo.de \
    --cc=tr@thomasrast.ch \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.