format-patch: add preset for --commit-list-format
"git format-patch --commit-list-format" enables the user to make their own format for the commit list in the cover letter. It would be nice to have a ready to use format to replace shortlog. Teach make_cover_letter() the "modern" format preset. This new format is the same as: "log:[%(count)/%(total)] %s". Signed-off-by: Mirko Faina <mroik@delayed.space> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Mirko Faina committed
Mar 23, 2026 at 17:57 UTC
d022dc77ab81fcc005b9965e91f524d4a43e74b5
4 files changed
+21
-8
Documentation/config/format.adoc
+1
-1
@@ -104,7 +104,7 @@ format.coverLetter::
104
format.commitListFormat::
105
When the `--cover-letter-format` option is not given, `format-patch`
106
uses the value of this variable to decide how to format the title of
107
- each commit. Default to `shortlog`.
107
+ each commit. Defaults to `shortlog`.
108
109
format.outputDirectory::
110
Set a custom directory to store the resulting files instead of the
Documentation/git-format-patch.adoc
+2
-2
@@ -325,8 +325,8 @@ feeding the result to `git send-email`.
325
326
--commit-list-format=<format-spec>::
327
Specify the format in which to generate the commit list of the patch
328
- series. The accepted values for format-spec are "shortlog" or a format
329
- string prefixed with `log:`.
328
+ series. The accepted values for format-spec are `shortlog`, `modern` or a
329
+ format string prefixed with `log:`.
330
e.g. `log: %s (%an)`
331
If not given, defaults to the `format.commitListFormat` configuration
332
variable.
builtin/log.c
+3
@@ -1445,6 +1445,9 @@ static void make_cover_letter(struct rev_info *rev, int use_separate_file,
1445
generate_commit_list_cover(rev->diffopt.file, format, list, nr);
1446
else if (!strcmp(format, "shortlog"))
1447
generate_shortlog_cover_letter(&log, rev, list, nr);
1448
+ else if (!strcmp(format, "modern"))
1449
+ generate_commit_list_cover(rev->diffopt.file, "[%(count)/%(total)] %s",
1450
+ list, nr);
1451
else
1452
die(_("'%s' is not a valid format string"), format);
1453
t/t4014-format-patch.sh
+15
-5
@@ -392,18 +392,17 @@ test_expect_success 'cover letter with subject, author and count' '
392
test_grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch
393
'
394
395
-test_expect_success 'cover letter with author and count' '
395
+test_expect_success 'cover letter modern format' '
396
test_when_finished "git reset --hard HEAD~1" &&
397
test_when_finished "rm -rf patches test_file" &&
398
touch test_file &&
399
git add test_file &&
400
git commit -m "This is a subject" &&
401
- git format-patch --commit-list-format="log:[%(count)/%(total)] %an" \
402
- -o patches HEAD~1 &&
403
- test_grep "^\[1/1\] A U Thor$" patches/0000-cover-letter.patch
401
+ git format-patch --commit-list-format="modern" -o patches HEAD~1 &&
402
+ test_grep "^\[1/1\] This is a subject$" patches/0000-cover-letter.patch
403
'
404
406
-test_expect_success 'cover letter shortlog' '
405
+test_expect_success 'cover letter shortlog format' '
406
test_when_finished "git reset --hard HEAD~1" &&
407
test_when_finished "rm -rf expect patches result test_file" &&
408
cat >expect <<-"EOF" &&
@@ -451,6 +450,17 @@ test_expect_success 'cover letter config with count and author' '
450
test_line_count = 2 result
451
'
452
453
+test_expect_success 'cover letter config commitlistformat set to modern' '
454
+ test_when_finished "rm -rf patches result" &&
455
+ test_when_finished "git config unset format.coverletter" &&
456
+ test_when_finished "git config unset format.commitlistformat" &&
457
+ git config set format.coverletter true &&
458
+ git config set format.commitlistformat modern &&
459
+ git format-patch -o patches HEAD~2 &&
460
+ grep -E "^[[[:digit:]]+/[[:digit:]]+] .*$" patches/0000-cover-letter.patch >result &&
461
+ test_line_count = 2 result
462
+'
463
+
464
test_expect_success 'cover letter config commitlistformat set to shortlog' '
465
test_when_finished "rm -rf patches result" &&
466
test_when_finished "git config unset format.coverletter" &&