Skip to content

Commit 38a227b

Browse files
committed
Merge branch 'js/gpg-errors'
Error messages given upon a signature verification failure used to discard the errors from underlying gpg program, which has been corrected. * js/gpg-errors: gpg: do show gpg's error message upon failure t7510: add a test case that does not need gpg
2 parents 9861932 + ad6b320 commit 38a227b

File tree

2 files changed

+50
-2
lines changed

2 files changed

+50
-2
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: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,4 +387,48 @@ test_expect_success GPG 'verify-commit verifies multiply signed commits' '
387387
! grep "BAD signature from" actual
388388
'
389389

390+
test_expect_success 'custom `gpg.program`' '
391+
write_script fake-gpg <<-\EOF &&
392+
args="$*"
393+
394+
# skip uninteresting options
395+
while case "$1" in
396+
--status-fd=*|--keyid-format=*) ;; # skip
397+
*) break;;
398+
esac; do shift; done
399+
400+
case "$1" in
401+
-bsau)
402+
test -z "$LET_GPG_PROGRAM_FAIL" || {
403+
echo "zOMG signing failed!" >&2
404+
exit 1
405+
}
406+
cat >sign.file
407+
echo "[GNUPG:] SIG_CREATED $args" >&2
408+
echo "-----BEGIN PGP MESSAGE-----"
409+
echo "$args"
410+
echo "-----END PGP MESSAGE-----"
411+
;;
412+
--verify)
413+
cat "$2" >verify.file
414+
exit 0
415+
;;
416+
*)
417+
echo "Unhandled args: $*" >&2
418+
exit 1
419+
;;
420+
esac
421+
EOF
422+
423+
test_config gpg.program "$(pwd)/fake-gpg" &&
424+
git commit -S --allow-empty -m signed-commit &&
425+
test_path_exists sign.file &&
426+
git show --show-signature &&
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
432+
'
433+
390434
test_done

0 commit comments

Comments
 (0)