mirror of
https://git.proxmox.com/git/libgit2
synced 2025-08-05 08:59:07 +00:00
apply: handle empty patches
When a patch is empty, simply copy the source into the destination.
This commit is contained in:
parent
d34f68261e
commit
0004386f29
@ -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 &&
|
||||
|
@ -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));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user