]> git.ipfire.org Git - thirdparty/git.git/commitdiff
fast-export: check for unsupported signing modes earlier
authorJustin Tobler <jltobler@gmail.com>
Thu, 26 Mar 2026 19:14:10 +0000 (14:14 -0500)
committerJunio C Hamano <gitster@pobox.com>
Thu, 26 Mar 2026 19:42:57 +0000 (12:42 -0700)
The '--signed-{commits,tags}' options for git-fast-export(1) support
only a subset of the modes accepted by git-fast-import(1). Unsupported
modes such as 'strip-if-invalid' and 'sign-if-invalid' are accepted
during option parsing, but cause the command to die later when a signed
object is encountered.

Instead, reject unsupported signing modes immediately after parsing the
option. This treats them the same as other unknown modes and avoids
deferring the error until object processing. This also removes
duplicated checks in commit/tag handling code.

Signed-off-by: Justin Tobler <jltobler@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/fast-export.c

index 13621b0d6a1552cf14cb14eb22ee41147c5cd722..a30fb90b6e0e96d2127bfba9a65cf39d37d6a9ba 100644 (file)
@@ -64,7 +64,8 @@ static int parse_opt_sign_mode(const struct option *opt,
        if (unset)
                return 0;
 
-       if (parse_sign_mode(arg, val, NULL))
+       if (parse_sign_mode(arg, val, NULL) || (*val == SIGN_STRIP_IF_INVALID) ||
+           (*val == SIGN_SIGN_IF_INVALID))
                return error(_("unknown %s mode: %s"), opt->long_name, arg);
 
        return 0;
@@ -822,12 +823,6 @@ static void handle_commit(struct commit *commit, struct rev_info *rev,
                        die(_("encountered signed commit %s; use "
                              "--signed-commits=<mode> to handle it"),
                            oid_to_hex(&commit->object.oid));
-               case SIGN_STRIP_IF_INVALID:
-                       die(_("'strip-if-invalid' is not a valid mode for "
-                             "git fast-export with --signed-commits=<mode>"));
-               case SIGN_SIGN_IF_INVALID:
-                       die(_("'sign-if-invalid' is not a valid mode for "
-                             "git fast-export with --signed-commits=<mode>"));
                default:
                        BUG("invalid signed_commit_mode value %d", signed_commit_mode);
                }
@@ -970,12 +965,6 @@ static void handle_tag(const char *name, struct tag *tag)
                                die(_("encountered signed tag %s; use "
                                      "--signed-tags=<mode> to handle it"),
                                    oid_to_hex(&tag->object.oid));
-                       case SIGN_STRIP_IF_INVALID:
-                               die(_("'strip-if-invalid' is not a valid mode for "
-                                     "git fast-export with --signed-tags=<mode>"));
-                       case SIGN_SIGN_IF_INVALID:
-                               die(_("'sign-if-invalid' is not a valid mode for "
-                                     "git fast-export with --signed-tags=<mode>"));
                        default:
                                BUG("invalid signed_commit_mode value %d", signed_commit_mode);
                        }