Skip to content

Commit f1afbb0

Browse files
committed
Merge branch 'bw/format-patch-o-create-leading-dirs'
"git format-patch -o <outdir>" did an equivalent of "mkdir <outdir>" not "mkdir -p <outdir>", which is being corrected. * bw/format-patch-o-create-leading-dirs: format-patch: create leading components of output directory
2 parents e5fca6b + edefc31 commit f1afbb0

File tree

4 files changed

+42
-2
lines changed

4 files changed

+42
-2
lines changed

Documentation/config/format.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ format.coverLetter::
8181

8282
format.outputDirectory::
8383
Set a custom directory to store the resulting files instead of the
84-
current working directory.
84+
current working directory. All directory components will be created.
8585

8686
format.useAutoBase::
8787
A boolean value which lets you enable the `--base=auto` option of

Documentation/git-format-patch.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ they are created in the current working directory. The default path
6666
can be set with the `format.outputDirectory` configuration option.
6767
The `-o` option takes precedence over `format.outputDirectory`.
6868
To store patches in the current working directory even when
69-
`format.outputDirectory` points elsewhere, use `-o .`.
69+
`format.outputDirectory` points elsewhere, use `-o .`. All directory
70+
components will be created.
7071

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

builtin/log.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1766,10 +1766,26 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
17661766
setup_pager();
17671767

17681768
if (output_directory) {
1769+
int saved;
17691770
if (rev.diffopt.use_color != GIT_COLOR_ALWAYS)
17701771
rev.diffopt.use_color = GIT_COLOR_NEVER;
17711772
if (use_stdout)
17721773
die(_("standard output, or directory, which one?"));
1774+
/*
1775+
* We consider <outdir> as 'outside of gitdir', therefore avoid
1776+
* applying adjust_shared_perm in s-c-l-d.
1777+
*/
1778+
saved = get_shared_repository();
1779+
set_shared_repository(0);
1780+
switch (safe_create_leading_directories_const(output_directory)) {
1781+
case SCLD_OK:
1782+
case SCLD_EXISTS:
1783+
break;
1784+
default:
1785+
die(_("could not create leading directories "
1786+
"of '%s'"), output_directory);
1787+
}
1788+
set_shared_repository(saved);
17731789
if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
17741790
die_errno(_("could not create directory '%s'"),
17751791
output_directory);

t/t4014-format-patch.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1606,6 +1606,29 @@ test_expect_success 'From line has expected format' '
16061606
test_cmp from filtered
16071607
'
16081608

1609+
test_expect_success 'format-patch -o with no leading directories' '
1610+
rm -fr patches &&
1611+
git format-patch -o patches master..side &&
1612+
count=$(git rev-list --count master..side) &&
1613+
ls patches >list &&
1614+
test_line_count = $count list
1615+
'
1616+
1617+
test_expect_success 'format-patch -o with leading existing directories' '
1618+
git format-patch -o patches/side master..side &&
1619+
count=$(git rev-list --count master..side) &&
1620+
ls patches/side >list &&
1621+
test_line_count = $count list
1622+
'
1623+
1624+
test_expect_success 'format-patch -o with leading non-existing directories' '
1625+
rm -fr patches &&
1626+
git format-patch -o patches/side master..side &&
1627+
count=$(git rev-list --count master..side) &&
1628+
ls patches/side >list &&
1629+
test_line_count = $count list
1630+
'
1631+
16091632
test_expect_success 'format-patch format.outputDirectory option' '
16101633
test_config format.outputDirectory patches &&
16111634
rm -fr patches &&

0 commit comments

Comments
 (0)