format-patch: ensure that --rfc and -k are mutually exclusive

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>

Dragan Simic committed Apr 19, 2024 at 03:05 UTC cadcf58085cada6e781444cbdde6d4b0067ebe4c
2 files changed +24 -1
builtin/log.c
+3 -1
@@ -2044,8 +2044,10 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
2044 if (cover_from_description_arg)
2045 cover_from_description_mode = parse_cover_from_description(cover_from_description_arg);
2046
2047 - if (rfc)
2047 + if (rfc) {
2048 strbuf_insertstr(&sprefix, 0, "RFC ");
2049 + subject_prefix = 1;
2050 + }
2051
2052 if (reroll_count) {
2053 strbuf_addf(&sprefix, " v%s", reroll_count);
t/t4014-format-patch.sh
+21
@@ -1397,6 +1397,27 @@ test_expect_success '--rfc is argument order independent' '
1397 test_cmp expect actual
1398 '
1399
1400 +test_expect_success '--subject-prefix="<non-empty>" and -k cannot be used together' '
1401 + echo "fatal: options '\''--subject-prefix/--rfc'\'' and '\''-k'\'' cannot be used together" >expect.err &&
1402 + test_must_fail git format-patch -1 --stdout --subject-prefix="MYPREFIX" -k >actual.out 2>actual.err &&
1403 + test_must_be_empty actual.out &&
1404 + test_cmp expect.err actual.err
1405 +'
1406 +
1407 +test_expect_success '--subject-prefix="" and -k cannot be used together' '
1408 + echo "fatal: options '\''--subject-prefix/--rfc'\'' and '\''-k'\'' cannot be used together" >expect.err &&
1409 + test_must_fail git format-patch -1 --stdout --subject-prefix="" -k >actual.out 2>actual.err &&
1410 + test_must_be_empty actual.out &&
1411 + test_cmp expect.err actual.err
1412 +'
1413 +
1414 +test_expect_success '--rfc and -k cannot be used together' '
1415 + echo "fatal: options '\''--subject-prefix/--rfc'\'' and '\''-k'\'' cannot be used together" >expect.err &&
1416 + test_must_fail git format-patch -1 --stdout --rfc -k >actual.out 2>actual.err &&
1417 + test_must_be_empty actual.out &&
1418 + test_cmp expect.err actual.err
1419 +'
1420 +
1421 test_expect_success '--from=ident notices bogus ident' '
1422 test_must_fail git format-patch -1 --stdout --from=foo >patch
1423 '