From: Ramkumar Ramachandra <artagnon@gmail.com>
To: Git List <git@vger.kernel.org>
Cc: Junio C Hamano <gitster@pobox.com>
Subject: [PATCH] format-patch: remove existing output-directory
Date: Fri, 14 Jun 2013 18:13:33 +0530 [thread overview]
Message-ID: <1371213813-7925-1-git-send-email-artagnon@gmail.com> (raw)
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
next reply other threads:[~2013-06-14 12:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-06-14 12:43 Ramkumar Ramachandra [this message]
2013-06-14 13:10 ` [PATCH] format-patch: remove existing output-directory 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1371213813-7925-1-git-send-email-artagnon@gmail.com \
--to=artagnon@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.