path: root/builtin/add.c
diff options
authorJohannes Schindelin <>2019-01-15 15:42:52 (GMT)
committerJunio C Hamano <>2019-01-15 18:51:21 (GMT)
commitfa6f225e0141ec0df1e131e894a3a7d7dea168f5 (patch)
tree5508eb1b322203531c943fb4048c1d925f3c7d56 /builtin/add.c
parent268fbcd172cdb306e8a3e7143cc16677c963d6cd (diff)
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. Of course, this file should not be left lying around. But at least in one case, there was a stale copy, larger than the current diff. So the result was a corrupt diff. Let's just truncate the file when we write it and not worry about it too much. Reported by J Wyman. Signed-off-by: Johannes Schindelin <> Signed-off-by: Junio C Hamano <>
Diffstat (limited to 'builtin/add.c')
1 files changed, 1 insertions, 1 deletions
diff --git a/builtin/add.c b/builtin/add.c
index 8a155dd..160a494 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");