]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-import: add 'abort-if-invalid' mode to '--signed-tags=<mode>'
authorJustin Tobler <jltobler@gmail.com>
Thu, 26 Mar 2026 19:14:14 +0000 (14:14 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2026 19:42:58 +0000 (12:42 -0700)
In git-fast-import(1), the 'abort-if-invalid' mode for the
'--signed-commits' option verifies commit signatures during import and
aborts the entire operation when verification fails. Extend the same
behavior to signed tag objects by introducing an 'abort-if-invalid' mode
for the '--signed-tags' option.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-import.c
t/t9306-fast-import-signed-tags.sh

index 783e0e7ab47e89bd47b003e04554a17839f6c634..cd1181023d8444ef821d06781b9ea0029e184b0a 100644 (file)
@@ -3109,6 +3109,9 @@ static void handle_tag_signature_if_invalid(struct strbuf *buf,
        if (!check_signature(&sigc, signature.buf, signature.len))
                goto out;
 
+       if (signed_tag_mode == SIGN_ABORT_IF_INVALID)
+               die(_("aborting due to invalid signature"));
+
        strbuf_setlen(msg, sig_offset);
 
        if (signed_tag_mode == SIGN_SIGN_IF_INVALID) {
@@ -3156,6 +3159,7 @@ static void handle_tag_signature(struct strbuf *buf, struct strbuf *msg, const c
                /* Truncate the buffer to remove the signature */
                strbuf_setlen(msg, sig_offset);
                break;
+       case SIGN_ABORT_IF_INVALID:
        case SIGN_SIGN_IF_INVALID:
        case SIGN_STRIP_IF_INVALID:
                handle_tag_signature_if_invalid(buf, msg, sig_offset);
@@ -3165,9 +3169,6 @@ static void handle_tag_signature(struct strbuf *buf, struct strbuf *msg, const c
        case SIGN_ABORT:
                die(_("encountered signed tag; use "
                      "--signed-tags=<mode> to handle it"));
-       case SIGN_ABORT_IF_INVALID:
-               die(_("'abort-if-invalid' is not a valid mode for "
-                     "git fast-import with --signed-tags=<mode>"));
        default:
                BUG("invalid signed_tag_mode value %d from tag '%s'",
                    signed_tag_mode, name);
index bb4c8008efe5b8e962097c23bbd839e96f535266..ec2b241cdb82ece1fe0af5f52f4339a9514a4ada 100755 (executable)
@@ -77,7 +77,7 @@ test_expect_success GPGSSH 'import SSH signed tag with --signed-tags=strip' '
        test_grep ! "SSH SIGNATURE" out
 '
 
-for mode in strip-if-invalid sign-if-invalid
+for mode in strip-if-invalid sign-if-invalid abort-if-invalid
 do
        test_expect_success GPG "import tag with no signature with --signed-tags=$mode" '
                test_when_finished rm -rf import &&
@@ -112,6 +112,14 @@ do
                # `data <length>` command would have to be changed too.
                sed "s/OpenPGP signed tag/OpenPGP forged tag/" output >modified &&
 
+               if test "$mode" = abort-if-invalid
+               then
+                       test_must_fail git -C import fast-import --quiet \
+                               --signed-tags=$mode <modified >log 2>&1 &&
+                       test_grep "aborting due to invalid signature" log &&
+                       return 0
+               fi &&
+
                git -C import fast-import --quiet --signed-tags=$mode <modified >log 2>&1 &&
 
                IMPORTED=$(git -C import rev-parse --verify refs/tags/openpgp-signed) &&