Skip to content

Commit bc6bf2d

Browse files
0xAXgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Stephen P. Smith <[email protected]> Reviewed-by: Eric Sunshine <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7548842 commit bc6bf2d

File tree

4 files changed

+30
-1
lines changed

4 files changed

+30
-1
lines changed

Documentation/config.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,6 +1243,10 @@ format.coverLetter::
12431243
format-patch is invoked, but in addition can be set to "auto", to
12441244
generate a cover-letter only when there's more than one patch.
12451245

1246+
format.outputDirectory::
1247+
Set a custom directory to store the resulting files instead of the
1248+
current working directory.
1249+
12461250
filter.<driver>.clean::
12471251
The command which is used to convert the content of a worktree
12481252
file to a blob upon checkin. See linkgit:gitattributes[5] for

Documentation/git-format-patch.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ The names of the output files are printed to standard
5757
output, unless the `--stdout` option is specified.
5858

5959
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 .`.
6165

6266
By default, the subject of a single patch is "[PATCH] " followed by
6367
the concatenation of lines from the commit message up to the first blank

builtin/log.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -699,6 +699,7 @@ static int do_signoff;
699699
static const char *signature = git_version_string;
700700
static const char *signature_file;
701701
static int config_cover_letter;
702+
static const char *config_output_directory;
702703

703704
enum {
704705
COVER_UNSET,
@@ -777,6 +778,8 @@ static int git_format_config(const char *var, const char *value, void *cb)
777778
config_cover_letter = git_config_bool(var, value) ? COVER_ON : COVER_OFF;
778779
return 0;
779780
}
781+
if (!strcmp(var, "format.outputdirectory"))
782+
return git_config_string(&config_output_directory, var, value);
780783

781784
return git_log_config(var, value, cb);
782785
}
@@ -1391,6 +1394,9 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
13911394
if (rev.show_notes)
13921395
init_display_notes(&rev.notes_opt);
13931396

1397+
if (!output_directory && !use_stdout)
1398+
output_directory = config_output_directory;
1399+
13941400
if (!use_stdout)
13951401
output_directory = set_outdir(prefix, output_directory);
13961402
else

t/t4014-format-patch.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1445,4 +1445,19 @@ test_expect_success 'From line has expected format' '
14451445
test_cmp from filtered
14461446
'
14471447

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+
14481463
test_done

0 commit comments

Comments
 (0)