summaryrefslogtreecommitdiff
path: root/src/apply.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2015-06-17 06:03:01 -0700
committerEdward Thomson <ethomson@github.com>2016-05-26 11:36:11 -0500
commit0004386f29d1165d5dbd54b26170560a7a98e125 (patch)
tree9e7034561f095ad3946fc89b4802aacbece8f0b0 /src/apply.c
parentd34f68261ef95b517944d4fa89ee13b4a68d3cb4 (diff)
downloadlibgit2-0004386f29d1165d5dbd54b26170560a7a98e125.tar.gz
apply: handle empty patches
When a patch is empty, simply copy the source into the destination.
Diffstat (limited to 'src/apply.c')
-rw-r--r--src/apply.c5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/apply.c b/src/apply.c
index e75fa5b4d..f1bd9f4b5 100644
--- a/src/apply.c
+++ b/src/apply.c
@@ -262,7 +262,10 @@ int git_apply__patch(
patch->nfile.file->mode : GIT_FILEMODE_BLOB;
}
- if ((error = apply_hunks(contents_out, source, source_len, patch)) < 0)
+ /* If the patch is empty, simply keep the source unchanged */
+ if (patch->hunks.size == 0)
+ git_buf_put(contents_out, source, source_len);
+ else if ((error = apply_hunks(contents_out, source, source_len, patch)) < 0)
goto done;
if (patch->delta->status == GIT_DELTA_DELETED &&