format.attach: allow empty value to disable multi-part messages

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>

Junio C Hamano committed Feb 17, 2023 at 15:33 UTC 50bebf98d96a6ccf2ca5c76da5dd8afff6933a4c
3 files changed +22 -1
Documentation/config/format.txt
+2 -1
@@ -3,7 +3,8 @@ format.attach::
3 'format-patch'. The value can also be a double quoted string
4 which will enable attachments as the default and set the
5 value as the boundary. See the --attach option in
6 - linkgit:git-format-patch[1].
6 + linkgit:git-format-patch[1]. To countermand an earlier
7 + value, set it to an empty string.
8
9 format.from::
10 Provides the default value for the `--from` option to format-patch.
builtin/log.c
+2
@@ -1007,6 +1007,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
1007 if (!strcmp(var, "format.attach")) {
1008 if (value && *value)
1009 default_attach = xstrdup(value);
1010 + else if (value && !*value)
1011 + FREE_AND_NULL(default_attach);
1012 else
1013 default_attach = xstrdup(git_version_string);
1014 return 0;
t/t4014-format-patch.sh
+18
@@ -2281,6 +2281,24 @@ test_expect_success 'format-patch --attach cover-letter only is non-multipart' '
2281 test_line_count = 1 output
2282 '
2283
2284 +test_expect_success 'format-patch with format.attach' '
2285 + test_when_finished "rm -fr patches" &&
2286 + separator=attachment-separator &&
2287 + test_config format.attach "$separator" &&
2288 + filename=$(git format-patch -o patches -1) &&
2289 + grep "^Content-Type: multipart/.*$separator" "$filename"
2290 +'
2291 +
2292 +test_expect_success 'format-patch with format.attach=disabled' '
2293 + test_when_finished "rm -fr patches" &&
2294 + separator=attachment-separator &&
2295 + test_config_global format.attach "$separator" &&
2296 + test_config format.attach "" &&
2297 + filename=$(git format-patch -o patches -1) &&
2298 + # The output should not even declare content type for text/plain.
2299 + ! grep "^Content-Type: multipart/" "$filename"
2300 +'
2301 +
2302 test_expect_success '-c format.mboxrd format-patch' '
2303 sp=" " &&
2304 cat >msg <<-INPUT_END &&