format-patch: introduce format.outputDirectory configuration

We can pass -o/--output-directory to the format-patch command to store patches in some place other than the working directory. This patch introduces format.outputDirectory configuration option for same purpose. The case of usage of this configuration option can be convenience to not pass every time -o/--output-directory if an user has pattern to store all patches in the /patches directory for example. The format.outputDirectory has lower priority than command line option, so if user will set format.outputDirectory and pass the command line option, a result will be stored in a directory that passed to command line option. Signed-off-by: Alexander Kuleshov <kuleshovmail@gmail.com> Signed-off-by: Stephen P. Smith <ischis2@cox.net> Reviewed-by: Eric Sunshine <sunshine@sunshineco.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Alexander Kuleshov committed Jan 13, 2016 at 06:20 UTC bc6bf2d7641d6c2450b347d5a0b2f954728bf4d9
4 files changed +30 -1
Documentation/config.txt
+4
@@ -1243,6 +1243,10 @@ format.coverLetter::
1243 format-patch is invoked, but in addition can be set to "auto", to
1244 generate a cover-letter only when there's more than one patch.
1245
1246 +format.outputDirectory::
1247 + Set a custom directory to store the resulting files instead of the
1248 + current working directory.
1249 +
1250 filter.<driver>.clean::
1251 The command which is used to convert the content of a worktree
1252 file to a blob upon checkin. See linkgit:gitattributes[5] for
Documentation/git-format-patch.txt
+5 -1
@@ -57,7 +57,11 @@ The names of the output files are printed to standard
57 output, unless the `--stdout` option is specified.
58
59 If `-o` is specified, output files are created in <dir>. Otherwise
60 -they are created in the current working directory.
60 +they are created in the current working directory. The default path
61 +can be set with the 'format.outputDirectory' configuration option.
62 +The `-o` option takes precedence over `format.outputDirectory`.
63 +To store patches in the current working directory even when
64 +`format.outputDirectory` points elsewhere, use `-o .`.
65
66 By default, the subject of a single patch is "[PATCH] " followed by
67 the concatenation of lines from the commit message up to the first blank
builtin/log.c
+6
@@ -699,6 +699,7 @@ static int do_signoff;
699 static const char *signature = git_version_string;
700 static const char *signature_file;
701 static int config_cover_letter;
702 +static const char *config_output_directory;
703
704 enum {
705 COVER_UNSET,
@@ -777,6 +778,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
778 config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
779 return 0;
780 }
781 + if (!strcmp(var, "format.outputdirectory"))
782 + return git_config_string(&config_output_directory, var, value);
783
784 return git_log_config(var, value, cb);
785 }
@@ -1391,6 +1394,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
1394 if (rev.show_notes)
1395 init_display_notes(&rev.notes_opt);
1396
1397 + if (!output_directory && !use_stdout)
1398 + output_directory = config_output_directory;
1399 +
1400 if (!use_stdout)
1401 output_directory = set_outdir(prefix, output_directory);
1402 else
t/t4014-format-patch.sh
+15
@@ -1445,4 +1445,19 @@ test_expect_success 'From line has expected format' '
1445 test_cmp from filtered
1446 '
1447
1448 +test_expect_success 'format-patch format.outputDirectory option' '
1449 + test_config format.outputDirectory patches &&
1450 + rm -fr patches &&
1451 + git format-patch master..side &&
1452 + test $(git rev-list master..side | wc -l) -eq $(ls patches | wc -l)
1453 +'
1454 +
1455 +test_expect_success 'format-patch -o overrides format.outputDirectory' '
1456 + test_config format.outputDirectory patches &&
1457 + rm -fr patches patchset &&
1458 + git format-patch master..side -o patchset &&
1459 + test_path_is_missing patches &&
1460 + test_path_is_dir patchset
1461 +'
1462 +
1463 test_done