fast-import: add 'abort-if-invalid' mode to '--signed-tags=<mode>'
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>
Justin Tobler committed
Mar 26, 2026 at 14:14 UTC
ddd7c7ab12a25850e96f550567ef06fb9bea0cc0
2 files changed
+13
-4
builtin/fast-import.c
+4
-3
@@ -3109,6 +3109,9 @@ static void handle_tag_signature_if_invalid(struct strbuf *buf,
3109
if (!check_signature(&sigc, signature.buf, signature.len))
3110
goto out;
3111
3112
+ if (signed_tag_mode == SIGN_ABORT_IF_INVALID)
3113
+ die(_("aborting due to invalid signature"));
3114
+
3115
strbuf_setlen(msg, sig_offset);
3116
3117
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
3159
/* Truncate the buffer to remove the signature */
3160
strbuf_setlen(msg, sig_offset);
3161
break;
3162
+ case SIGN_ABORT_IF_INVALID:
3163
case SIGN_SIGN_IF_INVALID:
3164
case SIGN_STRIP_IF_INVALID:
3165
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
3169
case SIGN_ABORT:
3170
die(_("encountered signed tag; use "
3171
"--signed-tags=<mode> to handle it"));
3168
- case SIGN_ABORT_IF_INVALID:
3169
- die(_("'abort-if-invalid' is not a valid mode for "
3170
- "git fast-import with --signed-tags=<mode>"));
3172
default:
3173
BUG("invalid signed_tag_mode value %d from tag '%s'",
3174
signed_tag_mode, name);
t/t9306-fast-import-signed-tags.sh
+9
-1
@@ -77,7 +77,7 @@ test_expect_success GPGSSH 'import SSH signed tag with --signed-tags=strip' '
77
test_grep ! "SSH SIGNATURE" out
78
'
79
80
-for mode in strip-if-invalid sign-if-invalid
80
+for mode in strip-if-invalid sign-if-invalid abort-if-invalid
81
do
82
test_expect_success GPG "import tag with no signature with --signed-tags=$mode" '
83
test_when_finished rm -rf import &&
@@ -112,6 +112,14 @@ do
112
# `data <length>` command would have to be changed too.
113
sed "s/OpenPGP signed tag/OpenPGP forged tag/" output >modified &&
114
115
+ if test "$mode" = abort-if-invalid
116
+ then
117
+ test_must_fail git -C import fast-import --quiet \
118
+ --signed-tags=$mode <modified >log 2>&1 &&
119
+ test_grep "aborting due to invalid signature" log &&
120
+ return 0
121
+ fi &&
122
+
123
git -C import fast-import --quiet --signed-tags=$mode <modified >log 2>&1 &&
124
125
IMPORTED=$(git -C import rev-parse --verify refs/tags/openpgp-signed) &&