From 0004386f29d1165d5dbd54b26170560a7a98e125 Mon Sep 17 00:00:00 2001 From: Edward Thomson Date: Wed, 17 Jun 2015 06:03:01 -0700 Subject: [PATCH] apply: handle empty patches When a patch is empty, simply copy the source into the destination. --- src/apply.c | 5 ++++- tests/apply/fromdiff.c | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) 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 && diff --git a/tests/apply/fromdiff.c b/tests/apply/fromdiff.c index 64ed9de79..af0541de8 100644 --- a/tests/apply/fromdiff.c +++ b/tests/apply/fromdiff.c @@ -174,3 +174,11 @@ void test_apply_fromdiff__delete(void) NULL, NULL, PATCH_DELETE_ORIGINAL, NULL)); } + +void test_apply_fromdiff__no_change(void) +{ + cl_git_pass(apply_buf( + FILE_ORIGINAL, "file.txt", + FILE_ORIGINAL, "file.txt", + "", NULL)); +}