]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format-patch: learn format.forceInBodyFrom configuration variable
authorJunio C Hamano <gitster@pobox.com>
Mon, 29 Aug 2022 21:38:37 +0000 (14:38 -0700)
committerJunio C Hamano <gitster@pobox.com>
Mon, 29 Aug 2022 21:39:13 +0000 (14:39 -0700)
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>
Documentation/config/format.txt
Documentation/git-format-patch.txt
builtin/log.c
t/t4014-format-patch.sh

index fdbc06a4d2a837f768a213fd5ffdf28ad5a48315..c7303d8d9f004b5e413c4e5fe0dbb2f0df0c9171 100644 (file)
@@ -15,6 +15,10 @@ format.from::
        different.  If set to a non-boolean value, format-patch uses that
        value instead of your committer identity.  Defaults to false.
 
+format.forceInBodyFrom::
+       Provides the default value for the `--[no-]force-in-body-from`
+       option to format-patch.  Defaults to false.
+
 format.numbered::
        A boolean which can enable or disable sequence numbers in patch
        subjects.  It defaults to "auto" which enables it only if there
index 7c7f244e579f82d77548bf0e6db22b274c39c49b..dfcc7da4c211706570cd1ce7e1fd8552fb8947d9 100644 (file)
@@ -283,6 +283,8 @@ feeding the result to `git send-email`.
        the in-body "From:" is added even when the sender and the
        author have the same name and address, which may help if the
        mailing list software mangles the sender's identity.
+       Defaults to the value of the `format.forceInBodyFrom`
+       configuration variable.
 
 --add-header=<header>::
        Add an arbitrary header to the email headers.  This is in addition
index 78ccd37bd92594b0d331b158dea6137f0b3987fe..776bc9afdb47d7c90dc7fd786db94f88684f4cae 100644 (file)
@@ -1007,6 +1007,10 @@ static int git_format_config(const char *var, const char *value, void *cb)
                        from = NULL;
                return 0;
        }
+       if (!strcmp(var, "format.forceinbodyfrom")) {
+               force_in_body_from = git_config_bool(var, value);
+               return 0;
+       }
        if (!strcmp(var, "format.notes")) {
                int b = git_parse_maybe_bool(value);
                if (b < 0)
index 347f7f7f351836740f72ffec143d7be06c45ae19..ad5c02927943ab44a6fb986a646cd9b829786ef3 100755 (executable)
@@ -1413,6 +1413,30 @@ test_expect_success 'with --force-in-body-from, redundant in-body from is kept'
        test_cmp expect patch.head
 '
 
+test_expect_success 'format.forceInBodyFrom, equivalent to --force-in-body-from' '
+       git -c format.forceInBodyFrom=yes format-patch \
+               -1 --stdout --from="A U Thor <author@example.com>" >patch &&
+       cat >expect <<-\EOF &&
+       From: A U Thor <author@example.com>
+
+       From: A U Thor <author@example.com>
+
+       EOF
+       sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
+       test_cmp expect patch.head
+'
+
+test_expect_success 'format.forceInBodyFrom, equivalent to --force-in-body-from' '
+       git -c format.forceInBodyFrom=yes format-patch --no-force-in-body-from \
+               -1 --stdout --from="A U Thor <author@example.com>" >patch &&
+       cat >expect <<-\EOF &&
+       From: A U Thor <author@example.com>
+
+       EOF
+       sed -ne "/^From:/p; /^$/p; /^---$/q" patch >patch.head &&
+       test_cmp expect patch.head
+'
+
 test_expect_success 'in-body headers trigger content encoding' '
        test_env GIT_AUTHOR_NAME="éxötìc" test_commit exotic &&
        test_when_finished "git reset --hard HEAD^" &&