Skip to content

Commit b2ed5ae

Browse files
committed
Merge branch 'ak/format-patch-odir-config'
"git format-patch" learned to notice format.outputDirectory configuration variable. This allows "-o <dir>" option to be omitted on the command line if you always use the same directory in your workflow. * ak/format-patch-odir-config: format-patch: introduce format.outputDirectory configuration
2 parents c7dd1c5 + bc6bf2d commit b2ed5ae

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
@@ -1245,6 +1245,10 @@ format.coverLetter::
12451245
format-patch is invoked, but in addition can be set to "auto", to
12461246
generate a cover-letter only when there's more than one patch.
12471247

1248+
format.outputDirectory::
1249+
Set a custom directory to store the resulting files instead of the
1250+
current working directory.
1251+
12481252
filter.<driver>.clean::
12491253
The command which is used to convert the content of a worktree
12501254
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)