diff mbox series

[2/3] format-patch: create output directory including leading components

Message ID d959e78af1cb7ef49bca970643b2136c436cd57d.1570051490.git.bert.wesarg@googlemail.com (mailing list archive)
State New, archived
Headers show
Series [1/3] format-patch: document and exercise that -o does only create the trailing directory | expand

Commit Message

Bert Wesarg Oct. 2, 2019, 9:26 p.m. UTC
Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
---
 Documentation/config/format.txt    | 3 +--
 Documentation/git-format-patch.txt | 5 ++---
 builtin/log.c                      | 8 ++++++++
 t/t4014-format-patch.sh            | 5 +++--
 4 files changed, 14 insertions(+), 7 deletions(-)

Comments

Junio C Hamano Oct. 3, 2019, 12:54 a.m. UTC | #1
Bert Wesarg <bert.wesarg@googlemail.com> writes:

> Signed-off-by: Bert Wesarg <bert.wesarg@googlemail.com>
> ---

Squash these two into a single step.  If "-o <output directory>"
forgets to create necessary leading directories, it is just a bug.

Thanks.
diff mbox series

Patch

diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt
index e17c5d6b0f..b6c96ece04 100644
--- a/Documentation/config/format.txt
+++ b/Documentation/config/format.txt
@@ -80,8 +80,7 @@  format.coverLetter::
 
 format.outputDirectory::
 	Set a custom directory to store the resulting files instead of the
-	current working directory. Only the trailing directory will be created
-	though.
+	current working directory. All directory components will be created.
 
 format.useAutoBase::
 	A boolean value which lets you enable the `--base=auto` option of
diff --git a/Documentation/git-format-patch.txt b/Documentation/git-format-patch.txt
index fe7492353e..f418f490aa 100644
--- a/Documentation/git-format-patch.txt
+++ b/Documentation/git-format-patch.txt
@@ -66,9 +66,8 @@  they are created in the current working directory. The default path
 can be set with the `format.outputDirectory` configuration option.
 The `-o` option takes precedence over `format.outputDirectory`.
 To store patches in the current working directory even when
-`format.outputDirectory` points elsewhere, use `-o .`. Note that only
-the trailing directory will be created by Git, leading directories must
-already exists.
+`format.outputDirectory` points elsewhere, use `-o .`. All directory
+components will be created.
 
 By default, the subject of a single patch is "[PATCH] " followed by
 the concatenation of lines from the commit message up to the first blank
diff --git a/builtin/log.c b/builtin/log.c
index 44b10b3415..1ab9eb6b78 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -1769,6 +1769,14 @@  int cmd_format_patch(int argc, const char **argv, const char *prefix)
 			rev.diffopt.use_color = GIT_COLOR_NEVER;
 		if (use_stdout)
 			die(_("standard output, or directory, which one?"));
+		switch (safe_create_leading_directories_const(output_directory)) {
+		case SCLD_OK:
+		case SCLD_EXISTS:
+			break;
+		default:
+			die(_("could not create leading directories "
+			      "of '%s'"), output_directory);
+		}
 		if (mkdir(output_directory, 0777) < 0 && errno != EEXIST)
 			die_errno(_("could not create directory '%s'"),
 				  output_directory);
diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh
index bf2715a503..43d608aa94 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -1643,9 +1643,10 @@  test_expect_success 'format-patch -o with leading existing directories' '
 	test $(git rev-list master..side | wc -l) -eq $(ls patches/side | wc -l)
 '
 
-test_expect_failure 'format-patch -o with leading non-existing directories' '
+test_expect_success 'format-patch -o with leading non-existing directories' '
 	rm -fr patches &&
-	git format-patch -o patches/side master..side
+	git format-patch -o patches/side master..side &&
+	test $(git rev-list master..side | wc -l) -eq $(ls patches/side | wc -l)
 '
 
 test_expect_success 'format-patch format.outputDirectory option' '