From 9e600a4c708fab6b434c6191ca0fc7bbfc4f86ad Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Mon, 12 Feb 2018 17:23:42 +0100 Subject: [PATCH] add --edit: truncate the patch file If there is already a .git/ADD_EDIT.patch file, we fail to truncate it properly, which could result in very funny errors. Let's just truncate it and not worry about it too much. Reported by J Wyman. Signed-off-by: Johannes Schindelin --- builtin/add.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/builtin/add.c b/builtin/add.c index f65c172299..53c18ea429 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -239,7 +239,7 @@ static int edit_patch(int argc, const char **argv, const char *prefix) rev.diffopt.output_format = DIFF_FORMAT_PATCH; rev.diffopt.use_color = 0; rev.diffopt.flags.ignore_dirty_submodules = 1; - out = open(file, O_CREAT | O_WRONLY, 0666); + out = open(file, O_CREAT | O_WRONLY | O_TRUNC, 0666); if (out < 0) die(_("Could not open '%s' for writing."), file); rev.diffopt.file = xfdopen(out, "w");