aboutsummaryrefslogtreecommitdiff
path: root/builtin-merge-file.c
diff options
context:
space:
mode:
authorJohannes Schindelin <Johannes.Schindelin@gmx.de>2008-03-13 16:19:35 +0100
committerJunio C Hamano <gitster@pobox.com>2008-03-13 23:43:56 -0700
commit381b851c9b010147bb1fa83a013b7c8f60419026 (patch)
treeec0e5f958344a99775c2ec82e755f9c9b50caa40 /builtin-merge-file.c
parent1affea4f629537fd48e3bd66de89a6f45d0fcd82 (diff)
downloadgit-381b851c9b010147bb1fa83a013b7c8f60419026.tar.gz
git-381b851c9b010147bb1fa83a013b7c8f60419026.tar.xz
merge-file: handle empty files gracefully
Earlier, it would error out while trying to read and/or writing them. Now, calling merge-file with empty files is neither interesting nor useful, but it is a bug that needed fixing. Noticed by Clemens Buchacher. Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
Diffstat (limited to 'builtin-merge-file.c')
-rw-r--r--builtin-merge-file.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/builtin-merge-file.c b/builtin-merge-file.c
index 58deb62ac..baff4495f 100644
--- a/builtin-merge-file.c
+++ b/builtin-merge-file.c
@@ -57,7 +57,8 @@ int cmd_merge_file(int argc, const char **argv, const char *prefix)
if (!f)
ret = error("Could not open %s for writing", filename);
- else if (fwrite(result.ptr, result.size, 1, f) != 1)
+ else if (result.size &&
+ fwrite(result.ptr, result.size, 1, f) != 1)
ret = error("Could not write to %s", filename);
else if (fclose(f))
ret = error("Could not close %s", filename);