]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: ensure that --rfc and -k are mutually exclusive
authorDragan Simic <dsimic@manjaro.org>
Fri, 19 Apr 2024 01:05:30 +0000 (03:05 +0200)
committerJunio C Hamano <gitster@pobox.com>
Fri, 19 Apr 2024 15:40:57 +0000 (08:40 -0700)
Fix a bug that allows the "--rfc" and "-k" options to be specified together
when "git format-patch" is executed, which was introduced in the commit
e0d7db7423a9 ("format-patch: --rfc honors what --subject-prefix sets").

Add a couple of additional tests to t4014, to cover additional cases of
the mutual exclusivity between different "git format-patch" options.

Signed-off-by: Dragan Simic <dsimic@manjaro.org>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
builtin/log.c
t/t4014-format-patch.sh

index 75762b497d32162a46ff22ad88a87f393f063d05..f08b8b5086151af913dab2ce8c1c24baad7333a2 100644 (file)
@@ -2044,8 +2044,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
        if (cover_from_description_arg)
                cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
 
-       if (rfc)
+       if (rfc) {
                strbuf_insertstr(&sprefix, 0, "RFC ");
+               subject_prefix = 1;
+       }
 
        if (reroll_count) {
                strbuf_addf(&sprefix, " v%s", reroll_count);
index 9fa1f3bc7a56351c29c157fa2d73acd1d63ad619..bce17703da9a8c23565210e02cc5ffa0765a6865 100755 (executable)
@@ -1397,6 +1397,27 @@ test_expect_success '--rfc is argument order independent' '
        test_cmp expect actual
 '
 
+test_expect_success '--subject-prefix="<non-empty>" and -k cannot be used together' '
+       echo "fatal: options '\''--subject-prefix/--rfc'\'' and '\''-k'\'' cannot be used together" >expect.err &&
+       test_must_fail git format-patch -1 --stdout --subject-prefix="MYPREFIX" -k >actual.out 2>actual.err &&
+       test_must_be_empty actual.out &&
+       test_cmp expect.err actual.err
+'
+
+test_expect_success '--subject-prefix="" and -k cannot be used together' '
+       echo "fatal: options '\''--subject-prefix/--rfc'\'' and '\''-k'\'' cannot be used together" >expect.err &&
+       test_must_fail git format-patch -1 --stdout --subject-prefix="" -k >actual.out 2>actual.err &&
+       test_must_be_empty actual.out &&
+       test_cmp expect.err actual.err
+'
+
+test_expect_success '--rfc and -k cannot be used together' '
+       echo "fatal: options '\''--subject-prefix/--rfc'\'' and '\''-k'\'' cannot be used together" >expect.err &&
+       test_must_fail git format-patch -1 --stdout --rfc -k >actual.out 2>actual.err &&
+       test_must_be_empty actual.out &&
+       test_cmp expect.err actual.err
+'
+
 test_expect_success '--from=ident notices bogus ident' '
        test_must_fail git format-patch -1 --stdout --from=foo >patch
 '