send-email: fix missing error message regression

Fix a regression with the "the editor exited uncleanly, aborting everything" error message going missing after my d21616c0394 (git-send-email: refactor duplicate $? checks into a function, 2021-04-06). I introduced a $msg variable, but did not actually use it. This caused us to miss the optional error message supplied by the "do_edit" codepath. Fix that, and add tests to check that this works. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed May 25, 2021 at 01:14 UTC 5b719b7552b9eca486a3a6507e9397572d16481d
2 files changed +32 -3
git-send-email.perl
+11 -1
@@ -219,8 +219,18 @@ sub system_or_msg {
219 my $exit_code = $? >> 8;
220 return unless $signalled or $exit_code;
221
222 + my @sprintf_args = ($args->[0], $exit_code);
223 + if (defined $msg) {
224 + # Quiet the 'redundant' warning category, except we
225 + # need to support down to Perl 5.8, so we can't do a
226 + # "no warnings 'redundant'", since that category was
227 + # introduced in perl 5.22, and asking for it will die
228 + # on older perls.
229 + no warnings;
230 + return sprintf($msg, @sprintf_args);
231 + }
232 return sprintf(__("fatal: command '%s' died with exit code %d"),
223 - $args->[0], $exit_code);
233 + @sprintf_args);
234 }
235
236 sub system_or_die {
t/t9001-send-email.sh
+21 -2
@@ -644,14 +644,33 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
644 test_cmp expect actual
645 '
646
647 +test_set_editor "$(pwd)/fake-editor"
648 +
649 +test_expect_success $PREREQ 'setup erroring fake editor' '
650 + write_script fake-editor <<-\EOF
651 + echo >&2 "I am about to error"
652 + exit 1
653 + EOF
654 +'
655 +
656 +test_expect_success $PREREQ 'fake editor dies with error' '
657 + clean_fake_sendmail &&
658 + test_must_fail git send-email \
659 + --compose --subject foo \
660 + --from="Example <nobody@example.com>" \
661 + --to=nobody@example.com \
662 + --smtp-server="$(pwd)/fake.sendmail" \
663 + $patches 2>err &&
664 + grep "I am about to error" err &&
665 + grep "the editor exited uncleanly, aborting everything" err
666 +'
667 +
668 test_expect_success $PREREQ 'setup fake editor' '
669 write_script fake-editor <<-\EOF
670 echo fake edit >>"$1"
671 EOF
672 '
673
653 -test_set_editor "$(pwd)/fake-editor"
654 -
674 test_expect_success $PREREQ '--compose works' '
675 clean_fake_sendmail &&
676 git send-email \