]> git.ipfire.org Git - thirdparty/git.git/commitdiff
gpg: do show gpg's error message upon failure
authorJohannes Schindelin <johannes.schindelin@gmx.de>
Wed, 15 Feb 2023 05:58:34 +0000 (05:58 +0000)
committerJunio C Hamano <gitster@pobox.com>
Wed, 15 Feb 2023 16:55:24 +0000 (08:55 -0800)
There are few things more frustrating when signing a commit fails than
reading a terse "error: gpg failed to sign the data" message followed by
the unsurprising "fatal: failed to write commit object" message.

In many cases where signing a commit or tag fails, `gpg` actually said
something helpful, on its stderr, and Git even consumed that, but then
keeps mum about it.

Teach Git to stop withholding that rather important information.

Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
gpg-interface.c
t/t7510-signed-commit.sh

index f877a1ea56460de8e7c831b58ab4cfbda837a304..917144f32eaedf09e526768c086f0f935a146698 100644 (file)
@@ -977,9 +977,13 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
                        break; /* found */
        }
        ret |= !cp;
+       if (ret) {
+               error(_("gpg failed to sign the data:\n%s"),
+                     gpg_status.len ? gpg_status.buf : "(no gpg output)");
+               strbuf_release(&gpg_status);
+               return -1;
+       }
        strbuf_release(&gpg_status);
-       if (ret)
-               return error(_("gpg failed to sign the data"));
 
        /* Strip CR from the line endings, in case we are on Windows. */
        remove_cr_after(signature, bottom);
index 24dc3ef0a21980ea822729d57404b5cf258b8b0e..1d416831191461af93b8e61fdddb9950111d273d 100755 (executable)
@@ -399,6 +399,10 @@ test_expect_success 'custom `gpg.program`' '
 
        case "$1" in
        -bsau)
+               test -z "$LET_GPG_PROGRAM_FAIL" || {
+                       echo "zOMG signing failed!" >&2
+                       exit 1
+               }
                cat >sign.file
                echo "[GNUPG:] SIG_CREATED $args" >&2
                echo "-----BEGIN PGP MESSAGE-----"
@@ -420,7 +424,11 @@ test_expect_success 'custom `gpg.program`' '
        git commit -S --allow-empty -m signed-commit &&
        test_path_exists sign.file &&
        git show --show-signature &&
-       test_path_exists verify.file
+       test_path_exists verify.file &&
+
+       test_must_fail env LET_GPG_PROGRAM_FAIL=1 \
+       git commit -S --allow-empty -m must-fail 2>err &&
+       grep zOMG err
 '
 
 test_done