]> git.ipfire.org Git - thirdparty/git.git/commitdiff
send-email: fix missing error message regression
authorÆvar Arnfjörð Bjarmason <avarab@gmail.com>
Mon, 24 May 2021 23:14:24 +0000 (01:14 +0200)
committerJunio C Hamano <gitster@pobox.com>
Tue, 25 May 2021 00:52:42 +0000 (09:52 +0900)
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>
git-send-email.perl
t/t9001-send-email.sh

index 175da07d9469d14584050f3fe5706b5e7db0ec0b..170f42fe210fa7156d1b97031b78cdf084b6abc0 100755 (executable)
@@ -219,8 +219,18 @@ sub system_or_msg {
        my $exit_code = $? >> 8;
        return unless $signalled or $exit_code;
 
+       my @sprintf_args = ($args->[0], $exit_code);
+       if (defined $msg) {
+               # Quiet the 'redundant' warning category, except we
+               # need to support down to Perl 5.8, so we can't do a
+               # "no warnings 'redundant'", since that category was
+               # introduced in perl 5.22, and asking for it will die
+               # on older perls.
+               no warnings;
+               return sprintf($msg, @sprintf_args);
+       }
        return sprintf(__("fatal: command '%s' died with exit code %d"),
-                      $args->[0], $exit_code);
+                      @sprintf_args);
 }
 
 sub system_or_die {
index 65b303537199d32de535f17b483b3eba11eed4b6..2acf389837c4efd561e271696681c85ad05f6c40 100755 (executable)
@@ -644,14 +644,33 @@ test_expect_success $PREREQ 'In-Reply-To with --chain-reply-to' '
        test_cmp expect actual
 '
 
+test_set_editor "$(pwd)/fake-editor"
+
+test_expect_success $PREREQ 'setup erroring fake editor' '
+       write_script fake-editor <<-\EOF
+       echo >&2 "I am about to error"
+       exit 1
+       EOF
+'
+
+test_expect_success $PREREQ 'fake editor dies with error' '
+       clean_fake_sendmail &&
+       test_must_fail git send-email \
+               --compose --subject foo \
+               --from="Example <nobody@example.com>" \
+               --to=nobody@example.com \
+               --smtp-server="$(pwd)/fake.sendmail" \
+               $patches 2>err &&
+       grep "I am about to error" err &&
+       grep "the editor exited uncleanly, aborting everything" err
+'
+
 test_expect_success $PREREQ 'setup fake editor' '
        write_script fake-editor <<-\EOF
        echo fake edit >>"$1"
        EOF
 '
 
-test_set_editor "$(pwd)/fake-editor"
-
 test_expect_success $PREREQ '--compose works' '
        clean_fake_sendmail &&
        git send-email \