git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] format-patch: remove existing output-directory
@ 2013-06-14 12:43 Ramkumar Ramachandra
  2013-06-14 13:10 ` John Keeping
  2013-06-14 13:16 ` Fredrik Gustafsson
  0 siblings, 2 replies; 12+ messages in thread
From: Ramkumar Ramachandra @ 2013-06-14 12:43 UTC (permalink / raw)
  To: Git List; +Cc: Junio C Hamano

The following command

  $ git format-patch -o outgoing master

does not ensure that the output-directory outgoing doesn't already
exist.  As a result, it's possible for patches from two different series
to get mixed up if the user is not careful.  Fix the problem by
unconditionally removing the output-directory before writing to it.

Signed-off-by: Ramkumar Ramachandra <artagnon@gmail.com>
---
 builtin/log.c           | 5 +++++
 t/t4014-format-patch.sh | 9 +++++++++
 2 files changed, 14 insertions(+)

diff --git a/builtin/log.c b/builtin/log.c
index 9e21232..babcfb7 100644
--- a/builtin/log.c
+++ b/builtin/log.c
@@ -25,6 +25,7 @@
 #include "version.h"
 #include "mailmap.h"
 #include "gpg-interface.h"
+#include "dir.h"
 
 /* Set a default date-time format for git log ("log.date" config variable) */
 static const char *default_date_mode = NULL;
@@ -1312,8 +1313,12 @@ int cmd_format_patch(int argc, const char **argv, const char *prefix)
 		setup_pager();
 
 	if (output_directory) {
+		struct strbuf buf = STRBUF_INIT;
+
 		if (use_stdout)
 			die(_("standard output, or directory, which one?"));
+		strbuf_addstr(&buf, output_directory);
+		remove_dir_recursively(&buf, 0);
 		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 58d4180..7ba0e66 100755
--- a/t/t4014-format-patch.sh
+++ b/t/t4014-format-patch.sh
@@ -271,6 +271,15 @@ test_expect_success 'multiple files' '
 	ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch
 '
 
+test_expect_success 'multiple files; unclean output-directory' '
+	mkdir -p patches &&
+	: >patches/fuzzle &&
+	git checkout side &&
+	git format-patch -o patches/ master &&
+	ls patches/0001-Side-changes-1.patch patches/0002-Side-changes-2.patch patches/0003-Side-changes-3-with-n-backslash-n-in-it.patch &&
+	test_path_is_missing patches/fuzzle
+'
+
 test_expect_success 'reroll count' '
 	rm -fr patches &&
 	git format-patch -o patches --cover-letter --reroll-count 4 master..side >list &&
-- 
1.8.3.1.379.g74a2e74

^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2013-06-14 13:58 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-14 12:43 [PATCH] format-patch: remove existing output-directory Ramkumar Ramachandra
2013-06-14 13:10 ` John Keeping
2013-06-14 13:15   ` Ramkumar Ramachandra
2013-06-14 13:21     ` John Keeping
2013-06-14 13:58       ` Junio C Hamano
2013-06-14 13:55   ` Junio C Hamano
2013-06-14 13:16 ` Fredrik Gustafsson
2013-06-14 13:34   ` Ramkumar Ramachandra
2013-06-14 13:48     ` Fredrik Gustafsson
2013-06-14 13:52       ` Ramkumar Ramachandra
2013-06-14 13:50     ` SZEDER Gábor
2013-06-14 13:51       ` Ramkumar Ramachandra

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).