]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: rename --cover-letter-format option
authorMirko Faina <mroik@delayed.space>
Mon, 23 Mar 2026 16:57:30 +0000 (17:57 +0100)
committerJunio C Hamano <gitster@pobox.com>
Mon, 23 Mar 2026 20:06:58 +0000 (13:06 -0700)
To align the name of the configuration variable and the name of the
command line option, either one should change name. By changing the name
of the option we get the added benefit of having --cover-<TAB> expand to
--cover-letter without ambiguity.

If the user gives the --cover-letter-format option it would be
reasonable to expect that the user wants to generate the cover letter
despite not giving --cover-letter.

Rename --cover-letter-format to --commit-list-format and make it imply
--cover-letter unless --no-cover-letter is given.

Signed-off-by: Mirko Faina <mroik@delayed.space>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/git-format-patch.adoc
builtin/log.c
t/t4014-format-patch.sh
t/t9902-completion.sh

index 31fa4923354b388ba0babb38bdfcbd1b20ac8b81..45ca72e6703cffb17bc02902d60d7b35d801e030 100644 (file)
@@ -24,7 +24,7 @@ SYNOPSIS
                   [(--reroll-count|-v) <n>]
                   [--to=<email>] [--cc=<email>]
                   [--[no-]cover-letter] [--quiet]
-                  [--cover-letter-format=<format-spec>]
+                  [--commit-list-format=<format-spec>]
                   [--[no-]encode-email-headers]
                   [--no-notes | --notes[=<ref>]]
                   [--interdiff=<previous>]
@@ -323,16 +323,15 @@ feeding the result to `git send-email`.
        containing the branch description, shortlog and the overall diffstat.  You can
        fill in a description in the file before sending it out.
 
---cover-letter-format=<format-spec>::
-       Specify the format in which to generate the commit list of the
-       patch series. This option is available if the user wants to use
-       an alternative to the default `shortlog` format. The accepted
-       values for format-spec are "shortlog" or a format string
-       prefixed with `log:`.
+--commit-list-format=<format-spec>::
+       Specify the format in which to generate the commit list of the patch
+       series. The accepted values for format-spec are "shortlog" or a format
+       string prefixed with `log:`.
        e.g. `log: %s (%an)`
-       If defined, defaults to the `format.commitListFormat` configuration
+       If not given, defaults to the `format.commitListFormat` configuration
        variable.
-       This option is relevant only if a cover letter is generated.
+       This option implies the use of `--cover-letter` unless
+       `--no-cover-letter` is given.
 
 --encode-email-headers::
 --no-encode-email-headers::
index 997bdd608e0c1174b7652955dfafab51d16d2262..a7f129d583f0bd944d4722e9ec8a570d06cefab3 100644 (file)
@@ -2014,7 +2014,7 @@ int cmd_format_patch(int argc,
                            N_("print patches to standard out")),
                OPT_BOOL(0, "cover-letter", &cover_letter,
                            N_("generate a cover letter")),
-               OPT_STRING(0, "cover-letter-format", &cover_letter_fmt, N_("format-spec"),
+               OPT_STRING(0, "commit-list-format", &cover_letter_fmt, N_("format-spec"),
                            N_("format spec used for the commit list in the cover letter")),
                OPT_BOOL(0, "numbered-files", &just_numbers,
                            N_("use simple number sequence for output file names")),
@@ -2358,6 +2358,8 @@ int cmd_format_patch(int argc,
                cover_letter_fmt = cfg.fmt_cover_letter_commit_list;
                if (!cover_letter_fmt)
                        cover_letter_fmt = "shortlog";
+       } else if (cover_letter == -1) {
+               cover_letter = 1;
        }
 
        if (cover_letter == -1) {
index 7c67bdf92267f6969e646bcba2ce0489a01229a4..d2a775f78d2cf2688934e96b193a01e8d942b91c 100755 (executable)
@@ -383,49 +383,50 @@ test_expect_success 'filename limit applies only to basename' '
 test_expect_success 'cover letter with subject, author and count' '
        rm -rf patches &&
        test_when_finished "git reset --hard HEAD~1" &&
-       test_when_finished "rm -rf patches result test_file" &&
+       test_when_finished "rm -rf patches test_file" &&
        touch test_file &&
        git add test_file &&
        git commit -m "This is a subject" &&
-       git format-patch --cover-letter \
-       --cover-letter-format="log:[%(count)/%(total)] %s (%an)" -o patches HEAD~1 &&
-       grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch >result &&
-       test_line_count = 1 result
+       git format-patch --commit-list-format="log:[%(count)/%(total)] %s (%an)" \
+       -o patches HEAD~1 &&
+       test_grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch
 '
 
-test_expected_success 'cover letter with author and count' '
+test_expect_success 'cover letter with author and count' '
        test_when_finished "git reset --hard HEAD~1" &&
-       test_when_finished "rm -rf patches result test_file" &&
+       test_when_finished "rm -rf patches test_file" &&
        touch test_file &&
        git add test_file &&
        git commit -m "This is a subject" &&
-       git format-patch --cover-letter \
-       --cover-letter-format="log:[%(count)/%(total)] %an" -o patches HEAD~1 &&
-       grep "^\[1/1\] A U Thor$" patches/0000-cover-letter.patch >result &&
-       test_line_count = 1 result
+       git format-patch --commit-list-format="log:[%(count)/%(total)] %an" \
+       -o patches HEAD~1 &&
+       test_grep "^\[1/1\] A U Thor$" patches/0000-cover-letter.patch
 '
 
 test_expect_success 'cover letter shortlog' '
        test_when_finished "git reset --hard HEAD~1" &&
-       test_when_finished "rm -rf patches result test_file" &&
+       test_when_finished "rm -rf expect patches result test_file" &&
+       cat >expect <<-"EOF" &&
+       A U Thor (1):
+         This is a subject
+       EOF
        touch test_file &&
        git add test_file &&
        git commit -m "This is a subject" &&
-       git format-patch --cover-letter --cover-letter-format=shortlog \
-       -o patches HEAD~1 &&
-       sed -n -e "/^A U Thor/p;" patches/0000-cover-letter.patch >result &&
-       test_line_count = 1 result
+       git format-patch --commit-list-format=shortlog -o patches HEAD~1 &&
+       grep -E -A 1 "^A U Thor \([[:digit:]]+\):$" patches/0000-cover-letter.patch >result &&
+       cat result &&
+       test_cmp expect result
 '
 
-test_expect_success 'cover letter no format' '
+test_expect_success 'no cover letter but with format specified' '
        test_when_finished "git reset --hard HEAD~1" &&
        test_when_finished "rm -rf patches result test_file" &&
        touch test_file &&
        git add test_file &&
        git commit -m "This is a subject" &&
-       git format-patch --cover-letter -o patches HEAD~1 &&
-       sed -n -e "/^A U Thor/p;" patches/0000-cover-letter.patch >result &&
-       test_line_count = 1 result
+       git format-patch --no-cover-letter --commit-list-format="[%(count)] %s" -o patches HEAD~1 &&
+       test_path_is_missing patches/0000-cover-letter.patch
 '
 
 test_expect_success 'cover letter config with count, subject and author' '
index 35e20b535114997235193720512a2894b2a4250f..2f9a597ec7f4939105562c7553ce00a038342eb8 100755 (executable)
@@ -2775,7 +2775,6 @@ test_expect_success PERL 'send-email' '
        test_completion "git send-email --cov" <<-\EOF &&
        --cover-from-description=Z
        --cover-letter Z
-       --cover-letter-format=Z
        EOF
        test_completion "git send-email --val" <<-\EOF &&
        --validate Z