Skip to content

Commit 2a4c260

Browse files
felipecgitster
authored andcommitted
format-patch: add format.coverLetter configuration variable
Also, add a new option: 'auto', so if there's more than one patch, the cover letter is generated, otherwise it's not. Signed-off-by: Felipe Contreras <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent aa089cd commit 2a4c260

File tree

4 files changed

+62
-8
lines changed

4 files changed

+62
-8
lines changed

Documentation/config.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,6 +1096,11 @@ format.signoff::
10961096
the rights to submit this work under the same open source license.
10971097
Please see the 'SubmittingPatches' document for further discussion.
10981098

1099+
format.coverLetter::
1100+
A boolean that controls whether to generate a cover-letter when
1101+
format-patch is invoked, but in addition can be set to "auto", to
1102+
generate a cover-letter only when there's more than one patch.
1103+
10991104
filter.<driver>.clean::
11001105
The command which is used to convert the content of a worktree
11011106
file to a blob upon checkin. See linkgit:gitattributes[5] for

Documentation/git-format-patch.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ SYNOPSIS
2020
[--ignore-if-in-upstream]
2121
[--subject-prefix=Subject-Prefix] [(--reroll-count|-v) <n>]
2222
[--to=<email>] [--cc=<email>]
23-
[--cover-letter] [--quiet] [--notes[=<ref>]]
23+
[--[no-]cover-letter] [--quiet] [--notes[=<ref>]]
2424
[<common diff options>]
2525
[ <since> | <revision range> ]
2626

@@ -195,7 +195,7 @@ will want to ensure that threading is disabled for `git send-email`.
195195
`Cc:`, and custom) headers added so far from config or command
196196
line.
197197

198-
--cover-letter::
198+
--[no-]cover-letter::
199199
In addition to the patches, generate a cover letter file
200200
containing the shortlog and the overall diffstat. You can
201201
fill in a description in the file before sending it out.
@@ -260,6 +260,7 @@ attachments, and sign off patches with configuration variables.
260260
cc = <email>
261261
attach [ = mime-boundary-string ]
262262
signoff = true
263+
coverletter = auto
263264
------------
264265

265266

builtin/log.c

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -622,6 +622,14 @@ static void add_header(const char *value)
622622
static int thread;
623623
static int do_signoff;
624624
static const char *signature = git_version_string;
625+
static int config_cover_letter;
626+
627+
enum {
628+
COVER_UNSET,
629+
COVER_OFF,
630+
COVER_ON,
631+
COVER_AUTO
632+
};
625633

626634
static int git_format_config(const char *var, const char *value, void *cb)
627635
{
@@ -683,6 +691,14 @@ static int git_format_config(const char *var, const char *value, void *cb)
683691
}
684692
if (!strcmp(var, "format.signature"))
685693
return git_config_string(&signature, var, value);
694+
if (!strcmp(var, "format.coverletter")) {
695+
if (value && !strcasecmp(value, "auto")) {
696+
config_cover_letter = COVER_AUTO;
697+
return 0;
698+
}
699+
config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
700+
return 0;
701+
}
686702

687703
return git_log_config(var, value, cb);
688704
}
@@ -1074,7 +1090,7 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
10741090
int start_number = -1;
10751091
int just_numbers = 0;
10761092
int ignore_if_in_upstream = 0;
1077-
int cover_letter = 0;
1093+
int cover_letter = -1;
10781094
int boundary_count = 0;
10791095
int no_binary_diff = 0;
10801096
struct commit *origin = NULL, *head = NULL;
@@ -1309,11 +1325,6 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
13091325
*/
13101326
rev.show_root_diff = 1;
13111327

1312-
if (cover_letter) {
1313-
if (!branch_name)
1314-
branch_name = find_branch_name(&rev);
1315-
}
1316-
13171328
if (ignore_if_in_upstream) {
13181329
/* Don't say anything if head and upstream are the same. */
13191330
if (rev.pending.nr == 2) {
@@ -1354,6 +1365,13 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
13541365
numbered = 1;
13551366
if (numbered)
13561367
rev.total = total + start_number - 1;
1368+
if (cover_letter == -1) {
1369+
if (config_cover_letter == COVER_AUTO)
1370+
cover_letter = (total > 1);
1371+
else
1372+
cover_letter = (config_cover_letter == COVER_ON);
1373+
}
1374+
13571375
if (in_reply_to || thread || cover_letter)
13581376
rev.ref_message_ids = xcalloc(1, sizeof(struct string_list));
13591377
if (in_reply_to) {
@@ -1365,6 +1383,8 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
13651383
if (cover_letter) {
13661384
if (thread)
13671385
gen_message_id(&rev, "cover");
1386+
if (!branch_name)
1387+
branch_name = find_branch_name(&rev);
13681388
make_cover_letter(&rev, use_stdout,
13691389
origin, nr, list, head, branch_name, quiet);
13701390
total++;

t/t4014-format-patch.sh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1289,4 +1289,32 @@ test_expect_success 'cover letter with nothing' '
12891289
test_line_count = 0 actual
12901290
'
12911291

1292+
test_expect_success 'cover letter auto' '
1293+
mkdir -p tmp &&
1294+
test_when_finished "rm -rf tmp;
1295+
git config --unset format.coverletter" &&
1296+
1297+
git config format.coverletter auto &&
1298+
git format-patch -o tmp -1 >list &&
1299+
test_line_count = 1 list &&
1300+
git format-patch -o tmp -2 >list &&
1301+
test_line_count = 3 list
1302+
'
1303+
1304+
test_expect_success 'cover letter auto user override' '
1305+
mkdir -p tmp &&
1306+
test_when_finished "rm -rf tmp;
1307+
git config --unset format.coverletter" &&
1308+
1309+
git config format.coverletter auto &&
1310+
git format-patch -o tmp --cover-letter -1 >list &&
1311+
test_line_count = 2 list &&
1312+
git format-patch -o tmp --cover-letter -2 >list &&
1313+
test_line_count = 3 list &&
1314+
git format-patch -o tmp --no-cover-letter -1 >list &&
1315+
test_line_count = 1 list &&
1316+
git format-patch -o tmp --no-cover-letter -2 >list &&
1317+
test_line_count = 2 list
1318+
'
1319+
12921320
test_done

0 commit comments

Comments
 (0)