git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
* [PATCHv2] send-email: Ask if a patch should be sent twice
@ 2019-07-30 16:26 Dmitry Safonov
  2019-07-30 19:19 ` SZEDER Gábor
  0 siblings, 1 reply; 4+ messages in thread
From: Dmitry Safonov @ 2019-07-30 16:26 UTC (permalink / raw)
  To: git
  Cc: Junio C Hamano, Ævar Arnfjörð Bjarmason,
	Dmitry Safonov, Dmitry Safonov, Andrei Vagin

I was almost certain that git won't let me send the same patch twice,
but today I've managed to double-send a directory by a mistake:
	git send-email --to linux-kernel@vger.kernel.org /tmp/timens/
	    --cc 'Dmitry Safonov <0x7f454c46@gmail.com>' /tmp/timens/`

[I haven't noticed that I put the directory twice ^^]

Prevent this shipwreck from happening again by asking if a patch
is sent multiple times on purpose.

link: https://lkml.kernel.org/r/4d53ebc7-d5b2-346e-c383-606401d19d3a@gmail.com
Cc: Andrei Vagin <avagin@openvz.org>
Suggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Signed-off-by: Dmitry Safonov <dima@arista.com>
---
v2: Moved the check under --validate,
    fixed tests,
    added a new test,
    updated documentation for --validate
 Documentation/git-send-email.txt |  2 ++
 git-send-email.perl              | 14 ++++++++++++++
 t/t9001-send-email.sh            | 15 +++++++++++++++
 3 files changed, 31 insertions(+)

diff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt
index d93e5d0f58f0..0441bb1b5d3b 100644
--- a/Documentation/git-send-email.txt
+++ b/Documentation/git-send-email.txt
@@ -421,6 +421,8 @@ have been specified, in which case default to 'compose'.
 			('auto', 'base64', or 'quoted-printable') is used;
 			this is due to SMTP limits as described by
 			http://www.ietf.org/rfc/rfc5322.txt.
+		*	Ask confirmation before sending patches multiple times
+			if the supplied patches set overlaps.
 --
 +
 Default is the value of `sendemail.validate`; if this is not set,
diff --git a/git-send-email.perl b/git-send-email.perl
index 5f92c89c1c1b..c1638d06f81d 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -688,6 +688,9 @@ sub is_format_patch_arg {
 @files = handle_backup_files(@files);
 
 if ($validate) {
+	my %seen;
+	my @dupes = grep { $seen{$_}++ } @files;
+
 	foreach my $f (@files) {
 		unless (-p $f) {
 			my $error = validate_patch($f, $target_xfer_encoding);
@@ -695,6 +698,17 @@ sub is_format_patch_arg {
 						  $f, $error);
 		}
 	}
+	if (@dupes) {
+		printf(__("Patches specified several times: \n"));
+		printf(__("%s \n" x @dupes), @dupes);
+		$_ = ask(__("Do you want to send those patches several times? Y/n "),
+			default => "y",
+			valid_re => qr/^(?:yes|y|no|n)/i);
+		if (/^n/i) {
+			cleanup_compose_files();
+			exit(0);
+		}
+	}
 }
 
 if (@files) {
diff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh
index 997f90b42b3e..77df51519d6e 100755
--- a/t/t9001-send-email.sh
+++ b/t/t9001-send-email.sh
@@ -555,6 +555,7 @@ test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '
 		--no-chain-reply-to \
 		--in-reply-to="$(cat expect)" \
 		--smtp-server="$(pwd)/fake.sendmail" \
+		--no-validate \
 		$patches $patches $patches \
 		2>errors &&
 	# The first message is a reply to --in-reply-to
@@ -577,6 +578,7 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
 		--chain-reply-to \
 		--in-reply-to="$(cat expect)" \
 		--smtp-server="$(pwd)/fake.sendmail" \
+		--no-validate \
 		$patches $patches $patches \
 		2>errors &&
 	sed -n -e "s/^In-Reply-To: *\(.*\)/\1/p" msgtxt1 >actual &&
@@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
 	test_cmp expect actual
 '
 
+test_expect_success $PREREQ 'ask confirmation for double-send' '
+	clean_fake_sendmail &&
+	echo y | \
+		GIT_SEND_EMAIL_NOTTY=1 \
+		git send-email --from=author@example.com \
+			--to=nobody@example.com \
+			--smtp-server="$(pwd)/fake.sendmail" \
+			--validate \
+			$patches $patches $patches \
+			>stdout &&
+	! grep "Patches specified several times: " stdout
+'
+
 test_expect_success $PREREQ 'setup fake editor' '
 	write_script fake-editor <<-\EOF
 	echo fake edit >>"$1"
-- 
2.22.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] send-email: Ask if a patch should be sent twice
  2019-07-30 16:26 [PATCHv2] send-email: Ask if a patch should be sent twice Dmitry Safonov
@ 2019-07-30 19:19 ` SZEDER Gábor
  2019-07-30 19:35   ` Junio C Hamano
  0 siblings, 1 reply; 4+ messages in thread
From: SZEDER Gábor @ 2019-07-30 19:19 UTC (permalink / raw)
  To: Dmitry Safonov
  Cc: git, Junio C Hamano, Ævar Arnfjörð Bjarmason,
	Dmitry Safonov, Andrei Vagin

On Tue, Jul 30, 2019 at 05:26:24PM +0100, Dmitry Safonov wrote:
> +	if (@dupes) {
> +		printf(__("Patches specified several times: \n"));

Is this message translated?  (I don't know what __("<str>") does in
Perl.)  If it is, then ...

> @@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
>  	test_cmp expect actual
>  '
>  
> +test_expect_success $PREREQ 'ask confirmation for double-send' '
> +	clean_fake_sendmail &&
> +	echo y | \
> +		GIT_SEND_EMAIL_NOTTY=1 \
> +		git send-email --from=author@example.com \
> +			--to=nobody@example.com \
> +			--smtp-server="$(pwd)/fake.sendmail" \
> +			--validate \
> +			$patches $patches $patches \
> +			>stdout &&
> +	! grep "Patches specified several times: " stdout

... this here should be 'test_i18ngrep' instead of plain old 'grep'.


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] send-email: Ask if a patch should be sent twice
  2019-07-30 19:19 ` SZEDER Gábor
@ 2019-07-30 19:35   ` Junio C Hamano
  2019-07-30 20:26     ` Dmitry Safonov
  0 siblings, 1 reply; 4+ messages in thread
From: Junio C Hamano @ 2019-07-30 19:35 UTC (permalink / raw)
  To: SZEDER Gábor
  Cc: Dmitry Safonov, git, Ævar Arnfjörð Bjarmason,
	Dmitry Safonov, Andrei Vagin

SZEDER Gábor <szeder.dev@gmail.com> writes:

> On Tue, Jul 30, 2019 at 05:26:24PM +0100, Dmitry Safonov wrote:
>> +	if (@dupes) {
>> +		printf(__("Patches specified several times: \n"));
>
> Is this message translated?  (I don't know what __("<str>") does in
> Perl.)  If it is, then ...

That's not "in Perl" per-se, but what our own Git::I18N gives us.

>> +test_expect_success $PREREQ 'ask confirmation for double-send' '
>> +	clean_fake_sendmail &&
>> +	echo y | \
>> +		GIT_SEND_EMAIL_NOTTY=1 \
>> +		git send-email --from=author@example.com \
>> +			--to=nobody@example.com \
>> +			--smtp-server="$(pwd)/fake.sendmail" \
>> +			--validate \
>> +			$patches $patches $patches \
>> +			>stdout &&
>> +	! grep "Patches specified several times: " stdout
>
> ... this here should be 'test_i18ngrep' instead of plain old 'grep'.

Yup.  Thanks for carefully reading the patch(es), as always.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCHv2] send-email: Ask if a patch should be sent twice
  2019-07-30 19:35   ` Junio C Hamano
@ 2019-07-30 20:26     ` Dmitry Safonov
  0 siblings, 0 replies; 4+ messages in thread
From: Dmitry Safonov @ 2019-07-30 20:26 UTC (permalink / raw)
  To: Junio C Hamano, SZEDER Gábor
  Cc: git, Ævar Arnfjörð Bjarmason, Dmitry Safonov,
	Andrei Vagin

On 7/30/19 8:35 PM, Junio C Hamano wrote:
> SZEDER Gábor <szeder.dev@gmail.com> writes:
> 
>> On Tue, Jul 30, 2019 at 05:26:24PM +0100, Dmitry Safonov wrote:
>>> +	if (@dupes) {
>>> +		printf(__("Patches specified several times: \n"));
>>
>> Is this message translated?  (I don't know what __("<str>") does in
>> Perl.)  If it is, then ...
> 
> That's not "in Perl" per-se, but what our own Git::I18N gives us.
> 
>>> +test_expect_success $PREREQ 'ask confirmation for double-send' '
>>> +	clean_fake_sendmail &&
>>> +	echo y | \
>>> +		GIT_SEND_EMAIL_NOTTY=1 \
>>> +		git send-email --from=author@example.com \
>>> +			--to=nobody@example.com \
>>> +			--smtp-server="$(pwd)/fake.sendmail" \
>>> +			--validate \
>>> +			$patches $patches $patches \
>>> +			>stdout &&
>>> +	! grep "Patches specified several times: " stdout
>>
>> ... this here should be 'test_i18ngrep' instead of plain old 'grep'.
> 
> Yup.  Thanks for carefully reading the patch(es), as always.

Thanks for spotting, will fix in v3.

-- 
          Dmitry

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2019-07-30 20:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-07-30 16:26 [PATCHv2] send-email: Ask if a patch should be sent twice Dmitry Safonov
2019-07-30 19:19 ` SZEDER Gábor
2019-07-30 19:35   ` Junio C Hamano
2019-07-30 20:26     ` Dmitry Safonov

Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).