format-patch: learn format.forceInBodyFrom configuration variable
As the need to use the "--force-in-body-from" option primarily is tied to which mailing list the mails go to (and get their From: address mangled), it is likely that a user who needs to use this option once to interact with their upstream project needs to use it for all patches they send out. Add a configuration variable, suitable for setting in the local configuration file per repository, for this. Signed-off-by: Junio C Hamano <gitster@pobox.com>
Junio C Hamano committed
Aug 29, 2022 at 14:38 UTC
d5fc07df688ace8c5a32f66b358ebd55cdaf4d28
4 files changed
+34
Documentation/config/format.txt
+4
@@ -15,6 +15,10 @@ format.from::
15
different. If set to a non-boolean value, format-patch uses that
16
value instead of your committer identity. Defaults to false.
17
18
+format.forceInBodyFrom::
19
+ Provides the default value for the `--[no-]force-in-body-from`
20
+ option to format-patch. Defaults to false.
21
+
22
format.numbered::
23
A boolean which can enable or disable sequence numbers in patch
24
subjects. It defaults to "auto" which enables it only if there
Documentation/git-format-patch.txt
+2
@@ -283,6 +283,8 @@ feeding the result to `git send-email`.
283
the in-body "From:" is added even when the sender and the
284
author have the same name and address, which may help if the
285
mailing list software mangles the sender's identity.
286
+ Defaults to the value of the `format.forceInBodyFrom`
287
+ configuration variable.
288
289
--add-header=<header>::
290
Add an arbitrary header to the email headers. This is in addition
builtin/log.c
+4
@@ -1007,6 +1007,10 @@ static int git_format_config(const char *var, const char *value, void *cb)
1007
from = NULL;
1008
return 0;
1009
}
1010
+ if (!strcmp(var, "format.forceinbodyfrom")) {
1011
+ force_in_body_from = git_config_bool(var, value);
1012
+ return 0;
1013
+ }
1014
if (!strcmp(var, "format.notes")) {
1015
int b = git_parse_maybe_bool(value);
1016
if (b < 0)
t/t4014-format-patch.sh
+24
@@ -1413,6 +1413,30 @@ test_expect_success 'with --force-in-body-from, redundant in-body from is kept'
1413
test_cmp expect patch.head
1414
'
1415
1416
+test_expect_success 'format.forceInBodyFrom, equivalent to --force-in-body-from' '
1417
+ git -c format.forceInBodyFrom=yes format-patch \
1418
+ -1 --stdout --from="A U Thor <author@example.com>" >patch &&
1419
+ cat >expect <<-\EOF &&
1420
+ From: A U Thor <author@example.com>
1421
+
1422
+ From: A U Thor <author@example.com>
1423
+
1424
+ EOF
1425
+ sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
1426
+ test_cmp expect patch.head
1427
+'
1428
+
1429
+test_expect_success 'format.forceInBodyFrom, equivalent to --force-in-body-from' '
1430
+ git -c format.forceInBodyFrom=yes format-patch --no-force-in-body-from \
1431
+ -1 --stdout --from="A U Thor <author@example.com>" >patch &&
1432
+ cat >expect <<-\EOF &&
1433
+ From: A U Thor <author@example.com>
1434
+
1435
+ EOF
1436
+ sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
1437
+ test_cmp expect patch.head
1438
+'
1439
+
1440
test_expect_success 'in-body headers trigger content encoding' '
1441
test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
1442
test_when_finished "git reset --hard HEAD^" &&