Skip to contentSkip to conversation

send-email: Ask if a patch should be sent twice

PATCH Superseded Dmitry Safonov 3 participants 4 messages Jul 30, 2019 Documentation

v2 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 send-email: Ask if a patch should be sent twice

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 [email protected] /tmp/timens/
	    --cc 'Dmitry Safonov <[email protected]>' /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.

---
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(+)
Documentation/git-send-email.txt +2 -0
index d93e5d0f58f0..0441bb1b5d3b 100644
@@ -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,
git-send-email.perl +14 -0
index 5f92c89c1c1b..c1638d06f81d 100755
@@ -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) {
t/t9001-send-email.sh +15 -0
index 997f90b42b3e..77df51519d6e 100755
@@ -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 [email protected] \
+			[email protected] \
+			--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"
Signature · 1 line
2.22.0
#1 lore raw

git-send-email.perl sub is_format_patch_arg { · line 702

Quoted 2 lines · Dmitry Safonov
git-send-email.perl +2 -0
+	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 ...

Quoted 5 lines
t/t9001-send-email.sh +1 -0
@@ -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' '

t/t9001-send-email.sh test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' · line 604

Quoted 10 lines
t/t9001-send-email.sh +10 -0
+	clean_fake_sendmail &&
+	echo y | \
+		GIT_SEND_EMAIL_NOTTY=1 \
+		git send-email [email protected] \
+			[email protected] \
+			--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'.

#2 lore raw
Quoted 6 lines · SZEDER Gábor

git-send-email.perl sub is_format_patch_arg { · line 702

Quoted 2 lines · Dmitry Safonov
git-send-email.perl +2 -0
+	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.

Quoted 5 lines
Quoted 5 lines
t/t9001-send-email.sh +5 -0
+test_expect_success $PREREQ 'ask confirmation for double-send' '
+	clean_fake_sendmail &&
+	echo y | \
+		GIT_SEND_EMAIL_NOTTY=1 \
+		git send-email [email protected] \
Quoted 8 lines

t/t9001-send-email.sh test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' · line 604

Quoted 6 lines
t/t9001-send-email.sh +6 -0
+			[email protected] \
+			--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.

#3 lore raw
Quoted 25 lines · Junio C Hamano
Quoted 6 lines · SZEDER Gábor

git-send-email.perl sub is_format_patch_arg { · line 702

Quoted 2 lines · Dmitry Safonov
git-send-email.perl +2 -0
+	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.

Quoted 5 lines
Quoted 5 lines
t/t9001-send-email.sh +5 -0
+test_expect_success $PREREQ 'ask confirmation for double-send' '
+	clean_fake_sendmail &&
+	echo y | \
+		GIT_SEND_EMAIL_NOTTY=1 \
+		git send-email [email protected] \
Quoted 8 lines

t/t9001-send-email.sh test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' ' · line 604

Quoted 6 lines
t/t9001-send-email.sh +6 -0
+			[email protected] \
+			--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'.

Quoted 1 line

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

Thanks for spotting, will fix in v3.

Signature · 1 line
          Dmitry