Skip to content

Commit ad6b320

Browse files
dschogitster
authored andcommitted
gpg: do show gpg's error message upon failure
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8300d15 commit ad6b320

File tree

2 files changed

+15
-3
lines changed

2 files changed

+15
-3
lines changed

gpg-interface.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -977,9 +977,13 @@ static int sign_buffer_gpg(struct strbuf *buffer, struct strbuf *signature,
977977
break; /* found */
978978
}
979979
ret |= !cp;
980+
if (ret) {
981+
error(_("gpg failed to sign the data:\n%s"),
982+
gpg_status.len ? gpg_status.buf : "(no gpg output)");
983+
strbuf_release(&gpg_status);
984+
return -1;
985+
}
980986
strbuf_release(&gpg_status);
981-
if (ret)
982-
return error(_("gpg failed to sign the data"));
983987

984988
/* Strip CR from the line endings, in case we are on Windows. */
985989
remove_cr_after(signature, bottom);

t/t7510-signed-commit.sh

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,10 @@ test_expect_success 'custom `gpg.program`' '
399399
400400
case "$1" in
401401
-bsau)
402+
test -z "$LET_GPG_PROGRAM_FAIL" || {
403+
echo "zOMG signing failed!" >&2
404+
exit 1
405+
}
402406
cat >sign.file
403407
echo "[GNUPG:] SIG_CREATED $args" >&2
404408
echo "-----BEGIN PGP MESSAGE-----"
@@ -420,7 +424,11 @@ test_expect_success 'custom `gpg.program`' '
420424
git commit -S --allow-empty -m signed-commit &&
421425
test_path_exists sign.file &&
422426
git show --show-signature &&
423-
test_path_exists verify.file
427+
test_path_exists verify.file &&
428+
429+
test_must_fail env LET_GPG_PROGRAM_FAIL=1 \
430+
git commit -S --allow-empty -m must-fail 2>err &&
431+
grep zOMG err
424432
'
425433

426434
test_done

0 commit comments

Comments
 (0)