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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Signed-off-by: Bert Wesarg <bert.wesarg@xxxxxxxxxxxxxx>
---
 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(-)

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' '
-- 
2.23.0.11.g242cf7f110




[Index of Archives]     [Linux Kernel Development]     [Gcc Help]     [IETF Annouce]     [DCCP]     [Netdev]     [Networking]     [Security]     [V4L]     [Bugtraq]     [Yosemite]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux SCSI]     [Fedora Users]

  Powered by Linux