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@xxxxxxxxx> --- 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 -- To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html