{"thread":{"id":"51560","subject":"[PATCHv4] send-email: Ask if a patch should be sent twice","startedAt":"2019-07-30T21:24:59Z","lastAt":"2019-07-30T21:24:59Z","messageCount":1,"participants":["Dmitry Safonov"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"379616","messageId":"20190730212453.28301-1-dima@arista.com","threadId":"51560","inReplyTo":null,"subject":"[PATCHv4] send-email: Ask if a patch should be sent twice","fromName":"Dmitry Safonov","fromEmail":"dima@arista.com","sentAt":"2019-07-30T21:24:53Z","receivedAt":"2019-07-30T21:24:59Z","isPatch":false,"sender":{"key":"dima@arista.com","avatar":null},"body":"I was almost certain that git won't let me send the same patch twice,\nbut today I've managed to double-send a directory by a mistake:\n\tgit send-email --to linux-kernel@vger.kernel.org /tmp/timens/\n\t    --cc 'Dmitry Safonov <0x7f454c46@gmail.com>' /tmp/timens/`\n\n[I haven't noticed that I put the directory twice ^^]\n\nPrevent this shipwreck from happening again by asking if a patch\nis sent multiple times on purpose.\n\nlink: https://lkml.kernel.org/r/4d53ebc7-d5b2-346e-c383-606401d19d3a@gmail.com\nCc: Andrei Vagin <avagin@openvz.org>\nSuggested-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com>\nSigned-off-by: Dmitry Safonov <dima@arista.com>\n---\nv4: Don't fail the test with GIT_TEST_GETTEXT_POISON=true\nv3: Use `test_i18ngrep` instead of plain `grep`\nv2: Moved the check under --validate,\n    fixed tests,\n    added a new test,\n    updated documentation for --validate\n\n Documentation/git-send-email.txt |  2 ++\n git-send-email.perl              | 14 ++++++++++++++\n t/t9001-send-email.sh            | 15 +++++++++++++++\n 3 files changed, 31 insertions(+)\n\ndiff --git a/Documentation/git-send-email.txt b/Documentation/git-send-email.txt\nindex d93e5d0f58f0..0441bb1b5d3b 100644\n--- a/Documentation/git-send-email.txt\n+++ b/Documentation/git-send-email.txt\n@@ -421,6 +421,8 @@ have been specified, in which case default to 'compose'.\n \t\t\t('auto', 'base64', or 'quoted-printable') is used;\n \t\t\tthis is due to SMTP limits as described by\n \t\t\thttp://www.ietf.org/rfc/rfc5322.txt.\n+\t\t*\tAsk confirmation before sending patches multiple times\n+\t\t\tif the supplied patches set overlaps.\n --\n +\n Default is the value of `sendemail.validate`; if this is not set,\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 5f92c89c1c1b..c1638d06f81d 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -688,6 +688,9 @@ sub is_format_patch_arg {\n @files = handle_backup_files(@files);\n \n if ($validate) {\n+\tmy %seen;\n+\tmy @dupes = grep { $seen{$_}++ } @files;\n+\n \tforeach my $f (@files) {\n \t\tunless (-p $f) {\n \t\t\tmy $error = validate_patch($f, $target_xfer_encoding);\n@@ -695,6 +698,17 @@ sub is_format_patch_arg {\n \t\t\t\t\t\t  $f, $error);\n \t\t}\n \t}\n+\tif (@dupes) {\n+\t\tprintf(__(\"Patches specified several times: \\n\"));\n+\t\tprintf(__(\"%s \\n\" x @dupes), @dupes);\n+\t\t$_ = ask(__(\"Do you want to send those patches several times? Y/n \"),\n+\t\t\tdefault => \"y\",\n+\t\t\tvalid_re => qr/^(?:yes|y|no|n)/i);\n+\t\tif (/^n/i) {\n+\t\t\tcleanup_compose_files();\n+\t\t\texit(0);\n+\t\t}\n+\t}\n }\n \n if (@files) {\ndiff --git a/t/t9001-send-email.sh b/t/t9001-send-email.sh\nindex 997f90b42b3e..8954f8e38d90 100755\n--- a/t/t9001-send-email.sh\n+++ b/t/t9001-send-email.sh\n@@ -555,6 +555,7 @@ test_expect_success $PREREQ 'In-Reply-To without --chain-reply-to' '\n \t\t--no-chain-reply-to \\\n \t\t--in-reply-to=\"$(cat expect)\" \\\n \t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\t--no-validate \\\n \t\t$patches $patches $patches \\\n \t\t2>errors &&\n \t# The first message is a reply to --in-reply-to\n@@ -577,6 +578,7 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '\n \t\t--chain-reply-to \\\n \t\t--in-reply-to=\"$(cat expect)\" \\\n \t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\t--no-validate \\\n \t\t$patches $patches $patches \\\n \t\t2>errors &&\n \tsed -n -e \"s/^In-Reply-To: *\\(.*\\)/\\1/p\" msgtxt1 >actual &&\n@@ -589,6 +591,19 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '\n \ttest_cmp expect actual\n '\n \n+test_expect_success $PREREQ 'ask confirmation for double-send' '\n+\tclean_fake_sendmail &&\n+\techo y | \\\n+\t\tGIT_SEND_EMAIL_NOTTY=1 \\\n+\t\tgit send-email --from=author@example.com \\\n+\t\t\t--to=nobody@example.com \\\n+\t\t\t--smtp-server=\"$(pwd)/fake.sendmail\" \\\n+\t\t\t--validate \\\n+\t\t\t$patches $patches $patches \\\n+\t\t\t>stdout &&\n+\ttest_i18ngrep ! \"Patches specified several times: \" stdout\n+'\n+\n test_expect_success $PREREQ 'setup fake editor' '\n \twrite_script fake-editor <<-\\EOF\n \techo fake edit >>\"$1\"\n-- \n2.22.0\n\n"}]}