]> git.ipfire.org Git - thirdparty/git.git/commitdiff
format.attach: allow empty value to disable multi-part messages
authorJunio C Hamano <gitster@pobox.com>
Fri, 17 Feb 2023 23:33:37 +0000 (15:33 -0800)
committerJunio C Hamano <gitster@pobox.com>
Fri, 17 Feb 2023 23:43:09 +0000 (15:43 -0800)
When a lower precedence configuration file (e.g. /etc/gitconfig)
defines format.attach in any way, there was no way to disable it in
a more specific configuration file (e.g. $HOME/.gitconfig).

Change the behaviour of setting it to an empty string.  It used to
mean that the result is still a multipart message with only dashes
used as a multi-part separator, but now it resets the setting to
the default (which would be to give an inline patch, unless other
command line options are in effect).

Signed-off-by: Junio C Hamano <gitster@pobox.com>
Documentation/config/format.txt
builtin/log.c
t/t4014-format-patch.sh

index 3bd78269e29a544fa13369f9e5169b403be294ac..73678d88a1dba172c43f4fb850e750c6a0c7f96c 100644 (file)
@@ -3,7 +3,8 @@ format.attach::
        'format-patch'.  The value can also be a double quoted string
        which will enable attachments as the default and set the
        value as the boundary.  See the --attach option in
-       linkgit:git-format-patch[1].
+       linkgit:git-format-patch[1].  To countermand an earlier
+       value, set it to an empty string.
 
 format.from::
        Provides the default value for the `--from` option to format-patch.
index 04412dd9c936569506c1ca932a7804059a57904f..a70fba198f9451c9005b3ecd14cfce8765e1d838 100644 (file)
@@ -1007,6 +1007,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
        if (!strcmp(var, "format.attach")) {
                if (value && *value)
                        default_attach = xstrdup(value);
+               else if (value && !*value)
+                       FREE_AND_NULL(default_attach);
                else
                        default_attach = xstrdup(git_version_string);
                return 0;
index 012f155e10ae9f9e1fcbd3472cd9a789bae919ec..f3313b8c58feabb3cd2e52fb1147bd68c6f43862 100755 (executable)
@@ -2281,6 +2281,24 @@ test_expect_success 'format-patch --attach cover-letter only is non-multipart' '
        test_line_count = 1 output
 '
 
+test_expect_success 'format-patch with format.attach' '
+       test_when_finished "rm -fr patches" &&
+       separator=attachment-separator &&
+       test_config format.attach "$separator" &&
+       filename=$(git format-patch -o patches -1) &&
+       grep "^Content-Type: multipart/.*$separator" "$filename"
+'
+
+test_expect_success 'format-patch with format.attach=disabled' '
+       test_when_finished "rm -fr patches" &&
+       separator=attachment-separator &&
+       test_config_global format.attach "$separator" &&
+       test_config format.attach "" &&
+       filename=$(git format-patch -o patches -1) &&
+       # The output should not even declare content type for text/plain.
+       ! grep "^Content-Type: multipart/" "$filename"
+'
+
 test_expect_success '-c format.mboxrd format-patch' '
        sp=" " &&
        cat >msg <<-INPUT_END &&