Skip to content

Commit 67ea2ad

Browse files
Mroikgitster
authored andcommitted
format-patch: rename --cover-letter-format option
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>
1 parent 3482b42 commit 67ea2ad

4 files changed

Lines changed: 32 additions & 31 deletions

File tree

Documentation/git-format-patch.adoc

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ SYNOPSIS
2424
[(--reroll-count|-v) <n>]
2525
[--to=<email>] [--cc=<email>]
2626
[--[no-]cover-letter] [--quiet]
27-
[--cover-letter-format=<format-spec>]
27+
[--commit-list-format=<format-spec>]
2828
[--[no-]encode-email-headers]
2929
[--no-notes | --notes[=<ref>]]
3030
[--interdiff=<previous>]
@@ -323,16 +323,15 @@ feeding the result to `git send-email`.
323323
containing the branch description, shortlog and the overall diffstat. You can
324324
fill in a description in the file before sending it out.
325325
326-
--cover-letter-format=<format-spec>::
327-
Specify the format in which to generate the commit list of the
328-
patch series. This option is available if the user wants to use
329-
an alternative to the default `shortlog` format. The accepted
330-
values for format-spec are "shortlog" or a format string
331-
prefixed with `log:`.
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:`.
332330
e.g. `log: %s (%an)`
333-
If defined, defaults to the `format.commitListFormat` configuration
331+
If not given, defaults to the `format.commitListFormat` configuration
334332
variable.
335-
This option is relevant only if a cover letter is generated.
333+
This option implies the use of `--cover-letter` unless
334+
`--no-cover-letter` is given.
336335
337336
--encode-email-headers::
338337
--no-encode-email-headers::

builtin/log.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,7 +2014,7 @@ int cmd_format_patch(int argc,
20142014
N_("print patches to standard out")),
20152015
OPT_BOOL(0, "cover-letter", &cover_letter,
20162016
N_("generate a cover letter")),
2017-
OPT_STRING(0, "cover-letter-format", &cover_letter_fmt, N_("format-spec"),
2017+
OPT_STRING(0, "commit-list-format", &cover_letter_fmt, N_("format-spec"),
20182018
N_("format spec used for the commit list in the cover letter")),
20192019
OPT_BOOL(0, "numbered-files", &just_numbers,
20202020
N_("use simple number sequence for output file names")),
@@ -2358,6 +2358,8 @@ int cmd_format_patch(int argc,
23582358
cover_letter_fmt = cfg.fmt_cover_letter_commit_list;
23592359
if (!cover_letter_fmt)
23602360
cover_letter_fmt = "shortlog";
2361+
} else if (cover_letter == -1) {
2362+
cover_letter = 1;
23612363
}
23622364

23632365
if (cover_letter == -1) {

t/t4014-format-patch.sh

Lines changed: 21 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -383,49 +383,50 @@ test_expect_success 'filename limit applies only to basename' '
383383
test_expect_success 'cover letter with subject, author and count' '
384384
rm -rf patches &&
385385
test_when_finished "git reset --hard HEAD~1" &&
386-
test_when_finished "rm -rf patches result test_file" &&
386+
test_when_finished "rm -rf patches test_file" &&
387387
touch test_file &&
388388
git add test_file &&
389389
git commit -m "This is a subject" &&
390-
git format-patch --cover-letter \
391-
--cover-letter-format="log:[%(count)/%(total)] %s (%an)" -o patches HEAD~1 &&
392-
grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch >result &&
393-
test_line_count = 1 result
390+
git format-patch --commit-list-format="log:[%(count)/%(total)] %s (%an)" \
391+
-o patches HEAD~1 &&
392+
test_grep "^\[1/1\] This is a subject (A U Thor)$" patches/0000-cover-letter.patch
394393
'
395394

396-
test_expected_success 'cover letter with author and count' '
395+
test_expect_success 'cover letter with author and count' '
397396
test_when_finished "git reset --hard HEAD~1" &&
398-
test_when_finished "rm -rf patches result test_file" &&
397+
test_when_finished "rm -rf patches test_file" &&
399398
touch test_file &&
400399
git add test_file &&
401400
git commit -m "This is a subject" &&
402-
git format-patch --cover-letter \
403-
--cover-letter-format="log:[%(count)/%(total)] %an" -o patches HEAD~1 &&
404-
grep "^\[1/1\] A U Thor$" patches/0000-cover-letter.patch >result &&
405-
test_line_count = 1 result
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
406404
'
407405

408406
test_expect_success 'cover letter shortlog' '
409407
test_when_finished "git reset --hard HEAD~1" &&
410-
test_when_finished "rm -rf patches result test_file" &&
408+
test_when_finished "rm -rf expect patches result test_file" &&
409+
cat >expect <<-"EOF" &&
410+
A U Thor (1):
411+
This is a subject
412+
EOF
411413
touch test_file &&
412414
git add test_file &&
413415
git commit -m "This is a subject" &&
414-
git format-patch --cover-letter --cover-letter-format=shortlog \
415-
-o patches HEAD~1 &&
416-
sed -n -e "/^A U Thor/p;" patches/0000-cover-letter.patch >result &&
417-
test_line_count = 1 result
416+
git format-patch --commit-list-format=shortlog -o patches HEAD~1 &&
417+
grep -E -A 1 "^A U Thor \([[:digit:]]+\):$" patches/0000-cover-letter.patch >result &&
418+
cat result &&
419+
test_cmp expect result
418420
'
419421

420-
test_expect_success 'cover letter no format' '
422+
test_expect_success 'no cover letter but with format specified' '
421423
test_when_finished "git reset --hard HEAD~1" &&
422424
test_when_finished "rm -rf patches result test_file" &&
423425
touch test_file &&
424426
git add test_file &&
425427
git commit -m "This is a subject" &&
426-
git format-patch --cover-letter -o patches HEAD~1 &&
427-
sed -n -e "/^A U Thor/p;" patches/0000-cover-letter.patch >result &&
428-
test_line_count = 1 result
428+
git format-patch --no-cover-letter --commit-list-format="[%(count)] %s" -o patches HEAD~1 &&
429+
test_path_is_missing patches/0000-cover-letter.patch
429430
'
430431

431432
test_expect_success 'cover letter config with count, subject and author' '

t/t9902-completion.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2775,7 +2775,6 @@ test_expect_success PERL 'send-email' '
27752775
test_completion "git send-email --cov" <<-\EOF &&
27762776
--cover-from-description=Z
27772777
--cover-letter Z
2778-
--cover-letter-format=Z
27792778
EOF
27802779
test_completion "git send-email --val" <<-\EOF &&
27812780
--validate Z

0 commit comments

Comments
 (0)